]> git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/src/libpmempool/check_util.h
import ceph 16.2.7
[ceph.git] / ceph / src / pmdk / src / libpmempool / check_util.h
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright 2016-2020, Intel Corporation */
3
4 /*
5 * check_util.h -- internal definitions check util
6 */
7 #ifndef CHECK_UTIL_H
8 #define CHECK_UTIL_H
9
10 #include <time.h>
11 #include <limits.h>
12 #include <sys/param.h>
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 #define CHECK_STEP_COMPLETE UINT_MAX
19 #define CHECK_INVALID_QUESTION UINT_MAX
20
21 #define REQUIRE_ADVANCED "the following error can be fixed using " \
22 "PMEMPOOL_CHECK_ADVANCED flag"
23
24 #ifndef min
25 #define min(a, b) ((a) < (b) ? (a) : (b))
26 #endif
27
28 /* check control context */
29 struct check_data;
30 struct arena;
31
32 /* queue of check statuses */
33 struct check_status;
34
35 /* container storing state of all check steps */
36 #define PREFIX_MAX_SIZE 30
37 typedef struct {
38 unsigned init_done;
39 unsigned step;
40
41 unsigned replica;
42 unsigned part;
43
44 int single_repl;
45 int single_part;
46
47 struct pool_set *set;
48 int is_dev_dax;
49
50 struct pool_hdr *hdrp;
51 /* copy of the pool header in host byte order */
52 struct pool_hdr hdr;
53 int hdr_valid;
54 /*
55 * If pool header has been modified this field indicates that
56 * the pool parameters structure requires refresh.
57 */
58 int pool_hdr_modified;
59
60 unsigned healthy_replicas;
61
62 struct pool_hdr *next_part_hdrp;
63 struct pool_hdr *prev_part_hdrp;
64 struct pool_hdr *next_repl_hdrp;
65 struct pool_hdr *prev_repl_hdrp;
66
67 int next_part_hdr_valid;
68 int prev_part_hdr_valid;
69 int next_repl_hdr_valid;
70 int prev_repl_hdr_valid;
71
72 /* valid poolset uuid */
73 uuid_t *valid_puuid;
74 /* valid part uuid */
75 uuid_t *valid_uuid;
76
77 /* valid part pool header */
78 struct pool_hdr *valid_part_hdrp;
79 int valid_part_done;
80 unsigned valid_part_replica;
81
82 char prefix[PREFIX_MAX_SIZE];
83
84 struct arena *arenap;
85 uint64_t offset;
86 uint32_t narena;
87
88 uint8_t *bitmap;
89 uint8_t *dup_bitmap;
90 uint8_t *fbitmap;
91
92 struct list *list_inval;
93 struct list *list_flog_inval;
94 struct list *list_unmap;
95
96 struct {
97 int btti_header;
98 int btti_backup;
99 } valid;
100
101 struct {
102 struct btt_info btti;
103 uint64_t btti_offset;
104 } pool_valid;
105 } location;
106
107 /* check steps */
108 void check_bad_blocks(PMEMpoolcheck *ppc);
109 void check_backup(PMEMpoolcheck *ppc);
110 void check_pool_hdr(PMEMpoolcheck *ppc);
111 void check_pool_hdr_uuids(PMEMpoolcheck *ppc);
112 void check_sds(PMEMpoolcheck *ppc);
113 void check_log(PMEMpoolcheck *ppc);
114 void check_blk(PMEMpoolcheck *ppc);
115 void check_btt_info(PMEMpoolcheck *ppc);
116 void check_btt_map_flog(PMEMpoolcheck *ppc);
117 void check_write(PMEMpoolcheck *ppc);
118
119 struct check_data *check_data_alloc(void);
120 void check_data_free(struct check_data *data);
121
122 uint32_t check_step_get(struct check_data *data);
123 void check_step_inc(struct check_data *data);
124 location *check_get_step_data(struct check_data *data);
125
126 void check_end(struct check_data *data);
127 int check_is_end_util(struct check_data *data);
128
129 int check_status_create(PMEMpoolcheck *ppc, enum pmempool_check_msg_type type,
130 uint32_t arg, const char *fmt, ...) FORMAT_PRINTF(4, 5);
131 void check_status_release(PMEMpoolcheck *ppc, struct check_status *status);
132 void check_clear_status_cache(struct check_data *data);
133 struct check_status *check_pop_question(struct check_data *data);
134 struct check_status *check_pop_error(struct check_data *data);
135 struct check_status *check_pop_info(struct check_data *data);
136 bool check_has_error(struct check_data *data);
137 bool check_has_answer(struct check_data *data);
138 int check_push_answer(PMEMpoolcheck *ppc);
139
140 struct pmempool_check_status *check_status_get_util(
141 struct check_status *status);
142 int check_status_is(struct check_status *status,
143 enum pmempool_check_msg_type type);
144
145 /* create info status */
146 #define CHECK_INFO(ppc, ...)\
147 check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_INFO, 0, __VA_ARGS__)
148
149 /* create info status and append error message based on errno */
150 #define CHECK_INFO_ERRNO(ppc, ...)\
151 check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_INFO,\
152 (uint32_t)errno, __VA_ARGS__)
153
154 /* create error status */
155 #define CHECK_ERR(ppc, ...)\
156 check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_ERROR, 0, __VA_ARGS__)
157
158 /* create question status */
159 #define CHECK_ASK(ppc, question, ...)\
160 check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_QUESTION, question,\
161 __VA_ARGS__)
162
163 #define CHECK_NOT_COMPLETE(loc, steps)\
164 ((loc)->step != CHECK_STEP_COMPLETE &&\
165 ((steps)[(loc)->step].check != NULL ||\
166 (steps)[(loc)->step].fix != NULL))
167
168 int check_answer_loop(PMEMpoolcheck *ppc, location *data,
169 void *ctx, int fail_on_no,
170 int (*callback)(PMEMpoolcheck *, location *, uint32_t, void *ctx));
171 int check_questions_sequence_validate(PMEMpoolcheck *ppc);
172
173 const char *check_get_time_str(time_t time);
174 const char *check_get_uuid_str(uuid_t uuid);
175 const char *check_get_pool_type_str(enum pool_type type);
176
177 void check_insert_arena(PMEMpoolcheck *ppc, struct arena *arenap);
178
179 #ifdef _WIN32
180 void cache_to_utf8(struct check_data *data, char *buf, size_t size);
181 #endif
182
183 #define CHECK_IS(ppc, flag)\
184 util_flag_isset((ppc)->args.flags, PMEMPOOL_CHECK_ ## flag)
185
186 #define CHECK_IS_NOT(ppc, flag)\
187 util_flag_isclr((ppc)->args.flags, PMEMPOOL_CHECK_ ## flag)
188
189 #define CHECK_WITHOUT_FIXING(ppc)\
190 CHECK_IS_NOT(ppc, REPAIR) || CHECK_IS(ppc, DRY_RUN)
191
192 #ifdef __cplusplus
193 }
194 #endif
195
196 #endif