2 #include <linux/kernel.h>
5 #include "disk_groups.h"
10 const char * const bch2_error_actions[] = {
17 const char * const bch2_csum_types[] = {
24 const char * const bch2_compression_types[] = {
32 const char * const bch2_str_hash_types[] = {
39 const char * const bch2_data_types[] = {
49 const char * const bch2_cache_replacement_policies[] = {
56 /* Default is -1; we skip past it for struct cached_dev's cache mode */
57 const char * const bch2_cache_modes[] = {
66 const char * const bch2_dev_state[] = {
74 void bch2_opts_apply(struct bch_opts *dst, struct bch_opts src)
76 #define BCH_OPT(_name, ...) \
77 if (opt_defined(src, _name)) \
78 opt_set(*dst, _name, src._name);
84 bool bch2_opt_defined_by_id(const struct bch_opts *opts, enum bch_opt_id id)
87 #define BCH_OPT(_name, ...) \
89 return opt_defined(*opts, _name);
97 u64 bch2_opt_get_by_id(const struct bch_opts *opts, enum bch_opt_id id)
100 #define BCH_OPT(_name, ...) \
110 void bch2_opt_set_by_id(struct bch_opts *opts, enum bch_opt_id id, u64 v)
113 #define BCH_OPT(_name, ...) \
115 opt_set(*opts, _name, v); \
125 * Initial options from superblock - here we don't want any options undefined,
126 * any options the superblock doesn't specify are set to 0:
128 struct bch_opts bch2_opts_from_sb(struct bch_sb *sb)
130 struct bch_opts opts = bch2_opts_empty();
132 #define BCH_OPT(_name, _bits, _mode, _type, _sb_opt, _default) \
133 if (_sb_opt != NO_SB_OPT) \
134 opt_set(opts, _name, _sb_opt(sb));
141 const struct bch_option bch2_opt_table[] = {
142 #define OPT_BOOL() .type = BCH_OPT_BOOL
143 #define OPT_UINT(_min, _max) .type = BCH_OPT_UINT, .min = _min, .max = _max
144 #define OPT_STR(_choices) .type = BCH_OPT_STR, .choices = _choices
145 #define OPT_FN(_fn) .type = BCH_OPT_FN, \
146 .parse = _fn##_parse, \
149 #define BCH_OPT(_name, _bits, _mode, _type, _sb_opt, _default) \
153 .mode = _mode == OPT_RUNTIME ? 0644 : 0444, \
156 .set_sb = SET_##_sb_opt, \
164 int bch2_opt_lookup(const char *name)
166 const struct bch_option *i;
168 for (i = bch2_opt_table;
169 i < bch2_opt_table + ARRAY_SIZE(bch2_opt_table);
171 if (!strcmp(name, i->attr.name))
172 return i - bch2_opt_table;
181 static const struct synonym bch_opt_synonyms[] = {
182 { "quota", "usrquota" },
185 static int bch2_mount_opt_lookup(const char *name)
187 const struct synonym *i;
189 for (i = bch_opt_synonyms;
190 i < bch_opt_synonyms + ARRAY_SIZE(bch_opt_synonyms);
192 if (!strcmp(name, i->s1))
195 return bch2_opt_lookup(name);
198 int bch2_opt_parse(struct bch_fs *c, const struct bch_option *opt,
199 const char *val, u64 *res)
205 ret = kstrtou64(val, 10, res);
213 ret = kstrtou64(val, 10, res);
217 if (*res < opt->min || *res >= opt->max)
221 ret = bch2_read_string_list(val, opt->choices);
231 return opt->parse(c, val, res);
237 int bch2_opt_to_text(struct bch_fs *c, char *buf, size_t len,
238 const struct bch_option *opt, u64 v,
241 char *out = buf, *end = buf + len;
243 if (flags & OPT_SHOW_MOUNT_STYLE) {
244 if (opt->type == BCH_OPT_BOOL)
245 return scnprintf(out, end - out, "%s%s",
249 out += scnprintf(out, end - out, "%s=", opt->attr.name);
255 out += scnprintf(out, end - out, "%lli", v);
258 out += (flags & OPT_SHOW_FULL_LIST)
259 ? bch2_scnprint_string_list(out, end - out, opt->choices, v)
260 : scnprintf(out, end - out, opt->choices[v]);
263 return opt->print(c, out, end - out, v);
271 int bch2_parse_mount_opts(struct bch_opts *opts, char *options)
273 char *opt, *name, *val;
277 while ((opt = strsep(&options, ",")) != NULL) {
278 name = strsep(&opt, "=");
282 id = bch2_mount_opt_lookup(name);
286 ret = bch2_opt_parse(NULL, &bch2_opt_table[id], val, &v);
290 id = bch2_mount_opt_lookup(name);
294 !strncmp("no", name, 2)) {
295 id = bch2_mount_opt_lookup(name + 2);
302 if (bch2_opt_table[id].type != BCH_OPT_BOOL)
306 if (bch2_opt_table[id].mode < OPT_MOUNT)
310 !IS_ENABLED(CONFIG_BCACHEFS_POSIX_ACL))
313 if ((id == Opt_usrquota ||
314 id == Opt_grpquota) &&
315 !IS_ENABLED(CONFIG_BCACHEFS_QUOTA))
318 bch2_opt_set_by_id(opts, id, v);
323 pr_err("Bad mount option %s", name);
326 pr_err("Invalid value %s for mount option %s", val, name);
329 pr_err("Mount option %s requires a value", name);
335 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts src)
337 struct bch_io_opts ret = { 0 };
338 #define BCH_INODE_OPT(_name, _bits) \
339 if (opt_defined(src, _name)) \
340 opt_set(ret, _name, src._name);
346 struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts src)
348 struct bch_opts ret = { 0 };
349 #define BCH_INODE_OPT(_name, _bits) \
350 if (opt_defined(src, _name)) \
351 opt_set(ret, _name, src._name);
357 void bch2_io_opts_apply(struct bch_io_opts *dst, struct bch_io_opts src)
359 #define BCH_INODE_OPT(_name, _bits) \
360 if (opt_defined(src, _name)) \
361 opt_set(*dst, _name, src._name);
366 bool bch2_opt_is_inode_opt(enum bch_opt_id id)
368 static const enum bch_opt_id inode_opt_list[] = {
369 #define BCH_INODE_OPT(_name, _bits) Opt_##_name,
375 for (i = 0; i < ARRAY_SIZE(inode_opt_list); i++)
376 if (inode_opt_list[i] == id)