1()                         PMDK Programmer's Manual                         ()
2
3
4

NAME

6       libpmempool - persistent memory pool management library
7
8              NOTE:  Support  for  Windows  and  FreeBSD deprecated since PMDK
9              1.13.0 release and will be removed in the PMDK 1.14.0 release.
10

SYNOPSIS

12              #include <libpmempool.h>
13              cc -std=gnu99 ... -lpmempool -lpmem
14
15   Library API versioning:
16              const char *pmempool_check_version(
17                  unsigned major_required,
18                  unsigned minor_required);
19
20   Error handling:
21              const char *pmempool_errormsg(void);
22
23   Other library functions:
24       A description of other libpmempool functions can be found on  the  fol‐
25       lowing manual pages:
26
27       • health check functions: pmempool_check_init(3)
28
29       • pool set synchronization and transformation: pmempool_sync(3)
30
31       • pool set management functions: pmempool_rm(3)
32
33       • toggle or query pool set features: pmempool_feature_query(3)
34

DESCRIPTION

36       libpmempool  provides  a set of utilities for off-line analysis and ma‐
37       nipulation of a pool.  A pool in this manpage  means  a  pmemobj  pool,
38       pmemblk pool, pmemlog pool or BTT layout, independent of the underlying
39       storage.  Some libpmempool functions are required to work  without  any
40       impact  on  the  pool  but  some may create a new or modify an existing
41       pool.
42
43       libpmempool is for applications that need high reliability or  built-in
44       troubleshooting.   It  may be useful for testing and debugging purposes
45       also.
46
47       libpmempool introduces functionality of pool set health check, synchro‐
48       nization, transformation and removal.
49

CAVEATS

51       libpmempool relies on the library destructor being called from the main
52       thread.  For this reason, all functions that might trigger  destruction
53       (e.g.  dlclose(3)) should be called in the main thread.  Otherwise some
54       of the resources associated with that thread might not  be  cleaned  up
55       properly.
56
57       libpmempool requires the -std=gnu99 compilation flag to build properly.
58

LIBRARY API VERSIONING

60       This  section  describes how the library API is versioned, allowing ap‐
61       plications to work with an evolving API.
62
63       The pmempool_check_version() function is used to see if  the  installed
64       libpmempool  supports the version of the library API required by an ap‐
65       plication.  The easiest way to do this for the application is to supply
66       the  compile-time version information, supplied by defines in <libpmem‐
67       pool.h>, like this:
68
69              reason = pmempool_check_version(PMEMPOOL_MAJOR_VERSION,
70                                              PMEMPOOL_MINOR_VERSION);
71              if (reason != NULL) {
72                  /* version check failed, reason string tells you why */
73              }
74
75       Any mismatch in the major version number is considered a failure, but a
76       library  with  a  newer minor version number will pass this check since
77       increasing minor versions imply backwards compatibility.
78
79       An application can also check specifically for the existence of an  in‐
80       terface  by  checking  for  the version where that interface was intro‐
81       duced.  These versions are documented in this man page as follows:  un‐
82       less  otherwise  specified, all interfaces described here are available
83       in version 1.0 of the library.  Interfaces added after version 1.0 will
84       contain the text introduced in version x.y in the section of this manu‐
85       al describing the feature.
86
87       When the version check performed by  pmempool_check_version()  is  suc‐
88       cessful,  the  return  value  is NULL.  Otherwise the return value is a
89       static string describing the reason for failing the version check.  The
90       string  returned  by  pmempool_check_version()  must not be modified or
91       freed.
92

DEBUGGING AND ERROR HANDLING

