]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/chardev.c
Move c_src dirs back to toplevel
[bcachefs-tools-debian] / libbcachefs / chardev.c
index 9ac34cc36c07ffeb95e30c3529aa79188c1f0546..226b39c176673a374f50ab06ad5f6d3e0a4858d8 100644 (file)
@@ -7,22 +7,27 @@
 #include "chardev.h"
 #include "journal.h"
 #include "move.h"
+#include "recovery.h"
 #include "replicas.h"
 #include "super.h"
 #include "super-io.h"
+#include "thread_with_file.h"
 
-#include <linux/anon_inodes.h>
 #include <linux/cdev.h>
 #include <linux/device.h>
-#include <linux/file.h>
 #include <linux/fs.h>
 #include <linux/ioctl.h>
-#include <linux/kthread.h>
 #include <linux/major.h>
 #include <linux/sched/task.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
 
+__must_check
+static int copy_to_user_errcode(void __user *to, const void *from, unsigned long n)
+{
+       return copy_to_user(to, from, n) ? -EFAULT : 0;
+}
+
 /* returns with ref on ca->ref */
 static struct bch_dev *bch2_device_lookup(struct bch_fs *c, u64 dev,
                                          unsigned flags)
@@ -86,10 +91,9 @@ static long bch2_ioctl_assemble(struct bch_ioctl_assemble __user *user_arg)
                devs[i] = strndup_user((const char __user *)(unsigned long)
                                       user_devs[i],
                                       PATH_MAX);
-               if (!devs[i]) {
-                       ret = -ENOMEM;
+               ret= PTR_ERR_OR_ZERO(devs[i]);
+               if (ret)
                        goto err;
-               }
        }
 
        c = bch2_fs_open(devs, arg.nr_devs, bch2_opts_empty());
