]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/src/tools/pmempool/common.h
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright 2014-2020, Intel Corporation */
5 * common.h -- declarations of common functions
16 #include "libpmemobj.h"
24 #include "heap_layout.h"
27 #include "btt_layout.h"
28 #include "page_size.h"
30 /* XXX - modify Linux makefiles to generate srcversion.h and remove #ifdef */
32 #include "srcversion.h"
35 #define COUNT_OF(x) (sizeof(x) / sizeof(0[x]))
38 #define OPT_MASK (~((1 << OPT_SHIFT) - 1))
39 #define OPT_LOG (1 << (PMEM_POOL_TYPE_LOG + OPT_SHIFT))
40 #define OPT_BLK (1 << (PMEM_POOL_TYPE_BLK + OPT_SHIFT))
41 #define OPT_OBJ (1 << (PMEM_POOL_TYPE_OBJ + OPT_SHIFT))
42 #define OPT_BTT (1 << (PMEM_POOL_TYPE_BTT + OPT_SHIFT))
43 #define OPT_ALL (OPT_LOG | OPT_BLK | OPT_OBJ | OPT_BTT)
45 #define OPT_REQ_SHIFT 8
46 #define OPT_REQ_MASK ((1 << OPT_REQ_SHIFT) - 1)
47 #define _OPT_REQ(c, n) ((c) << (OPT_REQ_SHIFT * (n)))
48 #define OPT_REQ0(c) _OPT_REQ(c, 0)
49 #define OPT_REQ1(c) _OPT_REQ(c, 1)
50 #define OPT_REQ2(c) _OPT_REQ(c, 2)
51 #define OPT_REQ3(c) _OPT_REQ(c, 3)
52 #define OPT_REQ4(c) _OPT_REQ(c, 4)
53 #define OPT_REQ5(c) _OPT_REQ(c, 5)
54 #define OPT_REQ6(c) _OPT_REQ(c, 6)
55 #define OPT_REQ7(c) _OPT_REQ(c, 7)
58 #define min(a, b) ((a) < (b) ? (a) : (b))
61 #define FOREACH_RANGE(range, ranges)\
62 PMDK_LIST_FOREACH(range, &(ranges)->head, next)
64 #define PLIST_OFF_TO_PTR(pop, off)\
65 ((off) == 0 ? NULL : (void *)((uintptr_t)(pop) + (off) - OBJ_OOB_SIZE))
67 #define ENTRY_TO_ALLOC_HDR(entry)\
68 ((void *)((uintptr_t)(entry) - sizeof(struct allocation_header)))
70 #define OBJH_FROM_PTR(ptr)\
71 ((void *)((uintptr_t)(ptr) - sizeof(struct legacy_object_header)))
73 #define DEFAULT_HDR_SIZE PMEM_PAGESIZE
74 #define DEFAULT_DESC_SIZE PMEM_PAGESIZE
75 #define POOL_HDR_DESC_SIZE (DEFAULT_HDR_SIZE + DEFAULT_DESC_SIZE)
77 #define PTR_TO_ALLOC_HDR(ptr)\
78 ((void *)((uintptr_t)(ptr) -\
79 sizeof(struct legacy_object_header)))
81 #define OBJH_TO_PTR(objh)\
82 ((void *)((uintptr_t)(objh) + sizeof(struct legacy_object_header)))
84 /* invalid answer for ask_* functions */
87 #define FORMAT_PRINTF(a, b) __attribute__((__format__(__printf__, (a), (b))))
90 * pmem_pool_type_t -- pool types
93 PMEM_POOL_TYPE_LOG
= 0x01,
94 PMEM_POOL_TYPE_BLK
= 0x02,
95 PMEM_POOL_TYPE_OBJ
= 0x04,
96 PMEM_POOL_TYPE_BTT
= 0x08,
97 PMEM_POOL_TYPE_ALL
= 0x0f,
98 PMEM_POOL_TYPE_UNKNOWN
= 0x80,
101 struct option_requirement
{
103 pmem_pool_type_t type
;
108 const struct option
*opts
;
111 const struct option_requirement
*req
;
114 struct pmem_pool_params
{
115 pmem_pool_type_t type
;
116 char signature
[POOL_HDR_SIG_LEN
];
127 char layout
[PMEMOBJ_MAX_LAYOUT
];
132 struct pool_set_file
{
137 struct pool_set
*poolset
;
144 struct pool_set_file
*pool_set_file_open(const char *fname
,
145 int rdonly
, int check
);
146 void pool_set_file_close(struct pool_set_file
*file
);
147 int pool_set_file_read(struct pool_set_file
*file
, void *buff
,
148 size_t nbytes
, uint64_t off
);
149 int pool_set_file_write(struct pool_set_file
*file
, void *buff
,
150 size_t nbytes
, uint64_t off
);
151 int pool_set_file_set_replica(struct pool_set_file
*file
, size_t replica
);
152 size_t pool_set_file_nreplicas(struct pool_set_file
*file
);
153 void *pool_set_file_map(struct pool_set_file
*file
, uint64_t offset
);
154 void pool_set_file_persist(struct pool_set_file
*file
,
155 const void *addr
, size_t len
);
158 PMDK_LIST_ENTRY(range
) next
;
164 PMDK_LIST_HEAD(rangeshead
, range
) head
;
167 pmem_pool_type_t
pmem_pool_type_parse_hdr(const struct pool_hdr
*hdrp
);
168 pmem_pool_type_t
pmem_pool_type(const void *base_pool_addr
);
169 int pmem_pool_checksum(const void *base_pool_addr
);
170 pmem_pool_type_t
pmem_pool_type_parse_str(const char *str
);
171 uint64_t pmem_pool_get_min_size(pmem_pool_type_t type
);
172 int pmem_pool_parse_params(const char *fname
, struct pmem_pool_params
*paramsp
,
174 int util_poolset_map(const char *fname
, struct pool_set
**poolset
, int rdonly
);
175 struct options
*util_options_alloc(const struct option
*options
,
176 size_t nopts
, const struct option_requirement
*req
);
177 void util_options_free(struct options
*opts
);
178 int util_options_verify(const struct options
*opts
, pmem_pool_type_t type
);
179 int util_options_getopt(int argc
, char *argv
[], const char *optstr
,
180 const struct options
*opts
);
181 pmem_pool_type_t
util_get_pool_type_second_page(const void *pool_base_addr
);
182 int util_parse_mode(const char *str
, mode_t
*mode
);
183 int util_parse_ranges(const char *str
, struct ranges
*rangesp
,
184 struct range entire
);
185 int util_ranges_add(struct ranges
*rangesp
, struct range range
);
186 void util_ranges_clear(struct ranges
*rangesp
);
187 int util_ranges_contain(const struct ranges
*rangesp
, uint64_t n
);
188 int util_ranges_empty(const struct ranges
*rangesp
);
189 int util_check_memory(const uint8_t *buff
, size_t len
, uint8_t val
);
190 int util_parse_chunk_types(const char *str
, uint64_t *types
);
191 int util_parse_lane_sections(const char *str
, uint64_t *types
);
192 char ask(char op
, char *answers
, char def_ans
, const char *fmt
, va_list ap
);
193 char ask_Yn(char op
, const char *fmt
, ...) FORMAT_PRINTF(2, 3);
194 char ask_yN(char op
, const char *fmt
, ...) FORMAT_PRINTF(2, 3);
195 unsigned util_heap_max_zone(size_t size
);
197 int util_pool_clear_badblocks(const char *path
, int create
);
199 static const struct range ENTIRE_UINT64
= {
200 { NULL
, NULL
}, /* range */
202 UINT64_MAX
/* last */