1PMEMOBJ_OPEN(3) PMDK Programmer's Manual PMEMOBJ_OPEN(3)
2
3
4
6 pmemobj_open(), pmemobj_create(), pmemobj_close(), pmemobj_check() --
7 create, open, close and validate persistent memory transactional object
8 store
9
11 #include <libpmemobj.h>
12
13 PMEMobjpool *pmemobj_open(const char *path, const char *layout);
14 PMEMobjpool *pmemobj_create(const char *path, const char *layout,
15 size_t poolsize, mode_t mode);
16 void pmemobj_close(PMEMobjpool *pop);
17 int pmemobj_check(const char *path, const char *layout);
18
20 To use the pmem-resident transactional object store provided by libp‐
21 memobj(7), a memory pool must first be created with the pmemobj_cre‐
22 ate() function described below. Existing pools may be opened with the
23 pmemobj_open() function.
24
25 None of the three functions described below is thread-safe with respect
26 to any other libpmemobj(7) functions. In other words, when creating,
27 opening or deleting a pool, nothing else in the library can happen in
28 parallel, and therefore these functions should be called from the main
29 thread.
30
31 Once created, the memory pool is represented by an opaque handle, of
32 type PMEMobjpool*, which is passed to most of the other libpmemobj(7)
33 functions. Internally, libpmemobj(7) will use either pmem_persist(3)
34 or msync(2) when it needs to flush changes, depending on whether the
35 memory pool appears to be persistent memory or a regular file (see the
36 pmem_is_pmem(3) function in libpmem(7) for more information). There is
37 no need for applications to flush changes directly when using the ob‐
38 ject memory API provided by libpmemobj(7).
39
40 The pmemobj_create() function creates a transactional object store with
41 the given total poolsize. path specifies the name of the memory pool
42 file to be created. layout specifies the application's layout type in
43 the form of a string. The layout name is not interpreted by libpmemo‐
44 bj(7), but may be used as a check when pmemobj_open() is called. The
45 layout name, including the terminating null byte (''), cannot be longer
46 than PMEMOBJ_MAX_LAYOUT as defined in <libpmemobj.h>. A NULL layout is
47 equivalent to using an empty string as a layout name. mode specifies
48 the permissions to use when creating the file, as described by cre‐
49 at(2). The memory pool file is fully allocated to the size poolsize
50 using posix_fallocate(3). The caller may choose to take responsibility
51 for creating the memory pool file by creating it before calling pmemo‐
52 bj_create(), and then specifying poolsize as zero. In this case pmemo‐
53 bj_create() will take the pool size from the size of the existing file
54 and will verify that the file appears to be empty by searching for any
55 non-zero data in the pool header at the beginning of the file. The
56 minimum net pool size allowed by the library for a local transactional
57 object store is defined in <libpmemobj.h> as PMEMOBJ_MIN_POOL. For re‐
58 mote replicas the minimum file size is defined in <librpmem.h> as RP‐
59 MEM_MIN_PART.
60
61 Depending on the configuration of the system, the available
62 non-volatile memory space may be divided into multiple memory devices.
63 In such case, the maximum size of the pmemobj memory pool could be lim‐
64 ited by the capacity of a single memory device. libpmemobj(7) allows
65 building persistent memory resident object store spanning multiple mem‐
66 ory devices by creation of persistent memory pools consisting of multi‐
67 ple files, where each part of such a pool set may be stored on a dif‐
68 ferent memory device or pmem-aware filesystem.
69
70 Creation of all the parts of the pool set can be done with pmemobj_cre‐
71 ate(); however, the recommended method for creating pool sets is with
72 the pmempool(1) utility.
73
74 When creating a pool set consisting of multiple files, the path argu‐
75 ment passed to pmemobj_create() must point to the special set file that
76 defines the pool layout and the location of all the parts of the pool
77 set. The poolsize argument must be 0. The meaning of the layout and
78 mode arguments does not change, except that the same mode is used for
79 creation of all the parts of the pool set.
80
81 The set file is a plain text file, the structure of which is described
82 in poolset(5).
83
84 The pmemobj_open() function opens an existing object store memory pool.
85 Similar to pmemobj_create(), path must identify either an existing obj
86 memory pool file, or the set file used to create a pool set. If layout
87 is non-NULL, it is compared to the layout name provided to pmemobj_cre‐
88 ate() when the pool was first created. This can be used to verify that
89 the layout of the pool matches what was expected. The application must
90 have permission to open the file and memory map it with read/write per‐
91 missions.
92
93 The pmemobj_close() function closes the memory pool indicated by pop
94 and deletes the memory pool handle. The object store itself lives on
95 in the file that contains it and may be re-opened at a later time using
96 pmemobj_open() as described above.
97
98 The pmemobj_check() function performs a consistency check of the file
99 indicated by path. pmemobj_check() opens the given path read-only so
100 it never makes any changes to the file. This function is not supported
101 on Device DAX.
102
104 The pmemobj_create() function returns a memory pool handle to be used
105 with most of the functions in libpmemobj(7). On error it returns NULL
106 and sets errno appropriately.
107
108 The pmemobj_open() function returns a memory pool handle to be used
109 with most of the functions in libpmemobj(7). If an error prevents the
110 pool from being opened, or if the given layout does not match the
111 pool's layout, pmemobj_open() returns NULL and sets errno appropriate‐
112 ly.
113
114 The pmemobj_close() function returns no value.
115
116 The pmemobj_check() function returns 1 if the memory pool is found to
117 be consistent. Any inconsistencies found will cause pmemobj_check() to
118 return 0, in which case the use of the file with libpmemobj(7) will re‐
119 sult in undefined behavior. The debug version of libpmemobj(7) will
120 provide additional details on inconsistencies when PMEMOBJ_LOG_LEVEL is
121 at least 1, asdescribed in the DEBUGGING AND ERROR HANDLING section in
122 libpmemobj(7). pmemobj_check() returns -1 and sets errno if it cannot
123 perform the consistency check due to other errors.
124
126 Not all file systems support posix_fallocate(3). pmemobj_create() will
127 fail if the underlying file system does not support posix_fallocate(3).
128
130 creat(2), msync(2), pmem_is_pmem(3), pmem_persist(3), posix_fallo‐
131 cate(3), libpmem(7), libpmemobj(7) and <http://pmem.io>
132
133
134
135PMDK - pmemobj API version 2.3 2018-03-13 PMEMOBJ_OPEN(3)