@@ -117,8 +121,9 @@ static long bch2_ioctl_incremental(struct bch_ioctl_incremental __user *user_arg
                return -EINVAL;
 
        path = strndup_user((const char __user *)(unsigned long) arg.dev, PATH_MAX);
-       if (!path)
-               return -ENOMEM;
+       ret = PTR_ERR_OR_ZERO(path);
+       if (ret)
+               return ret;
 
        err = bch2_fs_open_incremental(path);
        kfree(path);
@@ -132,8 +137,106 @@ static long bch2_ioctl_incremental(struct bch_ioctl_incremental __user *user_arg
 }
 #endif
 
+struct fsck_thread {
+       struct thread_with_stdio thr;
+       struct bch_fs           *c;
+       char                    **devs;
+       size_t                  nr_devs;
+       struct bch_opts         opts;
+};
+
+static void bch2_fsck_thread_exit(struct thread_with_stdio *_thr)
+{
+       struct fsck_thread *thr = container_of(_thr, struct fsck_thread, thr);
+       if (thr->devs)
+               for (size_t i = 0; i < thr->nr_devs; i++)
+                       kfree(thr->devs[i]);
+       kfree(thr->devs);
+       kfree(thr);
+}
+
+static int bch2_fsck_offline_thread_fn(void *arg)
+{
+       struct fsck_thread *thr = container_of(arg, struct fsck_thread, thr);
+       struct bch_fs *c = bch2_fs_open(thr->devs, thr->nr_devs, thr->opts);
+
+       thr->thr.thr.ret = PTR_ERR_OR_ZERO(c);
+       if (!thr->thr.thr.ret)
+               bch2_fs_stop(c);
+
+       thread_with_stdio_done(&thr->thr);
+       return 0;
+}
+
+static long bch2_ioctl_fsck_offline(struct bch_ioctl_fsck_offline __user *user_arg)
+{
+       struct bch_ioctl_fsck_offline arg;
+       struct fsck_thread *thr = NULL;
+       u64 *devs = NULL;
+       long ret = 0;
+
+       if (copy_from_user(&arg, user_arg, sizeof(arg)))
+               return -EFAULT;
+
+       if (arg.flags)
+               return -EINVAL;
+
+       if (!capable(CAP_SYS_ADMIN))
+               return -EPERM;
+
+       if (!(devs = kcalloc(arg.nr_devs, sizeof(*devs), GFP_KERNEL)) ||
+           !(thr = kzalloc(sizeof(*thr), GFP_KERNEL)) ||
+           !(thr->devs = kcalloc(arg.nr_devs, sizeof(*thr->devs), GFP_KERNEL))) {
+               ret = -ENOMEM;
+               goto err;
+       }
+
+       thr->opts = bch2_opts_empty();
+       thr->nr_devs = arg.nr_devs;
+
+       if (copy_from_user(devs, &user_arg->devs[0],
+                          array_size(sizeof(user_arg->devs[0]), arg.nr_devs))) {
+               ret = -EINVAL;
+               goto err;
+       }
+
+       for (size_t i = 0; i < arg.nr_devs; i++) {
+               thr->devs[i] = strndup_user((char __user *)(unsigned long) devs[i], PATH_MAX);
+               ret = PTR_ERR_OR_ZERO(thr->devs[i]);
+               if (ret)
+                       goto err;
+       }
+
+       if (arg.opts) {
+               char *optstr = strndup_user((char __user *)(unsigned long) arg.opts, 1 << 16);
+
+               ret =   PTR_ERR_OR_ZERO(optstr) ?:
+                       bch2_parse_mount_opts(NULL, &thr->opts, optstr);
+               kfree(optstr);
+
+               if (ret)
+                       goto err;
+       }
+
+       opt_set(thr->opts, stdio, (u64)(unsigned long)&thr->thr.stdio);
+
+       ret = bch2_run_thread_with_stdio(&thr->thr,
+                       bch2_fsck_thread_exit,
+                       bch2_fsck_offline_thread_fn);
+err:
+       if (ret < 0) {
+               if (thr)
+                       bch2_fsck_thread_exit(&thr->thr);
+               pr_err("ret %s", bch2_err_str(ret));
+       }
+       kfree(devs);
+       return ret;
+}
+
 static long bch2_global_ioctl(unsigned cmd, void __user *arg)
 {
+       long ret;
+
        switch (cmd) {
 #if 0
        case BCH_IOCTL_ASSEMBLE:
@@ -141,17 +244,25 @@ static long bch2_global_ioctl(unsigned cmd, void __user *arg)
        case BCH_IOCTL_INCREMENTAL:
                return bch2_ioctl_incremental(arg);
 #endif
+       case BCH_IOCTL_FSCK_OFFLINE: {
+               ret = bch2_ioctl_fsck_offline(arg);
+               break;
+       }
        default:
-               return -ENOTTY;
+               ret = -ENOTTY;
+               break;
        }
+
+       if (ret < 0)
+               ret = bch2_err_class(ret);
+       return ret;
 }
 
 static long bch2_ioctl_query_uuid(struct bch_fs *c,
                        struct bch_ioctl_query_uuid __user *user_arg)
 {
-       return copy_to_user(&user_arg->uuid,
-                           &c->sb.user_uuid,
-                           sizeof(c->sb.user_uuid));
+       return copy_to_user_errcode(&user_arg->uuid, &c->sb.user_uuid,
+                                   sizeof(c->sb.user_uuid));
 }
 
 #if 0
@@ -188,8 +299,9 @@ static long bch2_ioctl_disk_add(struct bch_fs *c, struct bch_ioctl_disk arg)
                return -EINVAL;
 
        path = strndup_user((const char __user *)(unsigned long) arg.dev, PATH_MAX);
-       if (!path)
-               return -ENOMEM;
+       ret = PTR_ERR_OR_ZERO(path);
+       if (ret)
+               return ret;
 
        ret = bch2_dev_add(c, path);
        kfree(path);
@@ -230,8 +342,9 @@ static long bch2_ioctl_disk_online(struct bch_fs *c, struct bch_ioctl_disk arg)
                return -EINVAL;
 
        path = strndup_user((const char __user *)(unsigned long) arg.dev, PATH_MAX);
-       if (!path)
-               return -ENOMEM;
+       ret = PTR_ERR_OR_ZERO(path);
+       if (ret)
+               return ret;
 
        ret = bch2_dev_online(c, path);
        kfree(path);
@@ -275,7 +388,8 @@ static long bch2_ioctl_disk_set_state(struct bch_fs *c,
                           BCH_FORCE_IF_METADATA_LOST|
                           BCH_FORCE_IF_DEGRADED|
                           BCH_BY_INDEX)) ||
-           arg.pad[0] || arg.pad[1] || arg.pad[2])
+           arg.pad[0] || arg.pad[1] || arg.pad[2] ||
+           arg.new_state >= BCH_MEMBER_STATE_NR)
                return -EINVAL;
 
        ca = bch2_device_lookup(c, arg.dev, arg.flags);
