bcachefs: Fix BCH_IOCTL_DISK_SET_STATE
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 25 Nov 2022 23:29:36 +0000 (18:29 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:47 +0000 (17:09 -0400)
 - Ensure we print an error message if necessary.

   Ideally we'd return the precise error code to userspace and leave
   printing the error message to the userspace tool, but we haven't
   decided to make our private error codes ABI-stable yet.

 - Return standard error code to userspace

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/chardev.c

index 7b448b9551b6611117367cc0dbe56b66f60733b5..28854a6c31b963ecf23d7263e3a814793e29816b 100644 (file)
@@ -284,6 +284,8 @@ static long bch2_ioctl_disk_set_state(struct bch_fs *c,
                return PTR_ERR(ca);
 
        ret = bch2_dev_set_state(c, ca, arg.new_state, arg.flags);
+       if (ret)
+               bch_err(c, "Error setting device state: %s", bch2_err_str(ret));
 
        percpu_ref_put(&ca->ref);
        return ret;
@@ -631,11 +633,14 @@ do {                                                                      \
                                                                        \
        if (copy_from_user(&i, arg, sizeof(i)))                         \
                return -EFAULT;                                         \
-       return bch2_ioctl_##_name(c, i);                                \
+       ret = bch2_ioctl_##_name(c, i);                                 \
+       goto out;                                                       \
 } while (0)
 
 long bch2_fs_ioctl(struct bch_fs *c, unsigned cmd, void __user *arg)
 {
+       long ret;
+
        switch (cmd) {
        case BCH_IOCTL_QUERY_UUID:
                return bch2_ioctl_query_uuid(c, arg);
@@ -679,6 +684,10 @@ long bch2_fs_ioctl(struct bch_fs *c, unsigned cmd, void __user *arg)
        default:
                return -ENOTTY;
        }
+out:
+       if (ret < 0)
+               ret = bch2_err_class(ret);
+       return ret;
 }
 
 static DEFINE_IDR(bch_chardev_minor);