Skip to content

Commit 79162e8

Browse files
Hongbo LiKent Overstreet
authored andcommitted
bcachefs: fix the error code when mounting with incorrect options.
When mount with incorrect options such as: "mount -t bcachefs -o errors=back /dev/loop1 /mnt/bcachefs/". It rebacks the error "mount: /mnt/bcachefs: permission denied." cause bch2_parse_mount_opts returns -1 and bch2_mount throws it up. This is unreasonable. The real error message should be like this: "mount: /mnt/bcachefs: wrong fs type, bad option, bad superblock on /dev/loop1, missing codepage or helper program, or other error." Adding three private error codes for mounting error. Here are: - BCH_ERR_mount_option as the parent class for option error. - BCH_ERR_option_name represents the invalid option name. - BCH_ERR_option_value represents the invalid option value. Signed-off-by: Hongbo Li <[email protected]> Signed-off-by: Kent Overstreet <[email protected]>
1 parent 2cce375 commit 79162e8

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

fs/bcachefs/errcode.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#define BCH_ERRCODES() \
66
x(ERANGE, ERANGE_option_too_small) \
77
x(ERANGE, ERANGE_option_too_big) \
8+
x(EINVAL, mount_option) \
9+
x(BCH_ERR_mount_option, option_name) \
10+
x(BCH_ERR_mount_option, option_value) \
811
x(ENOMEM, ENOMEM_stripe_buf) \
912
x(ENOMEM, ENOMEM_replicas_table) \
1013
x(ENOMEM, ENOMEM_cpu_replicas) \

fs/bcachefs/fs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1870,8 +1870,10 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type,
18701870
opt_set(opts, read_only, (flags & SB_RDONLY) != 0);
18711871

18721872
ret = bch2_parse_mount_opts(NULL, &opts, data);
1873-
if (ret)
1873+
if (ret) {
1874+
ret = bch2_err_class(ret);
18741875
return ERR_PTR(ret);
1876+
}
18751877

18761878
if (!dev_name || strlen(dev_name) == 0)
18771879
return ERR_PTR(-EINVAL);

fs/bcachefs/opts.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ int bch2_parse_mount_opts(struct bch_fs *c, struct bch_opts *opts,
456456

457457
copied_opts = kstrdup(options, GFP_KERNEL);
458458
if (!copied_opts)
459-
return -1;
459+
return -ENOMEM;
460460
copied_opts_start = copied_opts;
461461

462462
while ((opt = strsep(&copied_opts, ",")) != NULL) {
@@ -501,11 +501,11 @@ int bch2_parse_mount_opts(struct bch_fs *c, struct bch_opts *opts,
501501

502502
bad_opt:
503503
pr_err("Bad mount option %s", name);
504-
ret = -1;
504+
ret = -BCH_ERR_option_name;
505505
goto out;
506506
bad_val:
507507
pr_err("Invalid mount option %s", err.buf);
508-
ret = -1;
508+
ret = -BCH_ERR_option_value;
509509
goto out;
510510
out:
511511
kfree(copied_opts_start);

0 commit comments

Comments
 (0)