@@ -283,37 +397,35 @@ 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;
 }
 
 struct bch_data_ctx {
+       struct thread_with_file         thr;
+
        struct bch_fs                   *c;
        struct bch_ioctl_data           arg;
        struct bch_move_stats           stats;
-
-       int                             ret;
-
-       struct task_struct              *thread;
 };
 
 static int bch2_data_thread(void *arg)
 {
-       struct bch_data_ctx *ctx = arg;
-
-       ctx->ret = bch2_data_job(ctx->c, &ctx->stats, ctx->arg);
+       struct bch_data_ctx *ctx = container_of(arg, struct bch_data_ctx, thr);
 
+       ctx->thr.ret = bch2_data_job(ctx->c, &ctx->stats, ctx->arg);
        ctx->stats.data_type = U8_MAX;
        return 0;
 }
 
 static int bch2_data_job_release(struct inode *inode, struct file *file)
 {
-       struct bch_data_ctx *ctx = file->private_data;
+       struct bch_data_ctx *ctx = container_of(file->private_data, struct bch_data_ctx, thr);
 
-       kthread_stop(ctx->thread);
-       put_task_struct(ctx->thread);
+       bch2_thread_with_file_exit(&ctx->thr);
        kfree(ctx);
        return 0;
 }
@@ -321,13 +433,13 @@ static int bch2_data_job_release(struct inode *inode, struct file *file)
 static ssize_t bch2_data_job_read(struct file *file, char __user *buf,
                                  size_t len, loff_t *ppos)
 {
-       struct bch_data_ctx *ctx = file->private_data;
+       struct bch_data_ctx *ctx = container_of(file->private_data, struct bch_data_ctx, thr);
        struct bch_fs *c = ctx->c;
        struct bch_ioctl_data_event e = {
                .type                   = BCH_DATA_EVENT_PROGRESS,
                .p.data_type            = ctx->stats.data_type,
-               .p.btree_id             = ctx->stats.btree_id,
-               .p.pos                  = ctx->stats.pos,
+               .p.btree_id             = ctx->stats.pos.btree,
+               .p.pos                  = ctx->stats.pos.pos,
                .p.sectors_done         = atomic64_read(&ctx->stats.sectors_seen),
                .p.sectors_total        = bch2_fs_usage_read_short(c).used,
        };
@@ -335,7 +447,7 @@ static ssize_t bch2_data_job_read(struct file *file, char __user *buf,
        if (len < sizeof(e))
                return -EINVAL;
 
-       return copy_to_user(buf, &e, sizeof(e)) ?: sizeof(e);
+       return copy_to_user_errcode(buf, &e, sizeof(e)) ?: sizeof(e);
 }
 
 static const struct file_operations bcachefs_data_ops = {
@@ -347,10 +459,8 @@ static const struct file_operations bcachefs_data_ops = {
 static long bch2_ioctl_data(struct bch_fs *c,
                            struct bch_ioctl_data arg)
 {
-       struct bch_data_ctx *ctx = NULL;
-       struct file *file = NULL;
-       unsigned flags = O_RDONLY|O_CLOEXEC|O_NONBLOCK;
-       int ret, fd = -1;
+       struct bch_data_ctx *ctx;
+       int ret;
 
        if (!capable(CAP_SYS_ADMIN))
                return -EPERM;
@@ -365,36 +475,11 @@ static long bch2_ioctl_data(struct bch_fs *c,
        ctx->c = c;
        ctx->arg = arg;
 
-       ctx->thread = kthread_create(bch2_data_thread, ctx,
-                                    "bch-data/%s", c->name);
-       if (IS_ERR(ctx->thread)) {
-               ret = PTR_ERR(ctx->thread);
-               goto err;
-       }
-
-       ret = get_unused_fd_flags(flags);
+       ret = bch2_run_thread_with_file(&ctx->thr,
+                       &bcachefs_data_ops,
+                       bch2_data_thread);
        if (ret < 0)
-               goto err;
-       fd = ret;
-
-       file = anon_inode_getfile("[bcachefs]", &bcachefs_data_ops, ctx, flags);
-       if (IS_ERR(file)) {
-               ret = PTR_ERR(file);
-               goto err;
-       }
-
-       fd_install(fd, file);
-
-       get_task_struct(ctx->thread);
-       wake_up_process(ctx->thread);
-
-       return fd;
-err:
-       if (fd >= 0)
-               put_unused_fd(fd);
-       if (!IS_ERR_OR_NULL(ctx->thread))
-               kthread_stop(ctx->thread);
-       kfree(ctx);
+               kfree(ctx);
        return ret;
 }
 
@@ -408,13 +493,13 @@ static long bch2_ioctl_fs_usage(struct bch_fs *c,
        unsigned i;
        int ret = 0;
 
-       if (!test_bit(BCH_FS_STARTED, &c->flags))
+       if (!test_bit(BCH_FS_started, &c->flags))
                return -EINVAL;
 
        if (get_user(replica_entries_bytes, &user_arg->replica_entries_bytes))
                return -EFAULT;
 
-       arg = kzalloc(sizeof(*arg) + replica_entries_bytes, GFP_KERNEL);
+       arg = kzalloc(size_add(sizeof(*arg), replica_entries_bytes), GFP_KERNEL);
        if (!arg)
                return -ENOMEM;
 
@@ -435,7 +520,7 @@ static long bch2_ioctl_fs_usage(struct bch_fs *c,
        dst_end = (void *) arg->replicas + replica_entries_bytes;
 
        for (i = 0; i < c->replicas.nr; i++) {
-               struct bch_replicas_entry *src_e =
+               struct bch_replicas_entry_v1 *src_e =
                        cpu_replicas_entry(&c->replicas, i);
 
                /* check that we have enough space for one replicas entry */
@@ -463,14 +548,17 @@ static long bch2_ioctl_fs_usage(struct bch_fs *c,
        percpu_up_read(&c->mark_lock);
        kfree(src);
 
-       if (!ret)
-               ret = copy_to_user(user_arg, arg,
+       if (ret)
+               goto err;
+
+       ret = copy_to_user_errcode(user_arg, arg,
                        sizeof(*arg) + arg->replica_entries_bytes);
 err:
        kfree(arg);
        return ret;
 }
 
+/* obsolete, didn't allow for new data types: */
 static long bch2_ioctl_dev_usage(struct bch_fs *c,
                                 struct bch_ioctl_dev_usage __user *user_arg)
 {
@@ -479,7 +567,7 @@ static long bch2_ioctl_dev_usage(struct bch_fs *c,
        struct bch_dev *ca;
        unsigned i;
 
-       if (!test_bit(BCH_FS_STARTED, &c->flags))
+       if (!test_bit(BCH_FS_started, &c->flags))
                return -EINVAL;
 
        if (copy_from_user(&arg, user_arg, sizeof(arg)))
@@ -500,18 +588,67 @@ static long bch2_ioctl_dev_usage(struct bch_fs *c,
        arg.state               = ca->mi.state;
        arg.bucket_size         = ca->mi.bucket_size;
        arg.nr_buckets          = ca->mi.nbuckets - ca->mi.first_bucket;
-       arg.available_buckets   = arg.nr_buckets - src.buckets_unavailable;
-       arg.ec_buckets          = src.buckets_ec;
-       arg.ec_sectors          = 0;
 
        for (i = 0; i < BCH_DATA_NR; i++) {
-               arg.buckets[i] = src.d[i].buckets;
-               arg.sectors[i] = src.d[i].sectors;
+               arg.d[i].buckets        = src.d[i].buckets;
+               arg.d[i].sectors        = src.d[i].sectors;
+               arg.d[i].fragmented     = src.d[i].fragmented;
        }
 
        percpu_ref_put(&ca->ref);
 
-       return copy_to_user(user_arg, &arg, sizeof(arg));
+       return copy_to_user_errcode(user_arg, &arg, sizeof(arg));
+}
+
+static long bch2_ioctl_dev_usage_v2(struct bch_fs *c,
+                                struct bch_ioctl_dev_usage_v2 __user *user_arg)
+{
+       struct bch_ioctl_dev_usage_v2 arg;
+       struct bch_dev_usage src;
+       struct bch_dev *ca;
+       int ret = 0;
+
+       if (!test_bit(BCH_FS_started, &c->flags))
+               return -EINVAL;
+
+       if (copy_from_user(&arg, user_arg, sizeof(arg)))
+               return -EFAULT;
+
+       if ((arg.flags & ~BCH_BY_INDEX) ||
+           arg.pad[0] ||
+           arg.pad[1] ||
+           arg.pad[2])
+               return -EINVAL;
+
+       ca = bch2_device_lookup(c, arg.dev, arg.flags);
+       if (IS_ERR(ca))
+               return PTR_ERR(ca);
+
+       src = bch2_dev_usage_read(ca);
+
+       arg.state               = ca->mi.state;
+       arg.bucket_size         = ca->mi.bucket_size;
+       arg.nr_data_types       = min(arg.nr_data_types, BCH_DATA_NR);
+       arg.nr_buckets          = ca->mi.nbuckets - ca->mi.first_bucket;
+
+       ret = copy_to_user_errcode(user_arg, &arg, sizeof(arg));
+       if (ret)
+               goto err;
+
+       for (unsigned i = 0; i < arg.nr_data_types; i++) {
+               struct bch_ioctl_dev_usage_type t = {
+                       .buckets        = src.d[i].buckets,
+                       .sectors        = src.d[i].sectors,
+                       .fragmented     = src.d[i].fragmented,
+               };
+
+               ret = copy_to_user_errcode(&user_arg->d[i], &t, sizeof(t));
+               if (ret)
+                       goto err;
+       }
+err:
+       percpu_ref_put(&ca->ref);
+       return ret;
 }
 
 static long bch2_ioctl_read_super(struct bch_fs *c,
@@ -548,8 +685,8 @@ static long bch2_ioctl_read_super(struct bch_fs *c,
                goto err;
        }
 
-       ret = copy_to_user((void __user *)(unsigned long)arg.sb,
-                          sb, vstruct_bytes(sb));
+       ret = copy_to_user_errcode((void __user *)(unsigned long)arg.sb, sb,
+                                  vstruct_bytes(sb));
 err:
        if (!IS_ERR_OR_NULL(ca))
                percpu_ref_put(&ca->ref);
@@ -561,19 +698,20 @@ static long bch2_ioctl_disk_get_idx(struct bch_fs *c,
                                    struct bch_ioctl_disk_get_idx arg)
 {
        dev_t dev = huge_decode_dev(arg.dev);
-       struct bch_dev *ca;
-       unsigned i;
 
        if (!capable(CAP_SYS_ADMIN))
                return -EPERM;
 
-       for_each_online_member(ca, c, i)
-               if (ca->disk_sb.bdev->bd_dev == dev) {
+       if (!dev)
+               return -EINVAL;
+
+       for_each_online_member(c, ca)
+               if (ca->dev == dev) {
                        percpu_ref_put(&ca->io_ref);
-                       return i;
+                       return ca->dev_idx;
                }
 
-       return -ENOENT;
+       return -BCH_ERR_ENOENT_dev_idx_not_found;
 }
 
 static long bch2_ioctl_disk_resize(struct bch_fs *c,
@@ -612,6 +750,9 @@ static long bch2_ioctl_disk_resize_journal(struct bch_fs *c,
            arg.pad)
                return -EINVAL;
 
+       if (arg.nbuckets > U32_MAX)
+               return -EINVAL;
+
        ca = bch2_device_lookup(c, arg.dev, arg.flags);
        if (IS_ERR(ca))
                return PTR_ERR(ca);
@@ -622,17 +763,111 @@ static long bch2_ioctl_disk_resize_journal(struct bch_fs *c,
        return ret;
 }
 
+static int bch2_fsck_online_thread_fn(void *arg)
+{
+       struct fsck_thread *thr = container_of(arg, struct fsck_thread, thr);
+       struct bch_fs *c = thr->c;
+
+       c->stdio_filter = current;
+       c->stdio = &thr->thr.stdio;
+
+       /*
+        * XXX: can we figure out a way to do this without mucking with c->opts?
+        */
+       unsigned old_fix_errors = c->opts.fix_errors;
+       if (opt_defined(thr->opts, fix_errors))
+               c->opts.fix_errors = thr->opts.fix_errors;
+       else
+               c->opts.fix_errors = FSCK_FIX_ask;
+
+       c->opts.fsck = true;
+       set_bit(BCH_FS_fsck_running, &c->flags);
+
+       c->curr_recovery_pass = BCH_RECOVERY_PASS_check_alloc_info;
+       int ret = bch2_run_online_recovery_passes(c);
+
+       clear_bit(BCH_FS_fsck_running, &c->flags);
+       bch_err_fn(c, ret);
+
+       c->stdio = NULL;
+       c->stdio_filter = NULL;
+       c->opts.fix_errors = old_fix_errors;
+
+       thread_with_stdio_done(&thr->thr);
+
+       up(&c->online_fsck_mutex);
+       bch2_ro_ref_put(c);
+       return 0;
+}
+
+static long bch2_ioctl_fsck_online(struct bch_fs *c,
+                                  struct bch_ioctl_fsck_online arg)
+{
+       struct fsck_thread *thr = NULL;
+       long ret = 0;
+
+       if (arg.flags)
+               return -EINVAL;
+
+       if (!capable(CAP_SYS_ADMIN))
+               return -EPERM;
+
+       if (!bch2_ro_ref_tryget(c))
+               return -EROFS;
+
+       if (down_trylock(&c->online_fsck_mutex)) {
+               bch2_ro_ref_put(c);
+               return -EAGAIN;
+       }
+
+       thr = kzalloc(sizeof(*thr), GFP_KERNEL);
+       if (!thr) {
+               ret = -ENOMEM;
+               goto err;
+       }
+
+       thr->c = c;
+       thr->opts = bch2_opts_empty();
+
+       if (arg.opts) {
+               char *optstr = strndup_user((char __user *)(unsigned long) arg.opts, 1 << 16);
+
+               ret =   PTR_ERR_OR_ZERO(optstr) ?:
+                       bch2_parse_mount_opts(c, &thr->opts, optstr);
+               kfree(optstr);
+
+               if (ret)
+                       goto err;
+       }
+
+       ret = bch2_run_thread_with_stdio(&thr->thr,
+                       bch2_fsck_thread_exit,
+                       bch2_fsck_online_thread_fn);
+err:
+       if (ret < 0) {
+               bch_err_fn(c, ret);
+               if (thr)
+                       bch2_fsck_thread_exit(&thr->thr);
+               up(&c->online_fsck_mutex);
+               bch2_ro_ref_put(c);
+       }
+       return ret;
+}
+
 #define BCH_IOCTL(_name, _argtype)                                     \
 do {                                                                   \
        _argtype i;                                                     \
                                                                        \
        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);
@@ -640,6 +875,8 @@ long bch2_fs_ioctl(struct bch_fs *c, unsigned cmd, void __user *arg)
                return bch2_ioctl_fs_usage(c, arg);
        case BCH_IOCTL_DEV_USAGE:
                return bch2_ioctl_dev_usage(c, arg);
+       case BCH_IOCTL_DEV_USAGE_V2:
+               return bch2_ioctl_dev_usage_v2(c, arg);
 #if 0
        case BCH_IOCTL_START:
                BCH_IOCTL(start, struct bch_ioctl_start);
@@ -652,7 +889,7 @@ long bch2_fs_ioctl(struct bch_fs *c, unsigned cmd, void __user *arg)
                BCH_IOCTL(disk_get_idx, struct bch_ioctl_disk_get_idx);
        }
 
-       if (!test_bit(BCH_FS_STARTED, &c->flags))
+       if (!test_bit(BCH_FS_started, &c->flags))
                return -EINVAL;
 
        switch (cmd) {
@@ -672,10 +909,15 @@ long bch2_fs_ioctl(struct bch_fs *c, unsigned cmd, void __user *arg)
                BCH_IOCTL(disk_resize, struct bch_ioctl_disk_resize);
        case BCH_IOCTL_DISK_RESIZE_JOURNAL:
                BCH_IOCTL(disk_resize_journal, struct bch_ioctl_disk_resize_journal);
-
+       case BCH_IOCTL_FSCK_ONLINE:
+               BCH_IOCTL(fsck_online, struct bch_ioctl_fsck_online);
        default:
                return -ENOTTY;
        }
+out:
+       if (ret < 0)
+               ret = bch2_err_class(ret);
+       return ret;
 }
 
 static DEFINE_IDR(bch_chardev_minor);
@@ -741,7 +983,7 @@ int __init bch2_chardev_init(void)
        if (bch_chardev_major < 0)
                return bch_chardev_major;
 
-       bch_chardev_class = class_create(THIS_MODULE, "bcachefs");
+       bch_chardev_class = class_create("bcachefs");
        if (IS_ERR(bch_chardev_class))
                return PTR_ERR(bch_chardev_class);