bcachefs: intercept mountoption value for bool type
authorHongbo Li <lihongbo22@huawei.com>
Fri, 1 Mar 2024 06:38:33 +0000 (14:38 +0800)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 14 Mar 2024 01:22:26 +0000 (21:22 -0400)
For mount option with bool type, the value must be 0 or 1 (See
bch2_opt_parse). But this seems does not well intercepted cause
for other value(like 2...), it returns the unexpect return code
with error message printed.

Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/errcode.h
fs/bcachefs/opts.c

index 22c7a3322bcc028bffb55d4873d68dbbd88180cd..af25d8ec60f221d9d935a0ef4ad7aef3641a9e3d 100644 (file)
@@ -8,6 +8,7 @@
        x(EINVAL,                       mount_option)                           \
        x(BCH_ERR_mount_option,         option_name)                            \
        x(BCH_ERR_mount_option,         option_value)                           \
+       x(BCH_ERR_mount_option,         option_not_bool)                        \
        x(ENOMEM,                       ENOMEM_stripe_buf)                      \
        x(ENOMEM,                       ENOMEM_replicas_table)                  \
        x(ENOMEM,                       ENOMEM_cpu_replicas)                    \
index 1db11c15b2b96d3dec19a19c77ee00e2c4863df3..08ea0cfc4aef08acfd4d0fe33e0d8227f212cb02 100644 (file)
@@ -314,7 +314,7 @@ int bch2_opt_parse(struct bch_fs *c,
                if (ret < 0 || (*res != 0 && *res != 1)) {
                        if (err)
                                prt_printf(err, "%s: must be bool", opt->attr.name);
-                       return ret;
+                       return ret < 0 ? ret : -BCH_ERR_option_not_bool;
                }
                break;
        case BCH_OPT_UINT: