Lines Matching +full:c +full:- +full:define +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0
11 #include "super-io.h"
14 #define x(t, n, ...) [n] = #t,
107 #define PRT_STR_OPT_BOUNDSCHECKED(name, type) \ argument
108 void bch2_prt_##name(struct printbuf *out, type t) \
110 prt_str_opt_boundscheck(out, __bch2_##name##s, ARRAY_SIZE(__bch2_##name##s) - 1, #name, t);\
120 static int bch2_opt_fix_errors_parse(struct bch_fs *c, const char *val, u64 *res, in bch2_opt_fix_errors_parse() argument
126 int ret = match_string(bch2_fsck_fix_opts, -1, val); in bch2_opt_fix_errors_parse()
139 struct bch_fs *c, in bch2_opt_fix_errors_to_text() argument
146 #define bch2_opt_fix_errors (struct bch_opt_fn) { \
176 #define x(_name, ...) \ in bch2_opts_apply()
187 #define x(_name, ...) \ in bch2_opt_defined_by_id()
200 #define x(_name, ...) \ in bch2_opt_get_by_id()
202 return opts->_name; in bch2_opt_get_by_id()
213 #define x(_name, ...) \ in bch2_opt_set_by_id()
225 #define OPT_BOOL() .type = BCH_OPT_BOOL, .min = 0, .max = 2
226 #define OPT_UINT(_min, _max) .type = BCH_OPT_UINT, \
228 #define OPT_STR(_choices) .type = BCH_OPT_STR, \
229 .min = 0, .max = ARRAY_SIZE(_choices) - 1, \
231 #define OPT_STR_NOLIMIT(_choices) .type = BCH_OPT_STR, \
234 #define OPT_BITFIELD(_choices) .type = BCH_OPT_BITFIELD, \
236 #define OPT_FN(_fn) .type = BCH_OPT_FN, .fn = _fn
238 #define x(_name, _bits, _flags, _type, _sb_opt, _default, _hint, _help) \
241 .name = #_name, \
256 int bch2_opt_lookup(const char *name) in bch2_opt_lookup() argument
263 if (!strcmp(name, i->attr.name)) in bch2_opt_lookup()
264 return i - bch2_opt_table; in bch2_opt_lookup()
266 return -1; in bch2_opt_lookup()
277 static int bch2_mount_opt_lookup(const char *name) in bch2_mount_opt_lookup() argument
284 if (!strcmp(name, i->s1)) in bch2_mount_opt_lookup()
285 name = i->s2; in bch2_mount_opt_lookup()
287 return bch2_opt_lookup(name); in bch2_mount_opt_lookup()
292 if (v < opt->min) { in bch2_opt_validate()
295 opt->attr.name, opt->min); in bch2_opt_validate()
296 return -BCH_ERR_ERANGE_option_too_small; in bch2_opt_validate()
299 if (opt->max && v >= opt->max) { in bch2_opt_validate()
302 opt->attr.name, opt->max); in bch2_opt_validate()
303 return -BCH_ERR_ERANGE_option_too_big; in bch2_opt_validate()
306 if ((opt->flags & OPT_SB_FIELD_SECTORS) && (v & 511)) { in bch2_opt_validate()
309 opt->attr.name); in bch2_opt_validate()
310 return -BCH_ERR_opt_parse_error; in bch2_opt_validate()
313 if ((opt->flags & OPT_MUST_BE_POW_2) && !is_power_of_2(v)) { in bch2_opt_validate()
316 opt->attr.name); in bch2_opt_validate()
317 return -BCH_ERR_opt_parse_error; in bch2_opt_validate()
320 if (opt->fn.validate) in bch2_opt_validate()
321 return opt->fn.validate(v, err); in bch2_opt_validate()
326 int bch2_opt_parse(struct bch_fs *c, in bch2_opt_parse() argument
333 switch (opt->type) { in bch2_opt_parse()
344 prt_printf(err, "%s: must be bool", opt->attr.name); in bch2_opt_parse()
345 return ret < 0 ? ret : -BCH_ERR_option_not_bool; in bch2_opt_parse()
351 opt->attr.name); in bch2_opt_parse()
352 return -EINVAL; in bch2_opt_parse()
355 ret = opt->flags & OPT_HUMAN_READABLE in bch2_opt_parse()
361 opt->attr.name); in bch2_opt_parse()
368 opt->attr.name); in bch2_opt_parse()
369 return -EINVAL; in bch2_opt_parse()
372 ret = match_string(opt->choices, -1, val); in bch2_opt_parse()
376 opt->attr.name); in bch2_opt_parse()
383 s64 v = bch2_read_flag_list(val, opt->choices); in bch2_opt_parse()
390 ret = opt->fn.parse(c, val, res, err); in bch2_opt_parse()
392 if (ret == -BCH_ERR_option_needs_open_fs) in bch2_opt_parse()
398 opt->attr.name); in bch2_opt_parse()
407 struct bch_fs *c, struct bch_sb *sb, in bch2_opt_to_text() argument
412 if (opt->type == BCH_OPT_BOOL) { in bch2_opt_to_text()
415 opt->attr.name); in bch2_opt_to_text()
419 prt_printf(out, "%s=", opt->attr.name); in bch2_opt_to_text()
422 switch (opt->type) { in bch2_opt_to_text()
425 if (opt->flags & OPT_HUMAN_READABLE) in bch2_opt_to_text()
431 if (v < opt->min || v >= opt->max) in bch2_opt_to_text()
434 prt_string_option(out, opt->choices, v); in bch2_opt_to_text()
436 prt_str(out, opt->choices[v]); in bch2_opt_to_text()
439 prt_bitflags(out, opt->choices, v); in bch2_opt_to_text()
442 opt->fn.to_text(out, c, sb, v); in bch2_opt_to_text()
451 struct bch_fs *c, struct bch_sb *sb, in bch2_opts_to_text() argument
460 if ((opt->flags & hide_mask) || !(opt->flags & show_mask)) in bch2_opts_to_text()
471 bch2_opt_to_text(out, c, sb, opt, v, flags); in bch2_opts_to_text()
475 int bch2_opt_check_may_set(struct bch_fs *c, int id, u64 v) in bch2_opt_check_may_set() argument
482 ret = bch2_check_set_has_compressed_data(c, v); in bch2_opt_check_may_set()
486 bch2_check_set_feature(c, BCH_FEATURE_ec); in bch2_opt_check_may_set()
493 int bch2_opts_check_may_set(struct bch_fs *c) in bch2_opts_check_may_set() argument
499 ret = bch2_opt_check_may_set(c, i, in bch2_opts_check_may_set()
500 bch2_opt_get_by_id(&c->opts, i)); in bch2_opts_check_may_set()
508 int bch2_parse_one_mount_opt(struct bch_fs *c, struct bch_opts *opts, in bch2_parse_one_mount_opt() argument
510 const char *name, const char *val) in bch2_parse_one_mount_opt() argument
516 id = bch2_mount_opt_lookup(name); in bch2_parse_one_mount_opt()
521 !strncmp("no", name, 2)) { in bch2_parse_one_mount_opt()
522 id = bch2_mount_opt_lookup(name + 2); in bch2_parse_one_mount_opt()
542 ret = bch2_opt_parse(c, &bch2_opt_table[id], val, &v, &err); in bch2_parse_one_mount_opt()
543 if (ret == -BCH_ERR_option_needs_open_fs && parse_later) { in bch2_parse_one_mount_opt()
544 prt_printf(parse_later, "%s=%s,", name, val); in bch2_parse_one_mount_opt()
545 if (parse_later->allocation_failure) { in bch2_parse_one_mount_opt()
546 ret = -ENOMEM; in bch2_parse_one_mount_opt()
564 pr_err("Bad mount option %s", name); in bch2_parse_one_mount_opt()
565 ret = -BCH_ERR_option_name; in bch2_parse_one_mount_opt()
570 ret = -BCH_ERR_option_value; in bch2_parse_one_mount_opt()
577 int bch2_parse_mount_opts(struct bch_fs *c, struct bch_opts *opts, in bch2_parse_mount_opts() argument
581 char *opt, *name, *val; in bch2_parse_mount_opts() local
589 * starting with a comma - weird. in bch2_parse_mount_opts()
596 return -ENOMEM; in bch2_parse_mount_opts()
603 name = strsep(&opt, "="); in bch2_parse_mount_opts()
606 ret = bch2_parse_one_mount_opt(c, opts, parse_later, name, val); in bch2_parse_mount_opts()
624 v = opt->get_sb(sb); in bch2_opt_from_sb()
626 if (opt->flags & OPT_SB_FIELD_ILOG2) in bch2_opt_from_sb()
629 if (opt->flags & OPT_SB_FIELD_SECTORS) in bch2_opt_from_sb()
636 * Initial options from superblock - here we don't want any options undefined,
646 if (opt->get_sb == BCH2_NO_SB_OPT) in bch2_opts_from_sb()
660 #define x(n, set) [Opt_##n] = { .set_sb = SET_##set },
668 enum bch_opt_id id = opt - bch2_opt_table; in __bch2_opt_set_sb()
670 if (opt->flags & OPT_SB_FIELD_SECTORS) in __bch2_opt_set_sb()
673 if (opt->flags & OPT_SB_FIELD_ILOG2) in __bch2_opt_set_sb()
676 if (opt->flags & OPT_SB_FIELD_ONE_BIAS) in __bch2_opt_set_sb()
679 if (opt->flags & OPT_FS) { in __bch2_opt_set_sb()
680 if (opt->set_sb != SET_BCH2_NO_SB_OPT) in __bch2_opt_set_sb()
681 opt->set_sb(sb, v); in __bch2_opt_set_sb()
684 if ((opt->flags & OPT_DEVICE) && dev_idx >= 0) { in __bch2_opt_set_sb()
687 opt->attr.name, dev_idx)) in __bch2_opt_set_sb()
693 if (set->set_sb) in __bch2_opt_set_sb()
694 set->set_sb(m, v); in __bch2_opt_set_sb()
696 pr_err("option %s cannot be set via opt_set_sb()", opt->attr.name); in __bch2_opt_set_sb()
700 void bch2_opt_set_sb(struct bch_fs *c, struct bch_dev *ca, in bch2_opt_set_sb() argument
703 mutex_lock(&c->sb_lock); in bch2_opt_set_sb()
704 __bch2_opt_set_sb(c->disk_sb.sb, ca ? ca->dev_idx : -1, opt, v); in bch2_opt_set_sb()
705 bch2_write_super(c); in bch2_opt_set_sb()
706 mutex_unlock(&c->sb_lock); in bch2_opt_set_sb()
714 #define x(_name, _bits) ._name = src._name, in bch2_opts_to_inode_opts()
723 #define x(_name, _bits) Opt_##_name, in bch2_opt_is_inode_opt()