.\" Automatically generated by Pandoc 2.9.2.1 .\" .TH "" "" "2023-05-31" "PMDK - " "PMDK Programmer's Manual" .hy .\" SPDX-License-Identifier: BSD-3-Clause .\" Copyright 2016-2018, Intel Corporation .SH NAME .PP \f[B]libpmempool\f[R] - persistent memory pool management library .RS .PP NOTE: Support for Windows and FreeBSD deprecated since PMDK 1.13.0 release and will be removed in the PMDK 1.14.0 release. .RE .SH SYNOPSIS .IP .nf \f[C] #include cc -std=gnu99 ... -lpmempool -lpmem \f[R] .fi .SS Library API versioning: .IP .nf \f[C] const char *pmempool_check_version( unsigned major_required, unsigned minor_required); \f[R] .fi .SS Error handling: .IP .nf \f[C] const char *pmempool_errormsg(void); \f[R] .fi .SS Other library functions: .PP A description of other \f[B]libpmempool\f[R] functions can be found on the following manual pages: .IP \[bu] 2 health check functions: \f[B]pmempool_check_init\f[R](3) .IP \[bu] 2 pool set synchronization and transformation: \f[B]pmempool_sync\f[R](3) .IP \[bu] 2 pool set management functions: \f[B]pmempool_rm\f[R](3) .IP \[bu] 2 toggle or query pool set features: \f[B]pmempool_feature_query\f[R](3) .SH DESCRIPTION .PP \f[B]libpmempool\f[R] provides a set of utilities for off-line analysis and manipulation of a \f[I]pool\f[R]. A \f[I]pool\f[R] in this manpage means a pmemobj pool, pmemblk pool, pmemlog pool or BTT layout, independent of the underlying storage. Some \f[B]libpmempool\f[R] functions are required to work without any impact on the \f[I]pool\f[R] but some may create a new or modify an existing \f[I]pool\f[R]. .PP \f[B]libpmempool\f[R] is for applications that need high reliability or built-in troubleshooting. It may be useful for testing and debugging purposes also. .PP \f[B]libpmempool\f[R] introduces functionality of pool set health check, synchronization, transformation and removal. .SH CAVEATS .PP \f[B]libpmempool\f[R] relies on the library destructor being called from the main thread. For this reason, all functions that might trigger destruction (e.g. \f[B]dlclose\f[R](3)) should be called in the main thread. Otherwise some of the resources associated with that thread might not be cleaned up properly. .PP \f[B]libpmempool\f[R] requires the \f[B]-std=gnu99\f[R] compilation flag to build properly. .SH LIBRARY API VERSIONING .PP This section describes how the library API is versioned, allowing applications to work with an evolving API. .PP The \f[B]pmempool_check_version\f[R]() function is used to see if the installed \f[B]libpmempool\f[R] supports the version of the library API required by an application. The easiest way to do this for the application is to supply the compile-time version information, supplied by defines in \f[B]\f[R], like this: .IP .nf \f[C] reason = pmempool_check_version(PMEMPOOL_MAJOR_VERSION, PMEMPOOL_MINOR_VERSION); if (reason != NULL) { /* version check failed, reason string tells you why */ } \f[R] .fi .PP Any mismatch in the major version number is considered a failure, but a library with a newer minor version number will pass this check since increasing minor versions imply backwards compatibility. .PP An application can also check specifically for the existence of an interface by checking for the version where that interface was introduced. These versions are documented in this man page as follows: unless otherwise specified, all interfaces described here are available in version 1.0 of the library. Interfaces added after version 1.0 will contain the text \f[I]introduced in version x.y\f[R] in the section of this manual describing the feature. .PP When the version check performed by \f[B]pmempool_check_version\f[R]() is successful, the return value is NULL. Otherwise the return value is a static string describing the reason for failing the version check. The string returned by \f[B]pmempool_check_version\f[R]() must not be modified or freed. .SH DEBUGGING AND ERROR HANDLING .PP If an error is detected during the call to a \f[B]libpmempool\f[R] function, the application may retrieve an error message describing the reason for the failure from \f[B]pmempool_errormsg\f[R](). This function returns a pointer to a static buffer containing the last error message logged for the current thread. If \f[I]errno\f[R] was set, the error message may include a description of the corresponding error code as returned by \f[B]strerror\f[R](3). The error message buffer is thread-local; errors encountered in one thread do not affect its value in other threads. The buffer is never cleared by any library function; its content is significant only when the return value of the immediately preceding call to a \f[B]libpmempool\f[R] function indicated an error, or if \f[I]errno\f[R] was set. The application must not modify or free the error message string, but it may be modified by subsequent calls to other library functions. .PP Two versions of \f[B]libpmempool\f[R] are typically available on a development system. The normal version, accessed when a program is linked using the \f[B]-lpmempool\f[R] option, is optimized for performance. That version skips checks that impact performance and never logs any trace information or performs any run-time assertions. .PP A second version of \f[B]libpmempool\f[R], accessed when a program uses the libraries under \f[B]/usr/lib/pmdk_debug\f[R], contains run-time assertions and trace points. The typical way to access the debug version is to set the environment variable \f[B]LD_LIBRARY_PATH\f[R] to \f[B]/usr/lib/pmdk_debug\f[R] or \f[B]/usr/lib64/pmdk_debug\f[R], as appropriate. Debugging output is controlled using the following environment variables. These variables have no effect on the non-debug version of the library. .RS .PP NOTE: On Debian/Ubuntu systems, this extra debug version of the library is shipped in the respective \f[B]-debug\f[R] Debian package and placed in the \f[B]/usr/lib/$ARCH/pmdk_dbg/\f[R] directory. .RE .IP \[bu] 2 \f[B]PMEMPOOL_LOG_LEVEL\f[R] .PP The value of \f[B]PMEMPOOL_LOG_LEVEL\f[R] enables trace points in the debug version of the library, as follows: .IP \[bu] 2 \f[B]0\f[R] - This is the default level when \f[B]PMEMPOOL_LOG_LEVEL\f[R] is not set. No log messages are emitted at this level. .IP \[bu] 2 \f[B]1\f[R] - Additional details on any errors detected are logged (in addition to returning the \f[I]errno\f[R]-based errors as usual). The same information may be retrieved using \f[B]pmempool_errormsg\f[R](). .IP \[bu] 2 \f[B]2\f[R] - A trace of basic operations is logged. .IP \[bu] 2 \f[B]3\f[R] - Enables a very verbose amount of function call tracing in the library. .IP \[bu] 2 \f[B]4\f[R] - Enables voluminous and fairly obscure tracing information that is likely only useful to the \f[B]libpmempool\f[R] developers. .PP Unless \f[B]PMEMPOOL_LOG_FILE\f[R] is set, debugging output is written to \f[I]stderr\f[R]. .IP \[bu] 2 \f[B]PMEMPOOL_LOG_FILE\f[R] .PP Specifies the name of a file where all logging information should be written. If the last character in the name is \[lq]-\[rq], the \f[I]PID\f[R] of the current process will be appended to the file name when the log file is created. If \f[B]PMEMPOOL_LOG_FILE\f[R] is not set, output is written to \f[I]stderr\f[R]. .SH EXAMPLE .PP The following example illustrates how the \f[B]libpmempool\f[R] API is used. The program detects the type and checks consistency of given pool. If there are any issues detected, the pool is automatically repaired. .IP .nf \f[C] #include #include #include #include #include #define PATH \[dq]./pmem-fs/myfile\[dq] #define CHECK_FLAGS (PMEMPOOL_CHECK_FORMAT_STR|PMEMPOOL_CHECK_REPAIR|\[rs] PMEMPOOL_CHECK_VERBOSE) int main(int argc, char *argv[]) { PMEMpoolcheck *ppc; struct pmempool_check_status *status; enum pmempool_check_result ret; /* arguments for check */ struct pmempool_check_args args = { .path = PATH, .backup_path = NULL, .pool_type = PMEMPOOL_POOL_TYPE_DETECT, .flags = CHECK_FLAGS }; /* initialize check context */ if ((ppc = pmempool_check_init(&args, sizeof(args))) == NULL) { perror(\[dq]pmempool_check_init\[dq]); exit(EXIT_FAILURE); } /* perform check and repair, answer \[aq]yes\[aq] for each question */ while ((status = pmempool_check(ppc)) != NULL) { switch (status->type) { case PMEMPOOL_CHECK_MSG_TYPE_ERROR: printf(\[dq]%s\[rs]n\[dq], status->str.msg); break; case PMEMPOOL_CHECK_MSG_TYPE_INFO: printf(\[dq]%s\[rs]n\[dq], status->str.msg); break; case PMEMPOOL_CHECK_MSG_TYPE_QUESTION: printf(\[dq]%s\[rs]n\[dq], status->str.msg); status->str.answer = \[dq]yes\[dq]; break; default: pmempool_check_end(ppc); exit(EXIT_FAILURE); } } /* finalize the check and get the result */ ret = pmempool_check_end(ppc); switch (ret) { case PMEMPOOL_CHECK_RESULT_CONSISTENT: case PMEMPOOL_CHECK_RESULT_REPAIRED: return 0; default: return 1; } } \f[R] .fi .PP See for more examples using the \f[B]libpmempool\f[R] API. .SH ACKNOWLEDGEMENTS .PP \f[B]libpmempool\f[R] builds on the persistent memory programming model recommended by the SNIA NVM Programming Technical Work Group: .SH SEE ALSO .PP \f[B]dlclose\f[R](3), \f[B]pmempool_check_init\f[R](3), \f[B]pmempool_feature_query\f[R](3), \f[B]pmempool_rm\f[R](3), \f[B]pmempool_sync\f[R](3), \f[B]strerror\f[R](3), \f[B]libpmem\f[R](7), \f[B]libpmemblk\f[R](7), \f[B]libpmemlog\f[R](7), \f[B]libpmemobj\f[R](7)\f[B] and \f[R]**