Minor refactoring to get rid of some unneeded token pasting.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
return ret;
}
-int bch2_opt_target_parse(struct bch_fs *c, const char *buf, u64 *v)
+int bch2_opt_target_parse(struct bch_fs *c, const char *val, u64 *res,
+ struct printbuf *err)
{
struct bch_dev *ca;
int g;
- if (!strlen(buf) || !strcmp(buf, "none")) {
- *v = 0;
+ if (!val)
+ return -EINVAL;
+
+ if (!c)
+ return 0;
+
+ if (!strlen(val) || !strcmp(val, "none")) {
+ *res = 0;
return 0;
}
/* Is it a device? */
- ca = bch2_dev_lookup(c, buf);
+ ca = bch2_dev_lookup(c, val);
if (!IS_ERR(ca)) {
- *v = dev_to_target(ca->dev_idx);
+ *res = dev_to_target(ca->dev_idx);
percpu_ref_put(&ca->ref);
return 0;
}
mutex_lock(&c->sb_lock);
- g = bch2_disk_path_find(&c->disk_sb, buf);
+ g = bch2_disk_path_find(&c->disk_sb, val);
mutex_unlock(&c->sb_lock);
if (g >= 0) {
- *v = group_to_target(g);
+ *res = group_to_target(g);
return 0;
}
void bch2_disk_path_to_text(struct printbuf *, struct bch_sb *, unsigned);
-int bch2_opt_target_parse(struct bch_fs *, const char *, u64 *);
+int bch2_opt_target_parse(struct bch_fs *, const char *, u64 *, struct printbuf *);
void bch2_opt_target_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
+#define bch2_opt_target (struct bch_opt_fn) { \
+ .parse = bch2_opt_target_parse, \
+ .to_text = bch2_opt_target_to_text, \
+}
+
int bch2_sb_disk_groups_to_cpu(struct bch_fs *);
int __bch2_dev_group_set(struct bch_fs *, struct bch_dev *, const char *);
#define OPT_UINT(_min, _max) .type = BCH_OPT_UINT, \
.min = _min, .max = _max
#define OPT_STR(_choices) .type = BCH_OPT_STR, \
- .min = 0, .max = ARRAY_SIZE(_choices),\
+ .min = 0, .max = ARRAY_SIZE(_choices), \
.choices = _choices
-#define OPT_FN(_fn) .type = BCH_OPT_FN, \
- .parse = _fn##_parse, \
- .to_text = _fn##_to_text
+#define OPT_FN(_fn) .type = BCH_OPT_FN, .fn = _fn
#define x(_name, _bits, _flags, _type, _sb_opt, _default, _hint, _help) \
[Opt_##_name] = { \
*res = ret;
break;
case BCH_OPT_FN:
- if (!c)
- return 0;
-
- ret = opt->parse(c, val, res);
+ ret = opt->fn.parse(c, val, res, err);
if (ret < 0) {
if (err)
prt_printf(err, "%s: parse error",
prt_printf(out, "%s", opt->choices[v]);
break;
case BCH_OPT_FN:
- opt->to_text(out, c, sb, v);
+ opt->fn.to_text(out, c, sb, v);
break;
default:
BUG();
#include <linux/sysfs.h>
#include "bcachefs_format.h"
+struct bch_fs;
+
extern const char * const bch2_error_actions[];
extern const char * const bch2_version_upgrade_opts[];
extern const char * const bch2_sb_features[];
BCH_OPT_FN,
};
+struct bch_opt_fn {
+ int (*parse)(struct bch_fs *, const char *, u64 *, struct printbuf *);
+ void (*to_text)(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
+};
+
/**
* x(name, shortopt, type, in mem type, mode, sb_opt)
*
u64 min, max;
const char * const *choices;
- int (*parse)(struct bch_fs *, const char *, u64 *);
- void (*to_text)(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
+
+ struct bch_opt_fn fn;
const char *hint;
const char *help;