1 // SPDX-License-Identifier: GPL-2.0
2 #ifndef NO_BCACHEFS_CHARDEV
5 #include "bcachefs_ioctl.h"
10 #include "recovery_passes.h"
14 #include "thread_with_file.h"
16 #include <linux/cdev.h>
17 #include <linux/device.h>
19 #include <linux/ioctl.h>
20 #include <linux/major.h>
21 #include <linux/sched/task.h>
22 #include <linux/slab.h>
23 #include <linux/uaccess.h>
25 /* returns with ref on ca->ref */
26 static struct bch_dev *bch2_device_lookup(struct bch_fs *c, u64 dev,
31 if (flags & BCH_BY_INDEX) {
32 if (dev >= c->sb.nr_devices)
33 return ERR_PTR(-EINVAL);
36 ca = rcu_dereference(c->devs[dev]);
38 percpu_ref_get(&ca->ref);
42 return ERR_PTR(-EINVAL);
46 path = strndup_user((const char __user *)
47 (unsigned long) dev, PATH_MAX);
49 return ERR_CAST(path);
51 ca = bch2_dev_lookup(c, path);
59 static long bch2_ioctl_assemble(struct bch_ioctl_assemble __user *user_arg)
61 struct bch_ioctl_assemble arg;
63 u64 *user_devs = NULL;
68 if (copy_from_user(&arg, user_arg, sizeof(arg)))
71 if (arg.flags || arg.pad)
74 user_devs = kmalloc_array(arg.nr_devs, sizeof(u64), GFP_KERNEL);
78 devs = kcalloc(arg.nr_devs, sizeof(char *), GFP_KERNEL);
80 if (copy_from_user(user_devs, user_arg->devs,
81 sizeof(u64) * arg.nr_devs))
84 for (i = 0; i < arg.nr_devs; i++) {
85 devs[i] = strndup_user((const char __user *)(unsigned long)
88 ret= PTR_ERR_OR_ZERO(devs[i]);
93 c = bch2_fs_open(devs, arg.nr_devs, bch2_opts_empty());
94 ret = PTR_ERR_OR_ZERO(c);
99 for (i = 0; i < arg.nr_devs; i++)
105 static long bch2_ioctl_incremental(struct bch_ioctl_incremental __user *user_arg)
107 struct bch_ioctl_incremental arg;
111 if (copy_from_user(&arg, user_arg, sizeof(arg)))
114 if (arg.flags || arg.pad)
117 path = strndup_user((const char __user *)(unsigned long) arg.dev, PATH_MAX);
118 ret = PTR_ERR_OR_ZERO(path);
122 err = bch2_fs_open_incremental(path);
126 pr_err("Could not register bcachefs devices: %s", err);
135 struct thread_with_stdio thr;
137 struct bch_opts opts;
140 static void bch2_fsck_thread_exit(struct thread_with_stdio *_thr)
142 struct fsck_thread *thr = container_of(_thr, struct fsck_thread, thr);
146 static int bch2_fsck_offline_thread_fn(struct thread_with_stdio *stdio)
148 struct fsck_thread *thr = container_of(stdio, struct fsck_thread, thr);
149 struct bch_fs *c = thr->c;
151 int ret = PTR_ERR_OR_ZERO(c);
155 ret = bch2_fs_start(thr->c);
159 if (test_bit(BCH_FS_errors_fixed, &c->flags)) {
160 bch2_stdio_redirect_printf(&stdio->stdio, false, "%s: errors fixed\n", c->name);
163 if (test_bit(BCH_FS_error, &c->flags)) {
164 bch2_stdio_redirect_printf(&stdio->stdio, false, "%s: still has errors\n", c->name);
172 static const struct thread_with_stdio_ops bch2_offline_fsck_ops = {
173 .exit = bch2_fsck_thread_exit,
174 .fn = bch2_fsck_offline_thread_fn,
177 static long bch2_ioctl_fsck_offline(struct bch_ioctl_fsck_offline __user *user_arg)
179 struct bch_ioctl_fsck_offline arg;
180 struct fsck_thread *thr = NULL;
181 darray_str(devs) = {};
184 if (copy_from_user(&arg, user_arg, sizeof(arg)))
190 if (!capable(CAP_SYS_ADMIN))
193 for (size_t i = 0; i < arg.nr_devs; i++) {
195 ret = copy_from_user_errcode(&dev_u64, &user_arg->devs[i], sizeof(u64));
199 char *dev_str = strndup_user((char __user *)(unsigned long) dev_u64, PATH_MAX);
200 ret = PTR_ERR_OR_ZERO(dev_str);
204 ret = darray_push(&devs, dev_str);
211 thr = kzalloc(sizeof(*thr), GFP_KERNEL);
217 thr->opts = bch2_opts_empty();
220 char *optstr = strndup_user((char __user *)(unsigned long) arg.opts, 1 << 16);
222 ret = PTR_ERR_OR_ZERO(optstr) ?:
223 bch2_parse_mount_opts(NULL, &thr->opts, optstr);
230 opt_set(thr->opts, stdio, (u64)(unsigned long)&thr->thr.stdio);
232 /* We need request_key() to be called before we punt to kthread: */
233 opt_set(thr->opts, nostart, true);
235 bch2_thread_with_stdio_init(&thr->thr, &bch2_offline_fsck_ops);
237 thr->c = bch2_fs_open(devs.data, arg.nr_devs, thr->opts);
239 if (!IS_ERR(thr->c) &&
240 thr->c->opts.errors == BCH_ON_ERROR_panic)
241 thr->c->opts.errors = BCH_ON_ERROR_ro;
243 ret = __bch2_run_thread_with_stdio(&thr->thr);
245 darray_for_each(devs, i)
251 bch2_fsck_thread_exit(&thr->thr);
252 pr_err("ret %s", bch2_err_str(ret));
256 static long bch2_global_ioctl(unsigned cmd, void __user *arg)
262 case BCH_IOCTL_ASSEMBLE:
263 return bch2_ioctl_assemble(arg);
264 case BCH_IOCTL_INCREMENTAL:
265 return bch2_ioctl_incremental(arg);
267 case BCH_IOCTL_FSCK_OFFLINE: {
268 ret = bch2_ioctl_fsck_offline(arg);
277 ret = bch2_err_class(ret);
281 static long bch2_ioctl_query_uuid(struct bch_fs *c,
282 struct bch_ioctl_query_uuid __user *user_arg)
284 return copy_to_user_errcode(&user_arg->uuid, &c->sb.user_uuid,
285 sizeof(c->sb.user_uuid));
289 static long bch2_ioctl_start(struct bch_fs *c, struct bch_ioctl_start arg)
291 if (!capable(CAP_SYS_ADMIN))
294 if (arg.flags || arg.pad)
297 return bch2_fs_start(c);
300 static long bch2_ioctl_stop(struct bch_fs *c)
302 if (!capable(CAP_SYS_ADMIN))
310 static long bch2_ioctl_disk_add(struct bch_fs *c, struct bch_ioctl_disk arg)
315 if (!capable(CAP_SYS_ADMIN))
318 if (arg.flags || arg.pad)
321 path = strndup_user((const char __user *)(unsigned long) arg.dev, PATH_MAX);
322 ret = PTR_ERR_OR_ZERO(path);
326 ret = bch2_dev_add(c, path);
332 static long bch2_ioctl_disk_remove(struct bch_fs *c, struct bch_ioctl_disk arg)
336 if (!capable(CAP_SYS_ADMIN))
339 if ((arg.flags & ~(BCH_FORCE_IF_DATA_LOST|
340 BCH_FORCE_IF_METADATA_LOST|
341 BCH_FORCE_IF_DEGRADED|
346 ca = bch2_device_lookup(c, arg.dev, arg.flags);
350 return bch2_dev_remove(c, ca, arg.flags);
353 static long bch2_ioctl_disk_online(struct bch_fs *c, struct bch_ioctl_disk arg)
358 if (!capable(CAP_SYS_ADMIN))
361 if (arg.flags || arg.pad)
364 path = strndup_user((const char __user *)(unsigned long) arg.dev, PATH_MAX);
365 ret = PTR_ERR_OR_ZERO(path);
369 ret = bch2_dev_online(c, path);
374 static long bch2_ioctl_disk_offline(struct bch_fs *c, struct bch_ioctl_disk arg)
379 if (!capable(CAP_SYS_ADMIN))
382 if ((arg.flags & ~(BCH_FORCE_IF_DATA_LOST|
383 BCH_FORCE_IF_METADATA_LOST|
384 BCH_FORCE_IF_DEGRADED|
389 ca = bch2_device_lookup(c, arg.dev, arg.flags);
393 ret = bch2_dev_offline(c, ca, arg.flags);
394 percpu_ref_put(&ca->ref);
398 static long bch2_ioctl_disk_set_state(struct bch_fs *c,
399 struct bch_ioctl_disk_set_state arg)
404 if (!capable(CAP_SYS_ADMIN))
407 if ((arg.flags & ~(BCH_FORCE_IF_DATA_LOST|
408 BCH_FORCE_IF_METADATA_LOST|
409 BCH_FORCE_IF_DEGRADED|
411 arg.pad[0] || arg.pad[1] || arg.pad[2] ||
412 arg.new_state >= BCH_MEMBER_STATE_NR)
415 ca = bch2_device_lookup(c, arg.dev, arg.flags);
419 ret = bch2_dev_set_state(c, ca, arg.new_state, arg.flags);
421 bch_err(c, "Error setting device state: %s", bch2_err_str(ret));
423 percpu_ref_put(&ca->ref);
427 struct bch_data_ctx {
428 struct thread_with_file thr;
431 struct bch_ioctl_data arg;
432 struct bch_move_stats stats;
435 static int bch2_data_thread(void *arg)
437 struct bch_data_ctx *ctx = container_of(arg, struct bch_data_ctx, thr);
439 ctx->thr.ret = bch2_data_job(ctx->c, &ctx->stats, ctx->arg);
440 ctx->stats.data_type = U8_MAX;
444 static int bch2_data_job_release(struct inode *inode, struct file *file)
446 struct bch_data_ctx *ctx = container_of(file->private_data, struct bch_data_ctx, thr);
448 bch2_thread_with_file_exit(&ctx->thr);
453 static ssize_t bch2_data_job_read(struct file *file, char __user *buf,
454 size_t len, loff_t *ppos)
456 struct bch_data_ctx *ctx = container_of(file->private_data, struct bch_data_ctx, thr);
457 struct bch_fs *c = ctx->c;
458 struct bch_ioctl_data_event e = {
459 .type = BCH_DATA_EVENT_PROGRESS,
460 .p.data_type = ctx->stats.data_type,
461 .p.btree_id = ctx->stats.pos.btree,
462 .p.pos = ctx->stats.pos.pos,
463 .p.sectors_done = atomic64_read(&ctx->stats.sectors_seen),
464 .p.sectors_total = bch2_fs_usage_read_short(c).used,
470 return copy_to_user_errcode(buf, &e, sizeof(e)) ?: sizeof(e);
473 static const struct file_operations bcachefs_data_ops = {
474 .release = bch2_data_job_release,
475 .read = bch2_data_job_read,
479 static long bch2_ioctl_data(struct bch_fs *c,
480 struct bch_ioctl_data arg)
482 struct bch_data_ctx *ctx;
485 if (!capable(CAP_SYS_ADMIN))
488 if (arg.op >= BCH_DATA_OP_NR || arg.flags)
491 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
498 ret = bch2_run_thread_with_file(&ctx->thr,
506 static long bch2_ioctl_fs_usage(struct bch_fs *c,
507 struct bch_ioctl_fs_usage __user *user_arg)
509 struct bch_ioctl_fs_usage *arg = NULL;
510 struct bch_replicas_usage *dst_e, *dst_end;
511 struct bch_fs_usage_online *src;
512 u32 replica_entries_bytes;
516 if (!test_bit(BCH_FS_started, &c->flags))
519 if (get_user(replica_entries_bytes, &user_arg->replica_entries_bytes))
522 arg = kzalloc(size_add(sizeof(*arg), replica_entries_bytes), GFP_KERNEL);
526 src = bch2_fs_usage_read(c);
532 arg->capacity = c->capacity;
533 arg->used = bch2_fs_sectors_used(c, src);
534 arg->online_reserved = src->online_reserved;
536 for (i = 0; i < BCH_REPLICAS_MAX; i++)
537 arg->persistent_reserved[i] = src->u.persistent_reserved[i];
539 dst_e = arg->replicas;
540 dst_end = (void *) arg->replicas + replica_entries_bytes;
542 for (i = 0; i < c->replicas.nr; i++) {
543 struct bch_replicas_entry_v1 *src_e =
544 cpu_replicas_entry(&c->replicas, i);
546 /* check that we have enough space for one replicas entry */
547 if (dst_e + 1 > dst_end) {
552 dst_e->sectors = src->u.replicas[i];
555 /* recheck after setting nr_devs: */
556 if (replicas_usage_next(dst_e) > dst_end) {
561 memcpy(dst_e->r.devs, src_e->devs, src_e->nr_devs);
563 dst_e = replicas_usage_next(dst_e);
566 arg->replica_entries_bytes = (void *) dst_e - (void *) arg->replicas;
568 percpu_up_read(&c->mark_lock);
574 ret = copy_to_user_errcode(user_arg, arg,
575 sizeof(*arg) + arg->replica_entries_bytes);
581 /* obsolete, didn't allow for new data types: */
582 static long bch2_ioctl_dev_usage(struct bch_fs *c,
583 struct bch_ioctl_dev_usage __user *user_arg)
585 struct bch_ioctl_dev_usage arg;
586 struct bch_dev_usage src;
590 if (!test_bit(BCH_FS_started, &c->flags))
593 if (copy_from_user(&arg, user_arg, sizeof(arg)))
596 if ((arg.flags & ~BCH_BY_INDEX) ||
602 ca = bch2_device_lookup(c, arg.dev, arg.flags);
606 src = bch2_dev_usage_read(ca);
608 arg.state = ca->mi.state;
609 arg.bucket_size = ca->mi.bucket_size;
610 arg.nr_buckets = ca->mi.nbuckets - ca->mi.first_bucket;
612 for (i = 0; i < BCH_DATA_NR; i++) {
613 arg.d[i].buckets = src.d[i].buckets;
614 arg.d[i].sectors = src.d[i].sectors;
615 arg.d[i].fragmented = src.d[i].fragmented;
618 percpu_ref_put(&ca->ref);
620 return copy_to_user_errcode(user_arg, &arg, sizeof(arg));
623 static long bch2_ioctl_dev_usage_v2(struct bch_fs *c,
624 struct bch_ioctl_dev_usage_v2 __user *user_arg)
626 struct bch_ioctl_dev_usage_v2 arg;
627 struct bch_dev_usage src;
631 if (!test_bit(BCH_FS_started, &c->flags))
634 if (copy_from_user(&arg, user_arg, sizeof(arg)))
637 if ((arg.flags & ~BCH_BY_INDEX) ||
643 ca = bch2_device_lookup(c, arg.dev, arg.flags);
647 src = bch2_dev_usage_read(ca);
649 arg.state = ca->mi.state;
650 arg.bucket_size = ca->mi.bucket_size;
651 arg.nr_data_types = min(arg.nr_data_types, BCH_DATA_NR);
652 arg.nr_buckets = ca->mi.nbuckets - ca->mi.first_bucket;
654 ret = copy_to_user_errcode(user_arg, &arg, sizeof(arg));
658 for (unsigned i = 0; i < arg.nr_data_types; i++) {
659 struct bch_ioctl_dev_usage_type t = {
660 .buckets = src.d[i].buckets,
661 .sectors = src.d[i].sectors,
662 .fragmented = src.d[i].fragmented,
665 ret = copy_to_user_errcode(&user_arg->d[i], &t, sizeof(t));
670 percpu_ref_put(&ca->ref);
674 static long bch2_ioctl_read_super(struct bch_fs *c,
675 struct bch_ioctl_read_super arg)
677 struct bch_dev *ca = NULL;
681 if (!capable(CAP_SYS_ADMIN))
684 if ((arg.flags & ~(BCH_BY_INDEX|BCH_READ_DEV)) ||
688 mutex_lock(&c->sb_lock);
690 if (arg.flags & BCH_READ_DEV) {
691 ca = bch2_device_lookup(c, arg.dev, arg.flags);
703 if (vstruct_bytes(sb) > arg.size) {
708 ret = copy_to_user_errcode((void __user *)(unsigned long)arg.sb, sb,
711 if (!IS_ERR_OR_NULL(ca))
712 percpu_ref_put(&ca->ref);
713 mutex_unlock(&c->sb_lock);
717 static long bch2_ioctl_disk_get_idx(struct bch_fs *c,
718 struct bch_ioctl_disk_get_idx arg)
720 dev_t dev = huge_decode_dev(arg.dev);
722 if (!capable(CAP_SYS_ADMIN))
728 for_each_online_member(c, ca)
729 if (ca->dev == dev) {
730 percpu_ref_put(&ca->io_ref);
734 return -BCH_ERR_ENOENT_dev_idx_not_found;
737 static long bch2_ioctl_disk_resize(struct bch_fs *c,
738 struct bch_ioctl_disk_resize arg)
743 if (!capable(CAP_SYS_ADMIN))
746 if ((arg.flags & ~BCH_BY_INDEX) ||
750 ca = bch2_device_lookup(c, arg.dev, arg.flags);
754 ret = bch2_dev_resize(c, ca, arg.nbuckets);
756 percpu_ref_put(&ca->ref);
760 static long bch2_ioctl_disk_resize_journal(struct bch_fs *c,
761 struct bch_ioctl_disk_resize_journal arg)
766 if (!capable(CAP_SYS_ADMIN))
769 if ((arg.flags & ~BCH_BY_INDEX) ||
773 if (arg.nbuckets > U32_MAX)
776 ca = bch2_device_lookup(c, arg.dev, arg.flags);
780 ret = bch2_set_nr_journal_buckets(c, ca, arg.nbuckets);
782 percpu_ref_put(&ca->ref);
786 static int bch2_fsck_online_thread_fn(struct thread_with_stdio *stdio)
788 struct fsck_thread *thr = container_of(stdio, struct fsck_thread, thr);
789 struct bch_fs *c = thr->c;
791 c->stdio_filter = current;
792 c->stdio = &thr->thr.stdio;
795 * XXX: can we figure out a way to do this without mucking with c->opts?
797 unsigned old_fix_errors = c->opts.fix_errors;
798 if (opt_defined(thr->opts, fix_errors))
799 c->opts.fix_errors = thr->opts.fix_errors;
801 c->opts.fix_errors = FSCK_FIX_ask;
804 set_bit(BCH_FS_fsck_running, &c->flags);
806 c->curr_recovery_pass = BCH_RECOVERY_PASS_check_alloc_info;
807 int ret = bch2_run_online_recovery_passes(c);
809 clear_bit(BCH_FS_fsck_running, &c->flags);
813 c->stdio_filter = NULL;
814 c->opts.fix_errors = old_fix_errors;
816 up(&c->online_fsck_mutex);
821 static const struct thread_with_stdio_ops bch2_online_fsck_ops = {
822 .exit = bch2_fsck_thread_exit,
823 .fn = bch2_fsck_online_thread_fn,
826 static long bch2_ioctl_fsck_online(struct bch_fs *c,
827 struct bch_ioctl_fsck_online arg)
829 struct fsck_thread *thr = NULL;
835 if (!capable(CAP_SYS_ADMIN))
838 if (!bch2_ro_ref_tryget(c))
841 if (down_trylock(&c->online_fsck_mutex)) {
846 thr = kzalloc(sizeof(*thr), GFP_KERNEL);
853 thr->opts = bch2_opts_empty();
856 char *optstr = strndup_user((char __user *)(unsigned long) arg.opts, 1 << 16);
858 ret = PTR_ERR_OR_ZERO(optstr) ?:
859 bch2_parse_mount_opts(c, &thr->opts, optstr);
866 ret = bch2_run_thread_with_stdio(&thr->thr, &bch2_online_fsck_ops);
871 bch2_fsck_thread_exit(&thr->thr);
872 up(&c->online_fsck_mutex);
878 #define BCH_IOCTL(_name, _argtype) \
882 if (copy_from_user(&i, arg, sizeof(i))) \
884 ret = bch2_ioctl_##_name(c, i); \
888 long bch2_fs_ioctl(struct bch_fs *c, unsigned cmd, void __user *arg)
893 case BCH_IOCTL_QUERY_UUID:
894 return bch2_ioctl_query_uuid(c, arg);
895 case BCH_IOCTL_FS_USAGE:
896 return bch2_ioctl_fs_usage(c, arg);
897 case BCH_IOCTL_DEV_USAGE:
898 return bch2_ioctl_dev_usage(c, arg);
899 case BCH_IOCTL_DEV_USAGE_V2:
900 return bch2_ioctl_dev_usage_v2(c, arg);
902 case BCH_IOCTL_START:
903 BCH_IOCTL(start, struct bch_ioctl_start);
905 return bch2_ioctl_stop(c);
907 case BCH_IOCTL_READ_SUPER:
908 BCH_IOCTL(read_super, struct bch_ioctl_read_super);
909 case BCH_IOCTL_DISK_GET_IDX:
910 BCH_IOCTL(disk_get_idx, struct bch_ioctl_disk_get_idx);
913 if (!test_bit(BCH_FS_started, &c->flags))
917 case BCH_IOCTL_DISK_ADD:
918 BCH_IOCTL(disk_add, struct bch_ioctl_disk);
919 case BCH_IOCTL_DISK_REMOVE:
920 BCH_IOCTL(disk_remove, struct bch_ioctl_disk);
921 case BCH_IOCTL_DISK_ONLINE:
922 BCH_IOCTL(disk_online, struct bch_ioctl_disk);
923 case BCH_IOCTL_DISK_OFFLINE:
924 BCH_IOCTL(disk_offline, struct bch_ioctl_disk);
925 case BCH_IOCTL_DISK_SET_STATE:
926 BCH_IOCTL(disk_set_state, struct bch_ioctl_disk_set_state);
928 BCH_IOCTL(data, struct bch_ioctl_data);
929 case BCH_IOCTL_DISK_RESIZE:
930 BCH_IOCTL(disk_resize, struct bch_ioctl_disk_resize);
931 case BCH_IOCTL_DISK_RESIZE_JOURNAL:
932 BCH_IOCTL(disk_resize_journal, struct bch_ioctl_disk_resize_journal);
933 case BCH_IOCTL_FSCK_ONLINE:
934 BCH_IOCTL(fsck_online, struct bch_ioctl_fsck_online);
940 ret = bch2_err_class(ret);
944 static DEFINE_IDR(bch_chardev_minor);
946 static long bch2_chardev_ioctl(struct file *filp, unsigned cmd, unsigned long v)
948 unsigned minor = iminor(file_inode(filp));
949 struct bch_fs *c = minor < U8_MAX ? idr_find(&bch_chardev_minor, minor) : NULL;
950 void __user *arg = (void __user *) v;
953 ? bch2_fs_ioctl(c, cmd, arg)
954 : bch2_global_ioctl(cmd, arg);
957 static const struct file_operations bch_chardev_fops = {
958 .owner = THIS_MODULE,
959 .unlocked_ioctl = bch2_chardev_ioctl,
960 .open = nonseekable_open,
963 static int bch_chardev_major;
964 static const struct class bch_chardev_class = {
967 static struct device *bch_chardev;
969 void bch2_fs_chardev_exit(struct bch_fs *c)
971 if (!IS_ERR_OR_NULL(c->chardev))
972 device_unregister(c->chardev);
974 idr_remove(&bch_chardev_minor, c->minor);
977 int bch2_fs_chardev_init(struct bch_fs *c)
979 c->minor = idr_alloc(&bch_chardev_minor, c, 0, 0, GFP_KERNEL);
983 c->chardev = device_create(&bch_chardev_class, NULL,
984 MKDEV(bch_chardev_major, c->minor), c,
985 "bcachefs%u-ctl", c->minor);
986 if (IS_ERR(c->chardev))
987 return PTR_ERR(c->chardev);
992 void bch2_chardev_exit(void)
994 device_destroy(&bch_chardev_class, MKDEV(bch_chardev_major, U8_MAX));
995 class_unregister(&bch_chardev_class);
996 if (bch_chardev_major > 0)
997 unregister_chrdev(bch_chardev_major, "bcachefs");
1000 int __init bch2_chardev_init(void)
1004 bch_chardev_major = register_chrdev(0, "bcachefs-ctl", &bch_chardev_fops);
1005 if (bch_chardev_major < 0)
1006 return bch_chardev_major;
1008 ret = class_register(&bch_chardev_class);
1012 bch_chardev = device_create(&bch_chardev_class, NULL,
1013 MKDEV(bch_chardev_major, U8_MAX),
1014 NULL, "bcachefs-ctl");
1015 if (IS_ERR(bch_chardev)) {
1016 ret = PTR_ERR(bch_chardev);
1023 class_unregister(&bch_chardev_class);
1025 unregister_chrdev(bch_chardev_major, "bcachefs-ctl");
1029 #endif /* NO_BCACHEFS_CHARDEV */