Lines Matching +full:attr +full:- +full:max +full:- +full:name
1 // SPDX-License-Identifier: GPL-2.0
12 #include "super-io.h"
108 #define PRT_STR_OPT_BOUNDSCHECKED(name, type) \ argument
109 void bch2_prt_##name(struct printbuf *out, type t) \
111 prt_str_opt_boundscheck(out, __bch2_##name##s, ARRAY_SIZE(__bch2_##name##s) - 1, #name, t);\
128 int ret = match_string(bch2_fsck_fix_opts, -1, val); in bch2_opt_fix_errors_parse()
194 return opts->_name; in bch2_opt_get_by_id()
232 #define OPT_BOOL() .type = BCH_OPT_BOOL, .min = 0, .max = 2
234 .min = _min, .max = _max
236 .min = 0, .max = ARRAY_SIZE(_choices) - 1, \
239 .min = 0, .max = U64_MAX, \
247 .attr.name = #_name, \
248 .attr.mode = (_flags) & OPT_RUNTIME ? 0644 : 0444, \
263 int bch2_opt_lookup(const char *name) in bch2_opt_lookup() argument
270 if (!strcmp(name, i->attr.name)) in bch2_opt_lookup()
271 return i - bch2_opt_table; in bch2_opt_lookup()
273 return -1; in bch2_opt_lookup()
284 static int bch2_mount_opt_lookup(const char *name) in bch2_mount_opt_lookup() argument
291 if (!strcmp(name, i->s1)) in bch2_mount_opt_lookup()
292 name = i->s2; in bch2_mount_opt_lookup()
294 return bch2_opt_lookup(name); in bch2_mount_opt_lookup()
299 if (v < opt->min) { in bch2_opt_validate()
302 opt->attr.name, opt->min); in bch2_opt_validate()
303 return -BCH_ERR_ERANGE_option_too_small; in bch2_opt_validate()
306 if (opt->max && v >= opt->max) { in bch2_opt_validate()
308 prt_printf(err, "%s: too big (max %llu)", in bch2_opt_validate()
309 opt->attr.name, opt->max); in bch2_opt_validate()
310 return -BCH_ERR_ERANGE_option_too_big; in bch2_opt_validate()
313 if ((opt->flags & OPT_SB_FIELD_SECTORS) && (v & 511)) { 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->flags & OPT_MUST_BE_POW_2) && !is_power_of_2(v)) { in bch2_opt_validate()
323 opt->attr.name); in bch2_opt_validate()
324 return -BCH_ERR_opt_parse_error; in bch2_opt_validate()
327 if (opt->fn.validate) in bch2_opt_validate()
328 return opt->fn.validate(v, err); in bch2_opt_validate()
340 switch (opt->type) { in bch2_opt_parse()
343 ret = lookup_constant(bool_names, val, -BCH_ERR_option_not_bool); in bch2_opt_parse()
344 if (ret != -BCH_ERR_option_not_bool) { in bch2_opt_parse()
348 prt_printf(err, "%s: must be bool", opt->attr.name); in bch2_opt_parse()
359 opt->attr.name); in bch2_opt_parse()
360 return -EINVAL; in bch2_opt_parse()
363 ret = opt->flags & OPT_HUMAN_READABLE in bch2_opt_parse()
369 opt->attr.name); in bch2_opt_parse()
376 opt->attr.name); in bch2_opt_parse()
377 return -EINVAL; in bch2_opt_parse()
380 ret = match_string(opt->choices, -1, val); in bch2_opt_parse()
384 opt->attr.name); in bch2_opt_parse()
391 s64 v = bch2_read_flag_list(val, opt->choices); in bch2_opt_parse()
398 ret = opt->fn.parse(c, val, res, err); in bch2_opt_parse()
400 if (ret == -BCH_ERR_option_needs_open_fs) in bch2_opt_parse()
406 opt->attr.name); in bch2_opt_parse()
420 if (opt->type == BCH_OPT_BOOL) { in bch2_opt_to_text()
423 opt->attr.name); in bch2_opt_to_text()
427 prt_printf(out, "%s=", opt->attr.name); in bch2_opt_to_text()
430 switch (opt->type) { in bch2_opt_to_text()
433 if (opt->flags & OPT_HUMAN_READABLE) in bch2_opt_to_text()
439 if (v < opt->min || v >= opt->max) in bch2_opt_to_text()
442 prt_string_option(out, opt->choices, v); in bch2_opt_to_text()
444 prt_str(out, opt->choices[v]); in bch2_opt_to_text()
447 prt_bitflags(out, opt->choices, v); in bch2_opt_to_text()
450 opt->fn.to_text(out, c, sb, v); in bch2_opt_to_text()
468 if ((opt->flags & hide_mask) || !(opt->flags & show_mask)) in bch2_opts_to_text()
509 int ret = bch2_opt_check_may_set(c, NULL, i, bch2_opt_get_by_id(&c->opts, i)); in bch2_opts_check_may_set()
519 const char *name, const char *val) in bch2_parse_one_mount_opt() argument
525 id = bch2_mount_opt_lookup(name); in bch2_parse_one_mount_opt()
530 !strncmp("no", name, 2)) { in bch2_parse_one_mount_opt()
531 id = bch2_mount_opt_lookup(name + 2); in bch2_parse_one_mount_opt()
552 if (ret == -BCH_ERR_option_needs_open_fs) { in bch2_parse_one_mount_opt()
556 prt_printf(parse_later, "%s=%s,", name, val); in bch2_parse_one_mount_opt()
557 if (parse_later->allocation_failure) in bch2_parse_one_mount_opt()
558 ret = -ENOMEM; in bch2_parse_one_mount_opt()
575 ret = -BCH_ERR_option_name; in bch2_parse_one_mount_opt()
578 ret = -BCH_ERR_option_value; in bch2_parse_one_mount_opt()
587 char *opt, *name, *val; in bch2_parse_mount_opts() local
595 * starting with a comma - weird. in bch2_parse_mount_opts()
602 return -ENOMEM; in bch2_parse_mount_opts()
609 name = strsep(&opt, "="); in bch2_parse_mount_opts()
612 ret = bch2_parse_one_mount_opt(c, opts, parse_later, name, val); in bch2_parse_mount_opts()
613 if (ret == -BCH_ERR_option_name && ignore_unknown) in bch2_parse_mount_opts()
616 pr_err("Error parsing option %s: %s", name, bch2_err_str(ret)); in bch2_parse_mount_opts()
631 v = opt->get_sb(sb); in bch2_opt_from_sb()
635 opt->attr.name, dev_idx)) in bch2_opt_from_sb()
639 v = opt->get_member(&m); in bch2_opt_from_sb()
642 if (opt->flags & OPT_SB_FIELD_ONE_BIAS) in bch2_opt_from_sb()
643 --v; in bch2_opt_from_sb()
645 if (opt->flags & OPT_SB_FIELD_ILOG2) in bch2_opt_from_sb()
648 if (opt->flags & OPT_SB_FIELD_SECTORS) in bch2_opt_from_sb()
655 * Initial options from superblock - here we don't want any options undefined,
663 if (opt->get_sb) in bch2_opts_from_sb()
664 bch2_opt_set_by_id(opts, id, bch2_opt_from_sb(sb, id, -1)); in bch2_opts_from_sb()
673 if (opt->flags & OPT_SB_FIELD_SECTORS) in __bch2_opt_set_sb()
676 if (opt->flags & OPT_SB_FIELD_ILOG2) in __bch2_opt_set_sb()
679 if (opt->flags & OPT_SB_FIELD_ONE_BIAS) in __bch2_opt_set_sb()
682 if ((opt->flags & OPT_FS) && opt->set_sb && dev_idx < 0) in __bch2_opt_set_sb()
683 opt->set_sb(sb, v); in __bch2_opt_set_sb()
685 if ((opt->flags & OPT_DEVICE) && opt->set_member && dev_idx >= 0) { in __bch2_opt_set_sb()
688 opt->attr.name, dev_idx)) in __bch2_opt_set_sb()
691 opt->set_member(bch2_members_v2_get_mut(sb, dev_idx), v); in __bch2_opt_set_sb()
698 mutex_lock(&c->sb_lock); in bch2_opt_set_sb()
699 __bch2_opt_set_sb(c->disk_sb.sb, ca ? ca->dev_idx : -1, opt, v); in bch2_opt_set_sb()
701 mutex_unlock(&c->sb_lock); in bch2_opt_set_sb()