Commit a10e677a authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Fix for passing target= opts as mount opts

Some options can't be parsed until the filesystem initialized;
previously, passing these options to mount or remount would cause mount
to fail.

This changes the mount path so that we parse the options passed in
twice, and just ignore any options that can't be parsed the first time.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 5b088c1d
...@@ -1343,7 +1343,7 @@ static int bch2_remount(struct super_block *sb, int *flags, char *data) ...@@ -1343,7 +1343,7 @@ static int bch2_remount(struct super_block *sb, int *flags, char *data)
opt_set(opts, read_only, (*flags & SB_RDONLY) != 0); opt_set(opts, read_only, (*flags & SB_RDONLY) != 0);
ret = bch2_parse_mount_opts(&opts, data); ret = bch2_parse_mount_opts(c, &opts, data);
if (ret) if (ret)
return ret; return ret;
...@@ -1484,7 +1484,7 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type, ...@@ -1484,7 +1484,7 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type,
opt_set(opts, read_only, (flags & SB_RDONLY) != 0); opt_set(opts, read_only, (flags & SB_RDONLY) != 0);
ret = bch2_parse_mount_opts(&opts, data); ret = bch2_parse_mount_opts(NULL, &opts, data);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
...@@ -1507,11 +1507,24 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type, ...@@ -1507,11 +1507,24 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type,
goto got_sb; goto got_sb;
c = bch2_fs_open(devs, nr_devs, opts); c = bch2_fs_open(devs, nr_devs, opts);
if (IS_ERR(c)) {
if (!IS_ERR(c))
sb = sget(fs_type, NULL, bch2_set_super, flags|SB_NOSEC, c);
else
sb = ERR_CAST(c); sb = ERR_CAST(c);
goto got_sb;
}
/* Some options can't be parsed until after the fs is started: */
ret = bch2_parse_mount_opts(c, &opts, data);
if (ret) {
bch2_fs_stop(c);
sb = ERR_PTR(ret);
goto got_sb;
}
bch2_opts_apply(&c->opts, opts);
sb = sget(fs_type, NULL, bch2_set_super, flags|SB_NOSEC, c);
if (IS_ERR(sb))
bch2_fs_stop(c);
got_sb: got_sb:
kfree(devs_to_fs); kfree(devs_to_fs);
kfree(devs[0]); kfree(devs[0]);
......
...@@ -247,7 +247,7 @@ int bch2_opt_parse(struct bch_fs *c, const struct bch_option *opt, ...@@ -247,7 +247,7 @@ int bch2_opt_parse(struct bch_fs *c, const struct bch_option *opt,
break; break;
case BCH_OPT_FN: case BCH_OPT_FN:
if (!c) if (!c)
return -EINVAL; return 0;
return opt->parse(c, val, res); return opt->parse(c, val, res);
} }
...@@ -325,7 +325,8 @@ int bch2_opts_check_may_set(struct bch_fs *c) ...@@ -325,7 +325,8 @@ int bch2_opts_check_may_set(struct bch_fs *c)
return 0; return 0;
} }
int bch2_parse_mount_opts(struct bch_opts *opts, char *options) int bch2_parse_mount_opts(struct bch_fs *c, struct bch_opts *opts,
char *options)
{ {
char *opt, *name, *val; char *opt, *name, *val;
int ret, id; int ret, id;
...@@ -340,7 +341,7 @@ int bch2_parse_mount_opts(struct bch_opts *opts, char *options) ...@@ -340,7 +341,7 @@ int bch2_parse_mount_opts(struct bch_opts *opts, char *options)
if (id < 0) if (id < 0)
goto bad_opt; goto bad_opt;
ret = bch2_opt_parse(NULL, &bch2_opt_table[id], val, &v); ret = bch2_opt_parse(c, &bch2_opt_table[id], val, &v);
if (ret < 0) if (ret < 0)
goto bad_val; goto bad_val;
} else { } else {
......
...@@ -424,7 +424,7 @@ void bch2_opt_to_text(struct printbuf *, struct bch_fs *, ...@@ -424,7 +424,7 @@ void bch2_opt_to_text(struct printbuf *, struct bch_fs *,
int bch2_opt_check_may_set(struct bch_fs *, int, u64); int bch2_opt_check_may_set(struct bch_fs *, int, u64);
int bch2_opts_check_may_set(struct bch_fs *); int bch2_opts_check_may_set(struct bch_fs *);
int bch2_parse_mount_opts(struct bch_opts *, char *); int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *);
/* inode opts: */ /* inode opts: */
......
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