1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright 2016-2020, Intel Corporation */
5 * check_util.h -- internal definitions check util
12 #include <sys/param.h>
18 #define CHECK_STEP_COMPLETE UINT_MAX
19 #define CHECK_INVALID_QUESTION UINT_MAX
21 #define REQUIRE_ADVANCED "the following error can be fixed using " \
22 "PMEMPOOL_CHECK_ADVANCED flag"
25 #define min(a, b) ((a) < (b) ? (a) : (b))
28 /* check control context */
32 /* queue of check statuses */
35 /* container storing state of all check steps */
36 #define PREFIX_MAX_SIZE 30
50 struct pool_hdr
*hdrp
;
51 /* copy of the pool header in host byte order */
55 * If pool header has been modified this field indicates that
56 * the pool parameters structure requires refresh.
58 int pool_hdr_modified
;
60 unsigned healthy_replicas
;
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
;
67 int next_part_hdr_valid
;
68 int prev_part_hdr_valid
;
69 int next_repl_hdr_valid
;
70 int prev_repl_hdr_valid
;
72 /* valid poolset uuid */
77 /* valid part pool header */
78 struct pool_hdr
*valid_part_hdrp
;
80 unsigned valid_part_replica
;
82 char prefix
[PREFIX_MAX_SIZE
];
92 struct list
*list_inval
;
93 struct list
*list_flog_inval
;
94 struct list
*list_unmap
;
102 struct btt_info btti
;
103 uint64_t btti_offset
;
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
);
119 struct check_data
*check_data_alloc(void);
120 void check_data_free(struct check_data
*data
);
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
);
126 void check_end(struct check_data
*data
);
127 int check_is_end_util(struct check_data
*data
);
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
);
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
);
145 /* create info status */
146 #define CHECK_INFO(ppc, ...)\
147 check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_INFO, 0, __VA_ARGS__)
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__)
154 /* create error status */
155 #define CHECK_ERR(ppc, ...)\
156 check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_ERROR, 0, __VA_ARGS__)
158 /* create question status */
159 #define CHECK_ASK(ppc, question, ...)\
160 check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_QUESTION, question,\
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))
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
);
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
);
177 void check_insert_arena(PMEMpoolcheck
*ppc
, struct arena
*arenap
);
180 void cache_to_utf8(struct check_data
*data
, char *buf
, size_t size
);
183 #define CHECK_IS(ppc, flag)\
184 util_flag_isset((ppc)->args.flags, PMEMPOOL_CHECK_ ## flag)
186 #define CHECK_IS_NOT(ppc, flag)\
187 util_flag_isclr((ppc)->args.flags, PMEMPOOL_CHECK_ ## flag)
189 #define CHECK_WITHOUT_FIXING(ppc)\
190 CHECK_IS_NOT(ppc, REPAIR) || CHECK_IS(ppc, DRY_RUN)