Skip to content

Commit a7cdf22

Browse files
author
Kent Overstreet
committed
bcachefs: Add an "ignore unknown" option to bch2_parse_mount_opts()
To be used by the mount helper in userspace, where we still have options to be parsed by other layers. Signed-off-by: Kent Overstreet <[email protected]>
1 parent daa7713 commit a7cdf22

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

fs/bcachefs/fs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2179,7 +2179,7 @@ static int bch2_fs_get_tree(struct fs_context *fc)
21792179

21802180
/* Some options can't be parsed until after the fs is started: */
21812181
opts = bch2_opts_empty();
2182-
ret = bch2_parse_mount_opts(c, &opts, NULL, opts_parse->parse_later.buf);
2182+
ret = bch2_parse_mount_opts(c, &opts, NULL, opts_parse->parse_later.buf, false);
21832183
if (ret)
21842184
goto err_stop_fs;
21852185

@@ -2334,6 +2334,8 @@ static int bch2_fs_parse_param(struct fs_context *fc,
23342334
int ret = bch2_parse_one_mount_opt(c, &opts->opts,
23352335
&opts->parse_later, param->key,
23362336
param->string);
2337+
if (ret)
2338+
pr_err("Error parsing option %s: %s", param->key, bch2_err_str(ret));
23372339

23382340
return bch2_err_class(ret);
23392341
}

fs/bcachefs/fsck.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3021,7 +3021,7 @@ long bch2_ioctl_fsck_offline(struct bch_ioctl_fsck_offline __user *user_arg)
30213021
if (arg.opts) {
30223022
char *optstr = strndup_user((char __user *)(unsigned long) arg.opts, 1 << 16);
30233023
ret = PTR_ERR_OR_ZERO(optstr) ?:
3024-
bch2_parse_mount_opts(NULL, &thr->opts, NULL, optstr);
3024+
bch2_parse_mount_opts(NULL, &thr->opts, NULL, optstr, false);
30253025
if (!IS_ERR(optstr))
30263026
kfree(optstr);
30273027

@@ -3129,7 +3129,7 @@ long bch2_ioctl_fsck_online(struct bch_fs *c, struct bch_ioctl_fsck_online arg)
31293129
char *optstr = strndup_user((char __user *)(unsigned long) arg.opts, 1 << 16);
31303130

31313131
ret = PTR_ERR_OR_ZERO(optstr) ?:
3132-
bch2_parse_mount_opts(c, &thr->opts, NULL, optstr);
3132+
bch2_parse_mount_opts(c, &thr->opts, NULL, optstr, false);
31333133
if (!IS_ERR(optstr))
31343134
kfree(optstr);
31353135

fs/bcachefs/opts.c

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -549,14 +549,15 @@ int bch2_parse_one_mount_opt(struct bch_fs *c, struct bch_opts *opts,
549549
goto bad_opt;
550550

551551
ret = bch2_opt_parse(c, &bch2_opt_table[id], val, &v, &err);
552-
if (ret == -BCH_ERR_option_needs_open_fs && parse_later) {
553-
prt_printf(parse_later, "%s=%s,", name, val);
554-
if (parse_later->allocation_failure) {
555-
ret = -ENOMEM;
556-
goto out;
552+
if (ret == -BCH_ERR_option_needs_open_fs) {
553+
ret = 0;
554+
555+
if (parse_later) {
556+
prt_printf(parse_later, "%s=%s,", name, val);
557+
if (parse_later->allocation_failure)
558+
ret = -ENOMEM;
557559
}
558560

559-
ret = 0;
560561
goto out;
561562
}
562563

@@ -567,28 +568,24 @@ int bch2_parse_one_mount_opt(struct bch_fs *c, struct bch_opts *opts,
567568
bch2_opt_set_by_id(opts, id, v);
568569

569570
ret = 0;
570-
goto out;
571-
571+
out:
572+
printbuf_exit(&err);
573+
return ret;
572574
bad_opt:
573-
pr_err("Bad mount option %s", name);
574575
ret = -BCH_ERR_option_name;
575576
goto out;
576-
577577
bad_val:
578-
pr_err("Invalid mount option %s", err.buf);
579578
ret = -BCH_ERR_option_value;
580-
581-
out:
582-
printbuf_exit(&err);
583-
return ret;
579+
goto out;
584580
}
585581

586582
int bch2_parse_mount_opts(struct bch_fs *c, struct bch_opts *opts,
587-
struct printbuf *parse_later, char *options)
583+
struct printbuf *parse_later, char *options,
584+
bool ignore_unknown)
588585
{
589586
char *copied_opts, *copied_opts_start;
590587
char *opt, *name, *val;
591-
int ret;
588+
int ret = 0;
592589

593590
if (!options)
594591
return 0;
@@ -613,14 +610,14 @@ int bch2_parse_mount_opts(struct bch_fs *c, struct bch_opts *opts,
613610
val = opt;
614611

615612
ret = bch2_parse_one_mount_opt(c, opts, parse_later, name, val);
616-
if (ret < 0)
617-
goto out;
613+
if (ret == -BCH_ERR_option_name && ignore_unknown)
614+
ret = 0;
615+
if (ret) {
616+
pr_err("Error parsing option %s: %s", name, bch2_err_str(ret));
617+
break;
618+
}
618619
}
619620

620-
ret = 0;
621-
goto out;
622-
623-
out:
624621
kfree(copied_opts_start);
625622
return ret;
626623
}

fs/bcachefs/opts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ int bch2_opts_check_may_set(struct bch_fs *);
636636
int bch2_parse_one_mount_opt(struct bch_fs *, struct bch_opts *,
637637
struct printbuf *, const char *, const char *);
638638
int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, struct printbuf *,
639-
char *);
639+
char *, bool);
640640

641641
/* inode opts: */
642642

0 commit comments

Comments
 (0)