bcachefs: bch2_prt_csum_opt()

bounds checking helper

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2024-10-28 01:14:53 -04:00
parent 86066b111b
commit e1d67b5d67
4 changed files with 8 additions and 6 deletions

View File

@ -1030,7 +1030,7 @@ static inline _Bool bch2_csum_type_is_encryption(enum bch_csum_type type)
x(crc64, 2) \ x(crc64, 2) \
x(xxhash, 3) x(xxhash, 3)
enum bch_csum_opts { enum bch_csum_opt {
#define x(t, n) BCH_CSUM_OPT_##t = n, #define x(t, n) BCH_CSUM_OPT_##t = n,
BCH_CSUM_OPTS() BCH_CSUM_OPTS()
#undef x #undef x

View File

@ -109,7 +109,7 @@ int bch2_enable_encryption(struct bch_fs *, bool);
void bch2_fs_encryption_exit(struct bch_fs *); void bch2_fs_encryption_exit(struct bch_fs *);
int bch2_fs_encryption_init(struct bch_fs *); int bch2_fs_encryption_init(struct bch_fs *);
static inline enum bch_csum_type bch2_csum_opt_to_type(enum bch_csum_opts type, static inline enum bch_csum_type bch2_csum_opt_to_type(enum bch_csum_opt type,
bool data) bool data)
{ {
switch (type) { switch (type) {

View File

@ -48,7 +48,7 @@ static const char * const __bch2_csum_types[] = {
NULL NULL
}; };
const char * const bch2_csum_opts[] = { const char * const __bch2_csum_opts[] = {
BCH_CSUM_OPTS() BCH_CSUM_OPTS()
NULL NULL
}; };
@ -113,6 +113,7 @@ void bch2_prt_##name(struct printbuf *out, type t) \
PRT_STR_OPT_BOUNDSCHECKED(jset_entry_type, enum bch_jset_entry_type); PRT_STR_OPT_BOUNDSCHECKED(jset_entry_type, enum bch_jset_entry_type);
PRT_STR_OPT_BOUNDSCHECKED(fs_usage_type, enum bch_fs_usage_type); PRT_STR_OPT_BOUNDSCHECKED(fs_usage_type, enum bch_fs_usage_type);
PRT_STR_OPT_BOUNDSCHECKED(data_type, enum bch_data_type); PRT_STR_OPT_BOUNDSCHECKED(data_type, enum bch_data_type);
PRT_STR_OPT_BOUNDSCHECKED(csum_opt, enum bch_csum_opt);
PRT_STR_OPT_BOUNDSCHECKED(csum_type, enum bch_csum_type); PRT_STR_OPT_BOUNDSCHECKED(csum_type, enum bch_csum_type);
PRT_STR_OPT_BOUNDSCHECKED(compression_type, enum bch_compression_type); PRT_STR_OPT_BOUNDSCHECKED(compression_type, enum bch_compression_type);
PRT_STR_OPT_BOUNDSCHECKED(str_hash_type, enum bch_str_hash_type); PRT_STR_OPT_BOUNDSCHECKED(str_hash_type, enum bch_str_hash_type);

View File

@ -16,7 +16,7 @@ extern const char * const bch2_version_upgrade_opts[];
extern const char * const bch2_sb_features[]; extern const char * const bch2_sb_features[];
extern const char * const bch2_sb_compat[]; extern const char * const bch2_sb_compat[];
extern const char * const __bch2_btree_ids[]; extern const char * const __bch2_btree_ids[];
extern const char * const bch2_csum_opts[]; extern const char * const __bch2_csum_opts[];
extern const char * const bch2_compression_opts[]; extern const char * const bch2_compression_opts[];
extern const char * const __bch2_str_hash_types[]; extern const char * const __bch2_str_hash_types[];
extern const char * const bch2_str_hash_opts[]; extern const char * const bch2_str_hash_opts[];
@ -27,6 +27,7 @@ extern const char * const bch2_d_types[];
void bch2_prt_jset_entry_type(struct printbuf *, enum bch_jset_entry_type); void bch2_prt_jset_entry_type(struct printbuf *, enum bch_jset_entry_type);
void bch2_prt_fs_usage_type(struct printbuf *, enum bch_fs_usage_type); void bch2_prt_fs_usage_type(struct printbuf *, enum bch_fs_usage_type);
void bch2_prt_data_type(struct printbuf *, enum bch_data_type); void bch2_prt_data_type(struct printbuf *, enum bch_data_type);
void bch2_prt_csum_opt(struct printbuf *, enum bch_csum_opt);
void bch2_prt_csum_type(struct printbuf *, enum bch_csum_type); void bch2_prt_csum_type(struct printbuf *, enum bch_csum_type);
void bch2_prt_compression_type(struct printbuf *, enum bch_compression_type); void bch2_prt_compression_type(struct printbuf *, enum bch_compression_type);
void bch2_prt_str_hash_type(struct printbuf *, enum bch_str_hash_type); void bch2_prt_str_hash_type(struct printbuf *, enum bch_str_hash_type);
@ -171,12 +172,12 @@ enum fsck_err_opts {
"size", "Maximum size of checksummed/compressed extents")\ "size", "Maximum size of checksummed/compressed extents")\
x(metadata_checksum, u8, \ x(metadata_checksum, u8, \
OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
OPT_STR(bch2_csum_opts), \ OPT_STR(__bch2_csum_opts), \
BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \ BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
NULL, NULL) \ NULL, NULL) \
x(data_checksum, u8, \ x(data_checksum, u8, \
OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
OPT_STR(bch2_csum_opts), \ OPT_STR(__bch2_csum_opts), \
BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \ BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
NULL, NULL) \ NULL, NULL) \
x(compression, u8, \ x(compression, u8, \