94       If an error is detected during the call to a libpmempool function,  the
95       application may retrieve an error message describing the reason for the
96       failure from pmempool_errormsg().  This function returns a pointer to a
97       static  buffer containing the last error message logged for the current
98       thread.  If errno was set, the error message may include a  description
99       of  the corresponding error code as returned by strerror(3).  The error
100       message buffer is thread-local; errors encountered in one thread do not
101       affect  its value in other threads.  The buffer is never cleared by any
102       library function; its content is significant only when the return value
103       of  the  immediately preceding call to a libpmempool function indicated
104       an error, or if errno was set.  The application must not modify or free
105       the error message string, but it may be modified by subsequent calls to
106       other library functions.
107
108       Two versions of libpmempool are typically available  on  a  development
109       system.   The  normal  version, accessed when a program is linked using
110       the -lpmempool option, is  optimized  for  performance.   That  version
111       skips  checks that impact performance and never logs any trace informa‐
112       tion or performs any run-time assertions.
113
114       A second version of libpmempool, accessed when a program uses  the  li‐
115       braries  under  /usr/lib/pmdk_debug,  contains  run-time assertions and
116       trace points.  The typical way to access the debug version  is  to  set
117       the  environment  variable  LD_LIBRARY_PATH  to  /usr/lib/pmdk_debug or
118       /usr/lib64/pmdk_debug, as appropriate.  Debugging output is  controlled
119       using the following environment variables.  These variables have no ef‐
120       fect on the non-debug version of the library.
121
122PMEMPOOL_LOG_LEVEL
123
124       The value of PMEMPOOL_LOG_LEVEL enables trace points in the debug  ver‐
125       sion of the library, as follows:
126
1270 - This is the default level when PMEMPOOL_LOG_LEVEL is not set.  No
128         log messages are emitted at this level.
129
1301 - Additional details on any errors detected are logged (in addition
131         to  returning the errno-based errors as usual).  The same information
132         may be retrieved using pmempool_errormsg().
133
1342 - A trace of basic operations is logged.
135
1363 - Enables a very verbose amount of function call tracing in the li‐
137         brary.
138
1394 - Enables voluminous and fairly obscure tracing information that is
140         likely only useful to the libpmempool developers.
141
142       Unless PMEMPOOL_LOG_FILE is set, debugging output is written to stderr.
143
144PMEMPOOL_LOG_FILE
145
146       Specifies the name of a file where all logging  information  should  be
147       written.  If the last character in the name is “-”, the PID of the cur‐
148       rent process will be appended to the file name when  the  log  file  is
149       created.  If PMEMPOOL_LOG_FILE is not set, output is written to stderr.
150

EXAMPLE

152       The following example illustrates how the libpmempool API is used.  The
153       program detects the type and checks  consistency  of  given  pool.   If
154       there are any issues detected, the pool is automatically repaired.
155
156              #include <stddef.h>
157              #include <unistd.h>
158              #include <stdlib.h>
159              #include <stdio.h>
160              #include <libpmempool.h>
161
162              #define PATH "./pmem-fs/myfile"
163              #define CHECK_FLAGS (PMEMPOOL_CHECK_FORMAT_STR|PMEMPOOL_CHECK_REPAIR|\
164                                   PMEMPOOL_CHECK_VERBOSE)
165
166              int
167              main(int argc, char *argv[])
168              {
169                  PMEMpoolcheck *ppc;
170                  struct pmempool_check_status *status;
171                  enum pmempool_check_result ret;
172
173                  /* arguments for check */
174                  struct pmempool_check_args args = {
175                      .path       = PATH,
176                      .backup_path    = NULL,
177                      .pool_type  = PMEMPOOL_POOL_TYPE_DETECT,
178                      .flags      = CHECK_FLAGS
179                  };
180
181                  /* initialize check context */
182                  if ((ppc = pmempool_check_init(&args, sizeof(args))) == NULL) {
183                      perror("pmempool_check_init");
184                      exit(EXIT_FAILURE);
185                  }
186
187                  /* perform check and repair, answer 'yes' for each question */
188                  while ((status = pmempool_check(ppc)) != NULL) {
189                      switch (status->type) {
190                      case PMEMPOOL_CHECK_MSG_TYPE_ERROR:
191                          printf("%s\n", status->str.msg);
192                          break;
193                      case PMEMPOOL_CHECK_MSG_TYPE_INFO:
194                          printf("%s\n", status->str.msg);
195                          break;
196                      case PMEMPOOL_CHECK_MSG_TYPE_QUESTION:
197                          printf("%s\n", status->str.msg);
198                          status->str.answer = "yes";
199                          break;
200                      default:
201                          pmempool_check_end(ppc);
202                          exit(EXIT_FAILURE);
203                      }
204                  }
205
206                  /* finalize the check and get the result */
207                  ret = pmempool_check_end(ppc);
208                  switch (ret) {
209                      case PMEMPOOL_CHECK_RESULT_CONSISTENT:
210                      case PMEMPOOL_CHECK_RESULT_REPAIRED:
211                          return 0;
212                      default:
213                          return 1;
214                  }
215              }
216
217       See  <https://pmem.io/pmdk/libpmempool>  for  more  examples  using the
218       libpmempool API.
219

ACKNOWLEDGEMENTS

221       libpmempool builds on the persistent memory  programming  model  recom‐
222       mended   by   the   SNIA   NVM   Programming   Technical   Work  Group:
223       <https://snia.org/nvmp>
224

SEE ALSO

226       dlclose(3),  pmempool_check_init(3),  pmempool_feature_query(3),  pmem‐
227       pool_rm(3),  pmempool_sync(3),  strerror(3), libpmem(7), libpmemblk(7),
228       libpmemlog(7), libpmemobj(7) and <https://pmem.io>**
229
230
231
232PMDK -                            2023-06-05                                ()
Impressum