bcachefs: data_allowed is now an opts.h option
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 15 Jul 2024 20:53:49 +0000 (16:53 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 9 Sep 2024 13:41:47 +0000 (09:41 -0400)
need this so cmd_option in userspace can handle it

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/opts.c
fs/bcachefs/opts.h
fs/bcachefs/util.c
fs/bcachefs/util.h

index e10fc1d..8e2fd06 100644 (file)
@@ -230,6 +230,8 @@ const struct bch_option bch2_opt_table[] = {
 #define OPT_STR_NOLIMIT(_choices)      .type = BCH_OPT_STR,            \
                                .min = 0, .max = U64_MAX,               \
                                .choices = _choices
+#define OPT_BITFIELD(_choices) .type = BCH_OPT_BITFIELD,               \
+                               .choices = _choices
 #define OPT_FN(_fn)            .type = BCH_OPT_FN, .fn = _fn
 
 #define x(_name, _bits, _flags, _type, _sb_opt, _default, _hint, _help)        \
@@ -376,6 +378,13 @@ int bch2_opt_parse(struct bch_fs *c,
 
                *res = ret;
                break;
+       case BCH_OPT_BITFIELD: {
+               s64 v = bch2_read_flag_list(val, opt->choices);
+               if (v < 0)
+                       return v;
+               *res = v;
+               break;
+       }
        case BCH_OPT_FN:
                ret = opt->fn.parse(c, val, res, err);
 
index cda1725..1c7b68b 100644 (file)
@@ -70,6 +70,7 @@ enum opt_type {
        BCH_OPT_BOOL,
        BCH_OPT_UINT,
        BCH_OPT_STR,
+       BCH_OPT_BITFIELD,
        BCH_OPT_FN,
 };
 
@@ -477,6 +478,11 @@ enum fsck_err_opts {
          BCH2_NO_SB_OPT,               1,                              \
          "n",          "Data written to this device will be considered\n"\
                        "to have already been replicated n times")      \
+       x(data_allowed,                 u8,                             \
+         OPT_DEVICE,                                                   \
+         OPT_BITFIELD(__bch2_data_types),                              \
+         BCH2_NO_SB_OPT,               BIT(BCH_DATA_journal)|BIT(BCH_DATA_btree)|BIT(BCH_DATA_user),\
+         "types",      "Allowed data types for this device: journal, btree, and/or user")\
        x(btree_node_prefetch,          u8,                             \
          OPT_FS|OPT_MOUNT|OPT_RUNTIME,                                 \
          OPT_BOOL(),                                                   \
index 144d8df..8b4e839 100644 (file)
@@ -204,7 +204,7 @@ STRTO_H(strtoll, long long)
 STRTO_H(strtoull, unsigned long long)
 STRTO_H(strtou64, u64)
 
-u64 bch2_read_flag_list(char *opt, const char * const list[])
+u64 bch2_read_flag_list(const char *opt, const char * const list[])
 {
        u64 ret = 0;
        char *p, *s, *d = kstrdup(opt, GFP_KERNEL);
index 902b7f5..fb02c1c 100644 (file)
@@ -195,7 +195,7 @@ static inline int bch2_strtoul_h(const char *cp, long *res)
 
 bool bch2_is_zero(const void *, size_t);
 
-u64 bch2_read_flag_list(char *, const char * const[]);
+u64 bch2_read_flag_list(const char *, const char * const[]);
 
 void bch2_prt_u64_base2_nbits(struct printbuf *, u64, unsigned);
 void bch2_prt_u64_base2(struct printbuf *, u64);