2 #include <linux/kernel.h>
7 const char * const bch_error_actions[] = {
14 const char * const bch_csum_types[] = {
21 const char * const bch_compression_types[] = {
28 const char * const bch_str_hash_types[] = {
35 const char * const bch_cache_replacement_policies[] = {
42 /* Default is -1; we skip past it for struct cached_dev's cache mode */
43 const char * const bch_cache_modes[] = {
52 const char * const bch_cache_state[] = {
61 const char * const bch_bool_opt[] = {
67 const char * const bch_uint_opt[] = {
72 #define BCH_OPT(_name, _choices, _min, _max, _sb_opt, _perm) \
83 const char * const *opts;
84 unsigned long min, max;
87 struct bch_opt_result {
92 static int parse_bool_opt(const struct bch_option *opt, const char *s)
94 if (!strcmp(opt->name, s))
97 if (!strncmp("no", s, 2) && !strcmp(opt->name, s + 2))
103 static int parse_uint_opt(const struct bch_option *opt, const char *s)
108 if (strncmp(opt->name, s, strlen(opt->name)))
111 s += strlen(opt->name);
118 ret = kstrtoul(s, 10, &v);
122 if (v < opt->min || v >= opt->max)
128 static int parse_string_opt(const struct bch_option *opt, const char *s)
130 if (strncmp(opt->name, s, strlen(opt->name)))
133 s += strlen(opt->name);
140 return bch_read_string_list(s, opt->opts);
143 static struct bch_opt_result parse_one_opt(const char *opt)
145 static const struct bch_option opt_table[] = {
146 #define BCH_OPT(_name, _choices, _min, _max, _sb_opt, _perm) \
158 i < opt_table + ARRAY_SIZE(opt_table);
160 int res = i->opts == bch_bool_opt ? parse_bool_opt(i, opt)
161 : i->opts == bch_uint_opt ? parse_uint_opt(i, opt)
162 : parse_string_opt(i, opt);
165 return (struct bch_opt_result) {
170 return (struct bch_opt_result) { Opt_bad_opt };
173 int bch_parse_options(struct cache_set_opts *opts, int flags, char *options)
177 *opts = cache_set_opts_empty();
179 opts->read_only = (flags & MS_RDONLY) != 0;
184 while ((p = strsep(&options, ",")) != NULL) {
185 struct bch_opt_result res = parse_one_opt(p);
188 #define BCH_OPT(_name, _choices, _min, _max, _sb_opt, _perm) \
190 opts->_name = res.val; \