2 #include <linux/kernel.h>
7 const char * const bch2_error_actions[] = {
14 const char * const bch2_csum_types[] = {
21 const char * const bch2_compression_types[] = {
28 const char * const bch2_str_hash_types[] = {
35 const char * const bch2_data_types[] = {
44 const char * const bch2_cache_replacement_policies[] = {
51 /* Default is -1; we skip past it for struct cached_dev's cache mode */
52 const char * const bch2_cache_modes[] = {
61 const char * const bch2_dev_state[] = {
69 void bch2_opts_apply(struct bch_opts *dst, struct bch_opts src)
71 #define BCH_OPT(_name, ...) \
72 if (opt_defined(src, _name)) \
73 opt_set(*dst, _name, src._name);
79 bool bch2_opt_defined_by_id(const struct bch_opts *opts, enum bch_opt_id id)
82 #define BCH_OPT(_name, ...) \
84 return opt_defined(*opts, _name);
92 u64 bch2_opt_get_by_id(const struct bch_opts *opts, enum bch_opt_id id)
95 #define BCH_OPT(_name, ...) \
105 void bch2_opt_set_by_id(struct bch_opts *opts, enum bch_opt_id id, u64 v)
108 #define BCH_OPT(_name, ...) \
110 opt_set(*opts, _name, v); \
120 * Initial options from superblock - here we don't want any options undefined,
121 * any options the superblock doesn't specify are set to 0:
123 struct bch_opts bch2_opts_from_sb(struct bch_sb *sb)
125 struct bch_opts opts = bch2_opts_empty();
127 #define BCH_OPT(_name, _bits, _mode, _type, _sb_opt, _default) \
128 if (_sb_opt != NO_SB_OPT) \
129 opt_set(opts, _name, _sb_opt(sb));
136 const struct bch_option bch2_opt_table[] = {
137 #define OPT_BOOL() .type = BCH_OPT_BOOL
138 #define OPT_UINT(_min, _max) .type = BCH_OPT_UINT, .min = _min, .max = _max
139 #define OPT_STR(_choices) .type = BCH_OPT_STR, .choices = _choices
141 #define BCH_OPT(_name, _bits, _mode, _type, _sb_opt, _default) \
145 .mode = _mode == OPT_RUNTIME ? 0644 : 0444, \
148 .set_sb = SET_##_sb_opt, \
156 int bch2_opt_lookup(const char *name)
158 const struct bch_option *i;
160 for (i = bch2_opt_table;
161 i < bch2_opt_table + ARRAY_SIZE(bch2_opt_table);
163 if (!strcmp(name, i->attr.name))
164 return i - bch2_opt_table;
169 int bch2_opt_parse(const struct bch_option *opt, const char *val, u64 *res)
175 ret = kstrtou64(val, 10, res);
183 ret = kstrtou64(val, 10, res);
187 if (*res < opt->min || *res >= opt->max)
191 ret = bch2_read_string_list(val, opt->choices);
202 int bch2_parse_mount_opts(struct bch_opts *opts, char *options)
204 char *opt, *name, *val;
208 while ((opt = strsep(&options, ",")) != NULL) {
209 name = strsep(&opt, "=");
213 id = bch2_opt_lookup(name);
217 ret = bch2_opt_parse(&bch2_opt_table[id], val, &v);
221 id = bch2_opt_lookup(name);
225 !strncmp("no", name, 2)) {
226 id = bch2_opt_lookup(name + 2);
233 if (bch2_opt_table[id].type != BCH_OPT_BOOL)
237 if (bch2_opt_table[id].mode < OPT_MOUNT)
241 !IS_ENABLED(CONFIG_BCACHEFS_POSIX_ACL))
244 bch2_opt_set_by_id(opts, id, v);
249 pr_err("Bad mount option %s", name);
252 pr_err("Invalid value %s for mount option %s", val, name);
255 pr_err("Mount option %s requires a value", name);
261 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts src)
263 struct bch_io_opts ret = { 0 };
264 #define BCH_INODE_OPT(_name, _bits) \
265 if (opt_defined(src, _name)) \
266 opt_set(ret, _name, src._name);
272 struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts src)
274 struct bch_opts ret = { 0 };
275 #define BCH_INODE_OPT(_name, _bits) \
276 if (opt_defined(src, _name)) \
277 opt_set(ret, _name, src._name);
283 void bch2_io_opts_apply(struct bch_io_opts *dst, struct bch_io_opts src)
285 #define BCH_INODE_OPT(_name, _bits) \
286 if (opt_defined(src, _name)) \
287 opt_set(*dst, _name, src._name);
292 bool bch2_opt_is_inode_opt(enum bch_opt_id id)
294 static const enum bch_opt_id inode_opt_list[] = {
295 #define BCH_INODE_OPT(_name, _bits) Opt_##_name,
301 for (i = 0; i < ARRAY_SIZE(inode_opt_list); i++)
302 if (inode_opt_list[i] == id)