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[] = {
45 const char * const bch2_cache_replacement_policies[] = {
52 /* Default is -1; we skip past it for struct cached_dev's cache mode */
53 const char * const bch2_cache_modes[] = {
62 const char * const bch2_dev_state[] = {
70 void bch2_opts_apply(struct bch_opts *dst, struct bch_opts src)
72 #define BCH_OPT(_name, ...) \
73 if (opt_defined(src, _name)) \
74 opt_set(*dst, _name, src._name);
80 bool bch2_opt_defined_by_id(const struct bch_opts *opts, enum bch_opt_id id)
83 #define BCH_OPT(_name, ...) \
85 return opt_defined(*opts, _name);
93 u64 bch2_opt_get_by_id(const struct bch_opts *opts, enum bch_opt_id id)
96 #define BCH_OPT(_name, ...) \
106 void bch2_opt_set_by_id(struct bch_opts *opts, enum bch_opt_id id, u64 v)
109 #define BCH_OPT(_name, ...) \
111 opt_set(*opts, _name, v); \
121 * Initial options from superblock - here we don't want any options undefined,
122 * any options the superblock doesn't specify are set to 0:
124 struct bch_opts bch2_opts_from_sb(struct bch_sb *sb)
126 struct bch_opts opts = bch2_opts_empty();
128 #define BCH_OPT(_name, _bits, _mode, _type, _sb_opt, _default) \
129 if (_sb_opt != NO_SB_OPT) \
130 opt_set(opts, _name, _sb_opt(sb));
137 const struct bch_option bch2_opt_table[] = {
138 #define OPT_BOOL() .type = BCH_OPT_BOOL
139 #define OPT_UINT(_min, _max) .type = BCH_OPT_UINT, .min = _min, .max = _max
140 #define OPT_STR(_choices) .type = BCH_OPT_STR, .choices = _choices
142 #define BCH_OPT(_name, _bits, _mode, _type, _sb_opt, _default) \
146 .mode = _mode == OPT_RUNTIME ? 0644 : 0444, \
149 .set_sb = SET_##_sb_opt, \
157 int bch2_opt_lookup(const char *name)
159 const struct bch_option *i;
161 for (i = bch2_opt_table;
162 i < bch2_opt_table + ARRAY_SIZE(bch2_opt_table);
164 if (!strcmp(name, i->attr.name))
165 return i - bch2_opt_table;
174 static const struct synonym bch_opt_synonyms[] = {
175 { "quota", "usrquota" },
178 static int bch2_mount_opt_lookup(const char *name)
180 const struct synonym *i;
182 for (i = bch_opt_synonyms;
183 i < bch_opt_synonyms + ARRAY_SIZE(bch_opt_synonyms);
185 if (!strcmp(name, i->s1))
188 return bch2_opt_lookup(name);
191 int bch2_opt_parse(const struct bch_option *opt, const char *val, u64 *res)
197 ret = kstrtou64(val, 10, res);
205 ret = kstrtou64(val, 10, res);
209 if (*res < opt->min || *res >= opt->max)
213 ret = bch2_read_string_list(val, opt->choices);
224 int bch2_parse_mount_opts(struct bch_opts *opts, char *options)
226 char *opt, *name, *val;
230 while ((opt = strsep(&options, ",")) != NULL) {
231 name = strsep(&opt, "=");
235 id = bch2_mount_opt_lookup(name);
239 ret = bch2_opt_parse(&bch2_opt_table[id], val, &v);
243 id = bch2_mount_opt_lookup(name);
247 !strncmp("no", name, 2)) {
248 id = bch2_mount_opt_lookup(name + 2);
255 if (bch2_opt_table[id].type != BCH_OPT_BOOL)
259 if (bch2_opt_table[id].mode < OPT_MOUNT)
263 !IS_ENABLED(CONFIG_BCACHEFS_POSIX_ACL))
266 if ((id == Opt_usrquota ||
267 id == Opt_grpquota) &&
268 !IS_ENABLED(CONFIG_BCACHEFS_QUOTA))
271 bch2_opt_set_by_id(opts, id, v);
276 pr_err("Bad mount option %s", name);
279 pr_err("Invalid value %s for mount option %s", val, name);
282 pr_err("Mount option %s requires a value", name);
288 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts src)
290 struct bch_io_opts ret = { 0 };
291 #define BCH_INODE_OPT(_name, _bits) \
292 if (opt_defined(src, _name)) \
293 opt_set(ret, _name, src._name);
299 struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts src)
301 struct bch_opts ret = { 0 };
302 #define BCH_INODE_OPT(_name, _bits) \
303 if (opt_defined(src, _name)) \
304 opt_set(ret, _name, src._name);
310 void bch2_io_opts_apply(struct bch_io_opts *dst, struct bch_io_opts src)
312 #define BCH_INODE_OPT(_name, _bits) \
313 if (opt_defined(src, _name)) \
314 opt_set(*dst, _name, src._name);
319 bool bch2_opt_is_inode_opt(enum bch_opt_id id)
321 static const enum bch_opt_id inode_opt_list[] = {
322 #define BCH_INODE_OPT(_name, _bits) Opt_##_name,
328 for (i = 0; i < ARRAY_SIZE(inode_opt_list); i++)
329 if (inode_opt_list[i] == id)