Commit 1c12d1ca authored by Thomas Bertschinger's avatar Thomas Bertschinger Committed by Kent Overstreet

bcachefs: Add error code to defer option parsing

This introduces a new error code, option_needs_open_fs, which is used to
indicate that an attempt was made to parse a mount option prior to
opening a filesystem, when that mount option requires an open filesystem
in order to be validated.

Returning this error results in bch2_parse_one_mount_opt() saving that
option for later parsing, after the filesystem is opened.
Signed-off-by: default avatarThomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 9b7f0b5d
...@@ -511,7 +511,7 @@ int bch2_opt_target_parse(struct bch_fs *c, const char *val, u64 *res, ...@@ -511,7 +511,7 @@ int bch2_opt_target_parse(struct bch_fs *c, const char *val, u64 *res,
return -EINVAL; return -EINVAL;
if (!c) if (!c)
return 0; return -BCH_ERR_option_needs_open_fs;
if (!strlen(val) || !strcmp(val, "none")) { if (!strlen(val) || !strcmp(val, "none")) {
*res = 0; *res = 0;
......
...@@ -257,7 +257,8 @@ ...@@ -257,7 +257,8 @@
x(BCH_ERR_nopromote, nopromote_no_writes) \ x(BCH_ERR_nopromote, nopromote_no_writes) \
x(BCH_ERR_nopromote, nopromote_enomem) \ x(BCH_ERR_nopromote, nopromote_enomem) \
x(0, need_inode_lock) \ x(0, need_inode_lock) \
x(0, invalid_snapshot_node) x(0, invalid_snapshot_node) \
x(0, option_needs_open_fs)
enum bch_errcode { enum bch_errcode {
BCH_ERR_START = 2048, BCH_ERR_START = 2048,
......
...@@ -378,6 +378,10 @@ int bch2_opt_parse(struct bch_fs *c, ...@@ -378,6 +378,10 @@ int bch2_opt_parse(struct bch_fs *c,
break; break;
case BCH_OPT_FN: case BCH_OPT_FN:
ret = opt->fn.parse(c, val, res, err); ret = opt->fn.parse(c, val, res, err);
if (ret == -BCH_ERR_option_needs_open_fs)
return ret;
if (ret < 0) { if (ret < 0) {
if (err) if (err)
prt_printf(err, "%s: parse error", prt_printf(err, "%s: parse error",
...@@ -495,6 +499,17 @@ int bch2_parse_one_mount_opt(struct bch_fs *c, struct bch_opts *opts, ...@@ -495,6 +499,17 @@ int bch2_parse_one_mount_opt(struct bch_fs *c, struct bch_opts *opts,
goto bad_opt; goto bad_opt;
ret = bch2_opt_parse(c, &bch2_opt_table[id], val, &v, &err); ret = bch2_opt_parse(c, &bch2_opt_table[id], val, &v, &err);
if (ret == -BCH_ERR_option_needs_open_fs && parse_later) {
prt_printf(parse_later, "%s=%s,", name, val);
if (parse_later->allocation_failure) {
ret = -ENOMEM;
goto out;
}
ret = 0;
goto out;
}
if (ret < 0) if (ret < 0)
goto bad_val; goto bad_val;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment