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_dev_state[] = {
60 const struct bch_option bch_opt_table[] = {
61 #define OPT_BOOL() .type = BCH_OPT_BOOL
62 #define OPT_UINT(_min, _max) .type = BCH_OPT_UINT, .min = _min, .max = _max
63 #define OPT_STR(_choices) .type = BCH_OPT_STR, .choices = _choices
65 #define BCH_OPT(_name, _mode, _sb_opt, _bits, _type) \
68 .set_sb = SET_##_sb_opt, \
75 static enum bch_opt_id bch_opt_lookup(const char *name)
77 const struct bch_option *i;
79 for (i = bch_opt_table;
80 i < bch_opt_table + ARRAY_SIZE(bch_opt_table);
82 if (!strcmp(name, i->name))
83 return i - bch_opt_table;
88 static u64 bch_opt_get(struct bch_opts *opts, enum bch_opt_id id)
91 #define BCH_OPT(_name, ...) \
103 void bch_opt_set(struct bch_opts *opts, enum bch_opt_id id, u64 v)
106 #define BCH_OPT(_name, ...) \
120 * Initial options from superblock - here we don't want any options undefined,
121 * any options the superblock doesn't specify are set to 0:
123 struct bch_opts bch_sb_opts(struct bch_sb *sb)
125 struct bch_opts opts = bch_opts_empty();
127 #define BCH_OPT(_name, _mode, _sb_opt, ...) \
128 if (_sb_opt != NO_SB_OPT) \
129 opts._name = _sb_opt(sb);
137 int parse_one_opt(enum bch_opt_id id, const char *val, u64 *res)
139 const struct bch_option *opt = &bch_opt_table[id];
144 ret = kstrtou64(val, 10, res);
152 ret = kstrtou64(val, 10, res);
156 if (*res < opt->min || *res >= opt->max)
160 ret = bch_read_string_list(val, opt->choices);
171 int bch_parse_mount_opts(struct bch_opts *opts, char *options)
173 char *opt, *name, *val;
178 while ((opt = strsep(&options, ",")) != NULL) {
179 name = strsep(&opt, "=");
183 id = bch_opt_lookup(name);
187 ret = parse_one_opt(id, val, &v);
191 id = bch_opt_lookup(name);
195 !strncmp("no", name, 2)) {
196 id = bch_opt_lookup(name + 2);
200 if (bch_opt_table[id].type != BCH_OPT_BOOL)
204 bch_opt_set(opts, id, v);
210 enum bch_opt_id bch_parse_sysfs_opt(const char *name, const char *val,
213 enum bch_opt_id id = bch_opt_lookup(name);
219 ret = parse_one_opt(id, val, res);
226 ssize_t bch_opt_show(struct bch_opts *opts, const char *name,
227 char *buf, size_t size)
229 enum bch_opt_id id = bch_opt_lookup(name);
230 const struct bch_option *opt;
236 v = bch_opt_get(opts, id);
237 opt = &bch_opt_table[id];
239 return opt->type == BCH_OPT_STR
240 ? bch_snprint_string_list(buf, size, opt->choices, v)
241 : snprintf(buf, size, "%lli\n", v);