1 // SPDX-License-Identifier: GPL-2.0
3 * bcachefs setup/teardown code, and some metadata io - read a superblock and
4 * figure out what to do with it.
6 * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com>
7 * Copyright 2012 Google, Inc.
11 #include "alloc_background.h"
12 #include "alloc_foreground.h"
13 #include "bkey_sort.h"
14 #include "btree_cache.h"
16 #include "btree_update_interior.h"
23 #include "disk_groups.h"
32 #include "journal_reclaim.h"
37 #include "rebalance.h"
45 #include <linux/backing-dev.h>
46 #include <linux/blkdev.h>
47 #include <linux/debugfs.h>
48 #include <linux/device.h>
49 #include <linux/idr.h>
50 #include <linux/kthread.h>
51 #include <linux/module.h>
52 #include <linux/percpu.h>
53 #include <linux/random.h>
54 #include <linux/sysfs.h>
55 #include <crypto/hash.h>
57 MODULE_LICENSE("GPL");
58 MODULE_AUTHOR("Kent Overstreet <kent.overstreet@gmail.com>");
61 static const struct attribute_group type ## _group = { \
62 .attrs = type ## _files \
65 static const struct attribute_group *type ## _groups[] = { \
70 static const struct kobj_type type ## _ktype = { \
71 .release = type ## _release, \
72 .sysfs_ops = &type ## _sysfs_ops, \
73 .default_groups = type ## _groups \
76 static void bch2_fs_release(struct kobject *);
77 static void bch2_dev_release(struct kobject *);
79 static void bch2_fs_internal_release(struct kobject *k)
83 static void bch2_fs_opts_dir_release(struct kobject *k)
87 static void bch2_fs_time_stats_release(struct kobject *k)
92 KTYPE(bch2_fs_internal);
93 KTYPE(bch2_fs_opts_dir);
94 KTYPE(bch2_fs_time_stats);
97 static struct kset *bcachefs_kset;
98 static LIST_HEAD(bch_fs_list);
99 static DEFINE_MUTEX(bch_fs_list_lock);
101 static DECLARE_WAIT_QUEUE_HEAD(bch_read_only_wait);
103 static void bch2_dev_free(struct bch_dev *);
104 static int bch2_dev_alloc(struct bch_fs *, unsigned);
105 static int bch2_dev_sysfs_online(struct bch_fs *, struct bch_dev *);
106 static void __bch2_dev_read_only(struct bch_fs *, struct bch_dev *);
108 struct bch_fs *bch2_dev_to_fs(dev_t dev)
114 mutex_lock(&bch_fs_list_lock);
117 list_for_each_entry(c, &bch_fs_list, list)
118 for_each_member_device_rcu(ca, c, i, NULL)
119 if (ca->disk_sb.bdev->bd_dev == dev) {
126 mutex_unlock(&bch_fs_list_lock);
131 static struct bch_fs *__bch2_uuid_to_fs(__uuid_t uuid)
135 lockdep_assert_held(&bch_fs_list_lock);
137 list_for_each_entry(c, &bch_fs_list, list)
138 if (!memcmp(&c->disk_sb.sb->uuid, &uuid, sizeof(uuid)))
144 struct bch_fs *bch2_uuid_to_fs(__uuid_t uuid)
148 mutex_lock(&bch_fs_list_lock);
149 c = __bch2_uuid_to_fs(uuid);
152 mutex_unlock(&bch_fs_list_lock);
157 /* Filesystem RO/RW: */
160 * For startup/shutdown of RW stuff, the dependencies are:
162 * - foreground writes depend on copygc and rebalance (to free up space)
164 * - copygc and rebalance depend on mark and sweep gc (they actually probably
165 * don't because they either reserve ahead of time or don't block if
166 * allocations fail, but allocations can require mark and sweep gc to run
167 * because of generation number wraparound)
169 * - all of the above depends on the allocator threads
171 * - allocator depends on the journal (when it rewrites prios and gens)
174 static void __bch2_fs_read_only(struct bch_fs *c)
179 bch2_rebalance_stop(c);
181 for_each_member_device(ca, c, i)
182 bch2_copygc_stop(ca);
184 bch2_gc_thread_stop(c);
187 * Flush journal before stopping allocators, because flushing journal
188 * blacklist entries involves allocating new btree nodes:
190 bch2_journal_flush_all_pins(&c->journal);
192 for_each_member_device(ca, c, i)
193 bch2_dev_allocator_stop(ca);
195 bch2_journal_flush_all_pins(&c->journal);
198 * We need to explicitly wait on btree interior updates to complete
199 * before stopping the journal, flushing all journal pins isn't
200 * sufficient, because in the BTREE_INTERIOR_UPDATING_ROOT case btree
201 * interior updates have to drop their journal pin before they're
204 closure_wait_event(&c->btree_interior_update_wait,
205 !bch2_btree_interior_updates_nr_pending(c));
207 bch2_fs_journal_stop(&c->journal);
210 * the journal kicks off btree writes via reclaim - wait for in flight
211 * writes after stopping journal:
213 if (test_bit(BCH_FS_EMERGENCY_RO, &c->flags))
214 bch2_btree_flush_all_writes(c);
216 bch2_btree_verify_flushed(c);
219 * After stopping journal:
221 for_each_member_device(ca, c, i)
222 bch2_dev_allocator_remove(c, ca);
225 static void bch2_writes_disabled(struct percpu_ref *writes)
227 struct bch_fs *c = container_of(writes, struct bch_fs, writes);
229 set_bit(BCH_FS_WRITE_DISABLE_COMPLETE, &c->flags);
230 wake_up(&bch_read_only_wait);
233 void bch2_fs_read_only(struct bch_fs *c)
235 if (c->state == BCH_FS_RO)
238 BUG_ON(test_bit(BCH_FS_WRITE_DISABLE_COMPLETE, &c->flags));
241 * Block new foreground-end write operations from starting - any new
242 * writes will return -EROFS:
244 * (This is really blocking new _allocations_, writes to previously
245 * allocated space can still happen until stopping the allocator in
246 * bch2_dev_allocator_stop()).
248 percpu_ref_kill(&c->writes);
250 cancel_delayed_work(&c->pd_controllers_update);
253 * If we're not doing an emergency shutdown, we want to wait on
254 * outstanding writes to complete so they don't see spurious errors due
255 * to shutting down the allocator:
257 * If we are doing an emergency shutdown outstanding writes may
258 * hang until we shutdown the allocator so we don't want to wait
259 * on outstanding writes before shutting everything down - but
260 * we do need to wait on them before returning and signalling
261 * that going RO is complete:
263 wait_event(bch_read_only_wait,
264 test_bit(BCH_FS_WRITE_DISABLE_COMPLETE, &c->flags) ||
265 test_bit(BCH_FS_EMERGENCY_RO, &c->flags));
267 __bch2_fs_read_only(c);
269 wait_event(bch_read_only_wait,
270 test_bit(BCH_FS_WRITE_DISABLE_COMPLETE, &c->flags));
272 clear_bit(BCH_FS_WRITE_DISABLE_COMPLETE, &c->flags);
274 if (!bch2_journal_error(&c->journal) &&
275 !test_bit(BCH_FS_ERROR, &c->flags) &&
276 !test_bit(BCH_FS_EMERGENCY_RO, &c->flags))
277 bch2_fs_mark_clean(c, true);
279 if (c->state != BCH_FS_STOPPING)
280 c->state = BCH_FS_RO;
283 static void bch2_fs_read_only_work(struct work_struct *work)
286 container_of(work, struct bch_fs, read_only_work);
288 mutex_lock(&c->state_lock);
289 bch2_fs_read_only(c);
290 mutex_unlock(&c->state_lock);
293 static void bch2_fs_read_only_async(struct bch_fs *c)
295 queue_work(system_long_wq, &c->read_only_work);
298 bool bch2_fs_emergency_read_only(struct bch_fs *c)
300 bool ret = !test_and_set_bit(BCH_FS_EMERGENCY_RO, &c->flags);
302 bch2_fs_read_only_async(c);
303 bch2_journal_halt(&c->journal);
305 wake_up(&bch_read_only_wait);
309 const char *bch2_fs_read_write(struct bch_fs *c)
312 const char *err = NULL;
315 if (c->state == BCH_FS_RW)
318 bch2_fs_mark_clean(c, false);
320 for_each_rw_member(ca, c, i)
321 bch2_dev_allocator_add(c, ca);
322 bch2_recalc_capacity(c);
324 err = "error starting allocator thread";
325 for_each_rw_member(ca, c, i)
326 if (bch2_dev_allocator_start(ca)) {
327 percpu_ref_put(&ca->io_ref);
331 err = "error starting btree GC thread";
332 if (bch2_gc_thread_start(c))
335 err = "error starting copygc thread";
336 for_each_rw_member(ca, c, i)
337 if (bch2_copygc_start(c, ca)) {
338 percpu_ref_put(&ca->io_ref);
342 err = "error starting rebalance thread";
343 if (bch2_rebalance_start(c))
346 schedule_delayed_work(&c->pd_controllers_update, 5 * HZ);
348 if (c->state != BCH_FS_STARTING)
349 percpu_ref_reinit(&c->writes);
351 c->state = BCH_FS_RW;
354 __bch2_fs_read_only(c);
358 /* Filesystem startup/shutdown: */
360 static void bch2_fs_free(struct bch_fs *c)
364 for (i = 0; i < BCH_TIME_STAT_NR; i++)
365 bch2_time_stats_exit(&c->times[i]);
367 bch2_fs_quota_exit(c);
368 bch2_fs_fsio_exit(c);
370 bch2_fs_encryption_exit(c);
372 bch2_fs_btree_cache_exit(c);
373 bch2_fs_journal_exit(&c->journal);
374 bch2_io_clock_exit(&c->io_clock[WRITE]);
375 bch2_io_clock_exit(&c->io_clock[READ]);
376 bch2_fs_compress_exit(c);
377 percpu_free_rwsem(&c->usage_lock);
378 free_percpu(c->usage[0]);
379 mempool_exit(&c->btree_iters_pool);
380 mempool_exit(&c->btree_bounce_pool);
381 bioset_exit(&c->btree_bio);
382 mempool_exit(&c->btree_interior_update_pool);
383 mempool_exit(&c->btree_reserve_pool);
384 mempool_exit(&c->fill_iter);
385 percpu_ref_exit(&c->writes);
386 kfree(rcu_dereference_protected(c->replicas, 1));
387 kfree(rcu_dereference_protected(c->disk_groups, 1));
390 destroy_workqueue(c->copygc_wq);
392 destroy_workqueue(c->wq);
394 free_pages((unsigned long) c->disk_sb.sb,
395 c->disk_sb.page_order);
396 kvpfree(c, sizeof(*c));
397 module_put(THIS_MODULE);
400 static void bch2_fs_release(struct kobject *kobj)
402 struct bch_fs *c = container_of(kobj, struct bch_fs, kobj);
407 void bch2_fs_stop(struct bch_fs *c)
412 bch_verbose(c, "shutting down");
414 for_each_member_device(ca, c, i)
415 if (ca->kobj.state_in_sysfs &&
417 sysfs_remove_link(bdev_kobj(ca->disk_sb.bdev), "bcachefs");
419 if (c->kobj.state_in_sysfs)
420 kobject_del(&c->kobj);
422 bch2_fs_debug_exit(c);
423 bch2_fs_chardev_exit(c);
425 kobject_put(&c->time_stats);
426 kobject_put(&c->opts_dir);
427 kobject_put(&c->internal);
429 mutex_lock(&bch_fs_list_lock);
431 mutex_unlock(&bch_fs_list_lock);
433 closure_sync(&c->cl);
434 closure_debug_destroy(&c->cl);
436 mutex_lock(&c->state_lock);
437 bch2_fs_read_only(c);
438 mutex_unlock(&c->state_lock);
440 /* btree prefetch might have kicked off reads in the background: */
441 bch2_btree_flush_all_reads(c);
443 for_each_member_device(ca, c, i)
444 cancel_work_sync(&ca->io_error_work);
446 cancel_work_sync(&c->btree_write_error_work);
447 cancel_delayed_work_sync(&c->pd_controllers_update);
448 cancel_work_sync(&c->read_only_work);
450 for (i = 0; i < c->sb.nr_devices; i++)
452 bch2_dev_free(rcu_dereference_protected(c->devs[i], 1));
454 bch_verbose(c, "shutdown complete");
456 kobject_put(&c->kobj);
459 static const char *bch2_fs_online(struct bch_fs *c)
462 const char *err = NULL;
466 lockdep_assert_held(&bch_fs_list_lock);
468 if (!list_empty(&c->list))
471 if (__bch2_uuid_to_fs(c->sb.uuid))
472 return "filesystem UUID already open";
474 ret = bch2_fs_chardev_init(c);
476 return "error creating character device";
478 bch2_fs_debug_init(c);
480 if (kobject_add(&c->kobj, NULL, "%pU", c->sb.user_uuid.b) ||
481 kobject_add(&c->internal, &c->kobj, "internal") ||
482 kobject_add(&c->opts_dir, &c->kobj, "options") ||
483 kobject_add(&c->time_stats, &c->kobj, "time_stats") ||
484 bch2_opts_create_sysfs_files(&c->opts_dir))
485 return "error creating sysfs objects";
487 mutex_lock(&c->state_lock);
489 err = "error creating sysfs objects";
490 __for_each_member_device(ca, c, i, NULL)
491 if (bch2_dev_sysfs_online(c, ca))
494 list_add(&c->list, &bch_fs_list);
497 mutex_unlock(&c->state_lock);
501 static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
503 struct bch_sb_field_members *mi;
505 unsigned i, iter_size;
508 pr_verbose_init(opts, "");
510 c = kvpmalloc(sizeof(struct bch_fs), GFP_KERNEL|__GFP_ZERO);
514 __module_get(THIS_MODULE);
517 c->disk_sb.fs_sb = true;
519 mutex_init(&c->state_lock);
520 mutex_init(&c->sb_lock);
521 mutex_init(&c->replicas_gc_lock);
522 mutex_init(&c->btree_root_lock);
523 INIT_WORK(&c->read_only_work, bch2_fs_read_only_work);
525 init_rwsem(&c->gc_lock);
527 for (i = 0; i < BCH_TIME_STAT_NR; i++)
528 bch2_time_stats_init(&c->times[i]);
530 bch2_fs_allocator_background_init(c);
531 bch2_fs_allocator_foreground_init(c);
532 bch2_fs_rebalance_init(c);
533 bch2_fs_quota_init(c);
535 INIT_LIST_HEAD(&c->list);
537 INIT_LIST_HEAD(&c->btree_interior_update_list);
538 mutex_init(&c->btree_reserve_cache_lock);
539 mutex_init(&c->btree_interior_update_lock);
541 mutex_init(&c->bio_bounce_pages_lock);
543 bio_list_init(&c->btree_write_error_list);
544 spin_lock_init(&c->btree_write_error_lock);
545 INIT_WORK(&c->btree_write_error_work, bch2_btree_write_error_work);
547 INIT_LIST_HEAD(&c->fsck_errors);
548 mutex_init(&c->fsck_error_lock);
550 INIT_LIST_HEAD(&c->ec_new_stripe_list);
551 mutex_init(&c->ec_new_stripe_lock);
552 mutex_init(&c->ec_stripe_create_lock);
553 spin_lock_init(&c->ec_stripes_heap_lock);
555 seqcount_init(&c->gc_pos_lock);
557 c->copy_gc_enabled = 1;
558 c->rebalance.enabled = 1;
559 c->promote_whole_extents = true;
561 c->journal.write_time = &c->times[BCH_TIME_journal_write];
562 c->journal.delay_time = &c->times[BCH_TIME_journal_delay];
563 c->journal.blocked_time = &c->times[BCH_TIME_journal_blocked];
564 c->journal.flush_seq_time = &c->times[BCH_TIME_journal_flush_seq];
566 bch2_fs_btree_cache_init_early(&c->btree_cache);
568 mutex_lock(&c->sb_lock);
570 if (bch2_sb_to_fs(c, sb)) {
571 mutex_unlock(&c->sb_lock);
575 mutex_unlock(&c->sb_lock);
577 scnprintf(c->name, sizeof(c->name), "%pU", &c->sb.user_uuid);
579 c->opts = bch2_opts_default;
580 bch2_opts_apply(&c->opts, bch2_opts_from_sb(sb));
581 bch2_opts_apply(&c->opts, opts);
583 c->block_bits = ilog2(c->opts.block_size);
584 c->btree_foreground_merge_threshold = BTREE_FOREGROUND_MERGE_THRESHOLD(c);
586 c->opts.nochanges |= c->opts.noreplay;
587 c->opts.read_only |= c->opts.nochanges;
589 if (bch2_fs_init_fault("fs_alloc"))
592 iter_size = sizeof(struct btree_node_iter_large) +
593 (btree_blocks(c) + 1) * 2 *
594 sizeof(struct btree_node_iter_set);
596 if (!(c->wq = alloc_workqueue("bcachefs",
597 WQ_FREEZABLE|WQ_MEM_RECLAIM|WQ_HIGHPRI, 1)) ||
598 !(c->copygc_wq = alloc_workqueue("bcache_copygc",
599 WQ_FREEZABLE|WQ_MEM_RECLAIM|WQ_HIGHPRI, 1)) ||
600 percpu_ref_init(&c->writes, bch2_writes_disabled, 0, GFP_KERNEL) ||
601 mempool_init_kmalloc_pool(&c->btree_reserve_pool, 1,
602 sizeof(struct btree_reserve)) ||
603 mempool_init_kmalloc_pool(&c->btree_interior_update_pool, 1,
604 sizeof(struct btree_update)) ||
605 mempool_init_kmalloc_pool(&c->fill_iter, 1, iter_size) ||
606 bioset_init(&c->btree_bio, 1,
607 max(offsetof(struct btree_read_bio, bio),
608 offsetof(struct btree_write_bio, wbio.bio)),
609 BIOSET_NEED_BVECS) ||
610 !(c->usage[0] = alloc_percpu(struct bch_fs_usage)) ||
611 percpu_init_rwsem(&c->usage_lock) ||
612 mempool_init_kvpmalloc_pool(&c->btree_bounce_pool, 1,
614 mempool_init_kmalloc_pool(&c->btree_iters_pool, 1,
615 sizeof(struct btree_iter) * BTREE_ITER_MAX) ||
616 bch2_io_clock_init(&c->io_clock[READ]) ||
617 bch2_io_clock_init(&c->io_clock[WRITE]) ||
618 bch2_fs_journal_init(&c->journal) ||
619 bch2_fs_btree_cache_init(c) ||
620 bch2_fs_io_init(c) ||
621 bch2_fs_encryption_init(c) ||
622 bch2_fs_compress_init(c) ||
623 bch2_fs_ec_init(c) ||
624 bch2_fs_fsio_init(c))
627 mi = bch2_sb_get_members(c->disk_sb.sb);
628 for (i = 0; i < c->sb.nr_devices; i++)
629 if (bch2_dev_exists(c->disk_sb.sb, mi, i) &&
630 bch2_dev_alloc(c, i))
634 * Now that all allocations have succeeded, init various refcounty
635 * things that let us shutdown:
637 closure_init(&c->cl, NULL);
639 c->kobj.kset = bcachefs_kset;
640 kobject_init(&c->kobj, &bch2_fs_ktype);
641 kobject_init(&c->internal, &bch2_fs_internal_ktype);
642 kobject_init(&c->opts_dir, &bch2_fs_opts_dir_ktype);
643 kobject_init(&c->time_stats, &bch2_fs_time_stats_ktype);
645 mutex_lock(&bch_fs_list_lock);
646 err = bch2_fs_online(c);
647 mutex_unlock(&bch_fs_list_lock);
649 bch_err(c, "bch2_fs_online() error: %s", err);
653 pr_verbose_init(opts, "ret %i", c ? 0 : -ENOMEM);
661 const char *bch2_fs_start(struct bch_fs *c)
663 const char *err = "cannot allocate memory";
664 struct bch_sb_field_members *mi;
666 time64_t now = ktime_get_real_seconds();
670 mutex_lock(&c->state_lock);
672 BUG_ON(c->state != BCH_FS_STARTING);
674 mutex_lock(&c->sb_lock);
676 for_each_online_member(ca, c, i)
677 bch2_sb_from_fs(c, ca);
679 mi = bch2_sb_get_members(c->disk_sb.sb);
680 for_each_online_member(ca, c, i)
681 mi->members[ca->dev_idx].last_mount = cpu_to_le64(now);
683 mutex_unlock(&c->sb_lock);
685 for_each_rw_member(ca, c, i)
686 bch2_dev_allocator_add(c, ca);
687 bch2_recalc_capacity(c);
689 ret = BCH_SB_INITIALIZED(c->disk_sb.sb)
690 ? bch2_fs_recovery(c)
691 : bch2_fs_initialize(c);
695 ret = bch2_opts_check_may_set(c);
699 err = "dynamic fault";
700 if (bch2_fs_init_fault("fs_start"))
703 if (c->opts.read_only) {
704 bch2_fs_read_only(c);
706 err = bch2_fs_read_write(c);
711 set_bit(BCH_FS_STARTED, &c->flags);
715 mutex_unlock(&c->state_lock);
719 case BCH_FSCK_ERRORS_NOT_FIXED:
720 bch_err(c, "filesystem contains errors: please report this to the developers");
721 pr_cont("mount with -o fix_errors to repair\n");
724 case BCH_FSCK_REPAIR_UNIMPLEMENTED:
725 bch_err(c, "filesystem contains errors: please report this to the developers");
726 pr_cont("repair unimplemented: inform the developers so that it can be added\n");
729 case BCH_FSCK_REPAIR_IMPOSSIBLE:
730 bch_err(c, "filesystem contains errors, but repair impossible");
733 case BCH_FSCK_UNKNOWN_VERSION:
734 err = "unknown metadata version";;
737 err = "cannot allocate memory";
745 set_bit(BCH_FS_ERROR, &c->flags);
749 static const char *bch2_dev_may_add(struct bch_sb *sb, struct bch_fs *c)
751 struct bch_sb_field_members *sb_mi;
753 sb_mi = bch2_sb_get_members(sb);
755 return "Invalid superblock: member info area missing";
757 if (le16_to_cpu(sb->block_size) != c->opts.block_size)
758 return "mismatched block size";
760 if (le16_to_cpu(sb_mi->members[sb->dev_idx].bucket_size) <
761 BCH_SB_BTREE_NODE_SIZE(c->disk_sb.sb))
762 return "new cache bucket size is too small";
767 static const char *bch2_dev_in_fs(struct bch_sb *fs, struct bch_sb *sb)
769 struct bch_sb *newest =
770 le64_to_cpu(fs->seq) > le64_to_cpu(sb->seq) ? fs : sb;
771 struct bch_sb_field_members *mi = bch2_sb_get_members(newest);
773 if (!uuid_equal(&fs->uuid, &sb->uuid))
774 return "device not a member of filesystem";
776 if (!bch2_dev_exists(newest, mi, sb->dev_idx))
777 return "device has been removed";
779 if (fs->block_size != sb->block_size)
780 return "mismatched block size";
785 /* Device startup/shutdown: */
787 static void bch2_dev_release(struct kobject *kobj)
789 struct bch_dev *ca = container_of(kobj, struct bch_dev, kobj);
794 static void bch2_dev_free(struct bch_dev *ca)
796 cancel_work_sync(&ca->io_error_work);
798 if (ca->kobj.state_in_sysfs &&
800 sysfs_remove_link(bdev_kobj(ca->disk_sb.bdev), "bcachefs");
802 if (ca->kobj.state_in_sysfs)
803 kobject_del(&ca->kobj);
805 bch2_free_super(&ca->disk_sb);
806 bch2_dev_journal_exit(ca);
808 free_percpu(ca->io_done);
809 bioset_exit(&ca->replica_set);
810 bch2_dev_buckets_free(ca);
812 bch2_time_stats_exit(&ca->io_latency[WRITE]);
813 bch2_time_stats_exit(&ca->io_latency[READ]);
815 percpu_ref_exit(&ca->io_ref);
816 percpu_ref_exit(&ca->ref);
817 kobject_put(&ca->kobj);
820 static void __bch2_dev_offline(struct bch_fs *c, struct bch_dev *ca)
823 lockdep_assert_held(&c->state_lock);
825 if (percpu_ref_is_zero(&ca->io_ref))
828 __bch2_dev_read_only(c, ca);
830 reinit_completion(&ca->io_ref_completion);
831 percpu_ref_kill(&ca->io_ref);
832 wait_for_completion(&ca->io_ref_completion);
834 if (ca->kobj.state_in_sysfs) {
835 sysfs_remove_link(bdev_kobj(ca->disk_sb.bdev), "bcachefs");
836 sysfs_remove_link(&ca->kobj, "block");
839 bch2_free_super(&ca->disk_sb);
840 bch2_dev_journal_exit(ca);
843 static void bch2_dev_ref_complete(struct percpu_ref *ref)
845 struct bch_dev *ca = container_of(ref, struct bch_dev, ref);
847 complete(&ca->ref_completion);
850 static void bch2_dev_io_ref_complete(struct percpu_ref *ref)
852 struct bch_dev *ca = container_of(ref, struct bch_dev, io_ref);
854 complete(&ca->io_ref_completion);
857 static int bch2_dev_sysfs_online(struct bch_fs *c, struct bch_dev *ca)
861 if (!c->kobj.state_in_sysfs)
864 if (!ca->kobj.state_in_sysfs) {
865 ret = kobject_add(&ca->kobj, &c->kobj,
866 "dev-%u", ca->dev_idx);
871 if (ca->disk_sb.bdev) {
872 struct kobject *block = bdev_kobj(ca->disk_sb.bdev);
874 ret = sysfs_create_link(block, &ca->kobj, "bcachefs");
878 ret = sysfs_create_link(&ca->kobj, block, "block");
886 static struct bch_dev *__bch2_dev_alloc(struct bch_fs *c,
887 struct bch_member *member)
891 ca = kzalloc(sizeof(*ca), GFP_KERNEL);
895 kobject_init(&ca->kobj, &bch2_dev_ktype);
896 init_completion(&ca->ref_completion);
897 init_completion(&ca->io_ref_completion);
899 init_rwsem(&ca->bucket_lock);
901 writepoint_init(&ca->copygc_write_point, BCH_DATA_USER);
903 spin_lock_init(&ca->freelist_lock);
904 bch2_dev_copygc_init(ca);
906 INIT_WORK(&ca->io_error_work, bch2_io_error_work);
908 bch2_time_stats_init(&ca->io_latency[READ]);
909 bch2_time_stats_init(&ca->io_latency[WRITE]);
911 ca->mi = bch2_mi_to_cpu(member);
912 ca->uuid = member->uuid;
914 if (opt_defined(c->opts, discard))
915 ca->mi.discard = opt_get(c->opts, discard);
917 if (percpu_ref_init(&ca->ref, bch2_dev_ref_complete,
919 percpu_ref_init(&ca->io_ref, bch2_dev_io_ref_complete,
920 PERCPU_REF_INIT_DEAD, GFP_KERNEL) ||
921 bch2_dev_buckets_alloc(c, ca) ||
922 bioset_init(&ca->replica_set, 4,
923 offsetof(struct bch_write_bio, bio), 0) ||
924 !(ca->io_done = alloc_percpu(*ca->io_done)))
933 static void bch2_dev_attach(struct bch_fs *c, struct bch_dev *ca,
936 ca->dev_idx = dev_idx;
937 __set_bit(ca->dev_idx, ca->self.d);
938 scnprintf(ca->name, sizeof(ca->name), "dev-%u", dev_idx);
941 rcu_assign_pointer(c->devs[ca->dev_idx], ca);
943 if (bch2_dev_sysfs_online(c, ca))
944 pr_warn("error creating sysfs objects");
947 static int bch2_dev_alloc(struct bch_fs *c, unsigned dev_idx)
949 struct bch_member *member =
950 bch2_sb_get_members(c->disk_sb.sb)->members + dev_idx;
951 struct bch_dev *ca = NULL;
954 pr_verbose_init(c->opts, "");
956 if (bch2_fs_init_fault("dev_alloc"))
959 ca = __bch2_dev_alloc(c, member);
963 bch2_dev_attach(c, ca, dev_idx);
965 pr_verbose_init(c->opts, "ret %i", ret);
974 static int __bch2_dev_attach_bdev(struct bch_dev *ca, struct bch_sb_handle *sb)
978 if (bch2_dev_is_online(ca)) {
979 bch_err(ca, "already have device online in slot %u",
984 if (get_capacity(sb->bdev->bd_disk) <
985 ca->mi.bucket_size * ca->mi.nbuckets) {
986 bch_err(ca, "cannot online: device too small");
990 BUG_ON(!percpu_ref_is_zero(&ca->io_ref));
992 if (get_capacity(sb->bdev->bd_disk) <
993 ca->mi.bucket_size * ca->mi.nbuckets) {
994 bch_err(ca, "device too small");
998 ret = bch2_dev_journal_init(ca, sb->sb);
1004 memset(sb, 0, sizeof(*sb));
1006 percpu_ref_reinit(&ca->io_ref);
1011 static int bch2_dev_attach_bdev(struct bch_fs *c, struct bch_sb_handle *sb)
1016 lockdep_assert_held(&c->state_lock);
1018 if (le64_to_cpu(sb->sb->seq) >
1019 le64_to_cpu(c->disk_sb.sb->seq))
1020 bch2_sb_to_fs(c, sb->sb);
1022 BUG_ON(sb->sb->dev_idx >= c->sb.nr_devices ||
1023 !c->devs[sb->sb->dev_idx]);
1025 ca = bch_dev_locked(c, sb->sb->dev_idx);
1027 ret = __bch2_dev_attach_bdev(ca, sb);
1031 mutex_lock(&c->sb_lock);
1032 bch2_mark_dev_superblock(ca->fs, ca, 0);
1033 mutex_unlock(&c->sb_lock);
1035 bch2_dev_sysfs_online(c, ca);
1037 if (c->sb.nr_devices == 1)
1038 snprintf(c->name, sizeof(c->name), "%pg", ca->disk_sb.bdev);
1039 snprintf(ca->name, sizeof(ca->name), "%pg", ca->disk_sb.bdev);
1041 rebalance_wakeup(c);
1045 /* Device management: */
1048 * Note: this function is also used by the error paths - when a particular
1049 * device sees an error, we call it to determine whether we can just set the
1050 * device RO, or - if this function returns false - we'll set the whole
1053 * XXX: maybe we should be more explicit about whether we're changing state
1054 * because we got an error or what have you?
1056 bool bch2_dev_state_allowed(struct bch_fs *c, struct bch_dev *ca,
1057 enum bch_member_state new_state, int flags)
1059 struct bch_devs_mask new_online_devs;
1060 struct replicas_status s;
1061 struct bch_dev *ca2;
1062 int i, nr_rw = 0, required;
1064 lockdep_assert_held(&c->state_lock);
1066 switch (new_state) {
1067 case BCH_MEMBER_STATE_RW:
1069 case BCH_MEMBER_STATE_RO:
1070 if (ca->mi.state != BCH_MEMBER_STATE_RW)
1073 /* do we have enough devices to write to? */
1074 for_each_member_device(ca2, c, i)
1076 nr_rw += ca2->mi.state == BCH_MEMBER_STATE_RW;
1078 required = max(!(flags & BCH_FORCE_IF_METADATA_DEGRADED)
1079 ? c->opts.metadata_replicas
1080 : c->opts.metadata_replicas_required,
1081 !(flags & BCH_FORCE_IF_DATA_DEGRADED)
1082 ? c->opts.data_replicas
1083 : c->opts.data_replicas_required);
1085 return nr_rw >= required;
1086 case BCH_MEMBER_STATE_FAILED:
1087 case BCH_MEMBER_STATE_SPARE:
1088 if (ca->mi.state != BCH_MEMBER_STATE_RW &&
1089 ca->mi.state != BCH_MEMBER_STATE_RO)
1092 /* do we have enough devices to read from? */
1093 new_online_devs = bch2_online_devs(c);
1094 __clear_bit(ca->dev_idx, new_online_devs.d);
1096 s = __bch2_replicas_status(c, new_online_devs);
1098 return bch2_have_enough_devs(s, flags);
1104 static bool bch2_fs_may_start(struct bch_fs *c)
1106 struct replicas_status s;
1107 struct bch_sb_field_members *mi;
1109 unsigned i, flags = c->opts.degraded
1110 ? BCH_FORCE_IF_DEGRADED
1113 if (!c->opts.degraded) {
1114 mutex_lock(&c->sb_lock);
1115 mi = bch2_sb_get_members(c->disk_sb.sb);
1117 for (i = 0; i < c->disk_sb.sb->nr_devices; i++) {
1118 if (!bch2_dev_exists(c->disk_sb.sb, mi, i))
1121 ca = bch_dev_locked(c, i);
1123 if (!bch2_dev_is_online(ca) &&
1124 (ca->mi.state == BCH_MEMBER_STATE_RW ||
1125 ca->mi.state == BCH_MEMBER_STATE_RO)) {
1126 mutex_unlock(&c->sb_lock);
1130 mutex_unlock(&c->sb_lock);
1133 s = bch2_replicas_status(c);
1135 return bch2_have_enough_devs(s, flags);
1138 static void __bch2_dev_read_only(struct bch_fs *c, struct bch_dev *ca)
1140 bch2_copygc_stop(ca);
1143 * The allocator thread itself allocates btree nodes, so stop it first:
1145 bch2_dev_allocator_stop(ca);
1146 bch2_dev_allocator_remove(c, ca);
1147 bch2_dev_journal_stop(&c->journal, ca);
1150 static const char *__bch2_dev_read_write(struct bch_fs *c, struct bch_dev *ca)
1152 lockdep_assert_held(&c->state_lock);
1154 BUG_ON(ca->mi.state != BCH_MEMBER_STATE_RW);
1156 bch2_dev_allocator_add(c, ca);
1157 bch2_recalc_capacity(c);
1159 if (bch2_dev_allocator_start(ca))
1160 return "error starting allocator thread";
1162 if (bch2_copygc_start(c, ca))
1163 return "error starting copygc thread";
1168 int __bch2_dev_set_state(struct bch_fs *c, struct bch_dev *ca,
1169 enum bch_member_state new_state, int flags)
1171 struct bch_sb_field_members *mi;
1174 if (ca->mi.state == new_state)
1177 if (!bch2_dev_state_allowed(c, ca, new_state, flags))
1180 if (new_state != BCH_MEMBER_STATE_RW)
1181 __bch2_dev_read_only(c, ca);
1183 bch_notice(ca, "%s", bch2_dev_state[new_state]);
1185 mutex_lock(&c->sb_lock);
1186 mi = bch2_sb_get_members(c->disk_sb.sb);
1187 SET_BCH_MEMBER_STATE(&mi->members[ca->dev_idx], new_state);
1188 bch2_write_super(c);
1189 mutex_unlock(&c->sb_lock);
1191 if (new_state == BCH_MEMBER_STATE_RW &&
1192 __bch2_dev_read_write(c, ca))
1195 rebalance_wakeup(c);
1200 int bch2_dev_set_state(struct bch_fs *c, struct bch_dev *ca,
1201 enum bch_member_state new_state, int flags)
1205 mutex_lock(&c->state_lock);
1206 ret = __bch2_dev_set_state(c, ca, new_state, flags);
1207 mutex_unlock(&c->state_lock);
1212 /* Device add/removal: */
1214 int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags)
1216 struct bch_sb_field_members *mi;
1217 unsigned dev_idx = ca->dev_idx, data;
1220 mutex_lock(&c->state_lock);
1222 percpu_ref_put(&ca->ref); /* XXX */
1224 if (!bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_FAILED, flags)) {
1225 bch_err(ca, "Cannot remove without losing data");
1229 __bch2_dev_read_only(c, ca);
1232 * XXX: verify that dev_idx is really not in use anymore, anywhere
1234 * flag_data_bad() does not check btree pointers
1236 ret = bch2_dev_data_drop(c, ca->dev_idx, flags);
1238 bch_err(ca, "Remove failed: error %i dropping data", ret);
1242 ret = bch2_journal_flush_device_pins(&c->journal, ca->dev_idx);
1244 bch_err(ca, "Remove failed: error %i flushing journal", ret);
1248 data = bch2_dev_has_data(c, ca);
1250 char data_has_str[100];
1252 bch2_string_opt_to_text(&PBUF(data_has_str),
1253 bch2_data_types, data);
1254 bch_err(ca, "Remove failed, still has data (%s)", data_has_str);
1259 ret = bch2_btree_delete_range(c, BTREE_ID_ALLOC,
1260 POS(ca->dev_idx, 0),
1261 POS(ca->dev_idx + 1, 0),
1264 bch_err(ca, "Remove failed, error deleting alloc info");
1269 * must flush all existing journal entries, they might have
1270 * (overwritten) keys that point to the device we're removing:
1272 bch2_journal_flush_all_pins(&c->journal);
1273 ret = bch2_journal_error(&c->journal);
1275 bch_err(ca, "Remove failed, journal error");
1279 __bch2_dev_offline(c, ca);
1281 mutex_lock(&c->sb_lock);
1282 rcu_assign_pointer(c->devs[ca->dev_idx], NULL);
1283 mutex_unlock(&c->sb_lock);
1285 percpu_ref_kill(&ca->ref);
1286 wait_for_completion(&ca->ref_completion);
1291 * Free this device's slot in the bch_member array - all pointers to
1292 * this device must be gone:
1294 mutex_lock(&c->sb_lock);
1295 mi = bch2_sb_get_members(c->disk_sb.sb);
1296 memset(&mi->members[dev_idx].uuid, 0, sizeof(mi->members[dev_idx].uuid));
1298 bch2_write_super(c);
1300 mutex_unlock(&c->sb_lock);
1301 mutex_unlock(&c->state_lock);
1304 if (ca->mi.state == BCH_MEMBER_STATE_RW)
1305 __bch2_dev_read_write(c, ca);
1306 mutex_unlock(&c->state_lock);
1310 static void dev_usage_clear(struct bch_dev *ca)
1312 struct bucket_array *buckets;
1315 for_each_possible_cpu(cpu) {
1316 struct bch_dev_usage *p =
1317 per_cpu_ptr(ca->usage[0], cpu);
1318 memset(p, 0, sizeof(*p));
1321 down_read(&ca->bucket_lock);
1322 buckets = bucket_array(ca);
1324 memset(buckets->b, 0, sizeof(buckets->b[0]) * buckets->nbuckets);
1325 up_read(&ca->bucket_lock);
1328 /* Add new device to running filesystem: */
1329 int bch2_dev_add(struct bch_fs *c, const char *path)
1331 struct bch_opts opts = bch2_opts_empty();
1332 struct bch_sb_handle sb;
1334 struct bch_dev *ca = NULL;
1335 struct bch_sb_field_members *mi;
1336 struct bch_member dev_mi;
1337 unsigned dev_idx, nr_devices, u64s;
1340 ret = bch2_read_super(path, &opts, &sb);
1344 err = bch2_sb_validate(&sb);
1348 dev_mi = bch2_sb_get_members(sb.sb)->members[sb.sb->dev_idx];
1350 err = bch2_dev_may_add(sb.sb, c);
1354 ca = __bch2_dev_alloc(c, &dev_mi);
1356 bch2_free_super(&sb);
1360 ret = __bch2_dev_attach_bdev(ca, &sb);
1367 * We want to allocate journal on the new device before adding the new
1368 * device to the filesystem because allocating after we attach requires
1369 * spinning up the allocator thread, and the allocator thread requires
1370 * doing btree writes, which if the existing devices are RO isn't going
1373 * So we have to mark where the superblocks are, but marking allocated
1374 * data normally updates the filesystem usage too, so we have to mark,
1375 * allocate the journal, reset all the marks, then remark after we
1378 bch2_mark_dev_superblock(ca->fs, ca, 0);
1380 err = "journal alloc failed";
1381 ret = bch2_dev_journal_alloc(ca);
1385 dev_usage_clear(ca);
1387 mutex_lock(&c->state_lock);
1388 mutex_lock(&c->sb_lock);
1390 err = "insufficient space in new superblock";
1391 ret = bch2_sb_from_fs(c, ca);
1395 mi = bch2_sb_get_members(ca->disk_sb.sb);
1397 if (!bch2_sb_resize_members(&ca->disk_sb,
1398 le32_to_cpu(mi->field.u64s) +
1399 sizeof(dev_mi) / sizeof(u64))) {
1404 if (dynamic_fault("bcachefs:add:no_slot"))
1407 mi = bch2_sb_get_members(c->disk_sb.sb);
1408 for (dev_idx = 0; dev_idx < BCH_SB_MEMBERS_MAX; dev_idx++)
1409 if (!bch2_dev_exists(c->disk_sb.sb, mi, dev_idx))
1412 err = "no slots available in superblock";
1417 nr_devices = max_t(unsigned, dev_idx + 1, c->sb.nr_devices);
1418 u64s = (sizeof(struct bch_sb_field_members) +
1419 sizeof(struct bch_member) * nr_devices) / sizeof(u64);
1421 err = "no space in superblock for member info";
1424 mi = bch2_sb_resize_members(&c->disk_sb, u64s);
1430 mi->members[dev_idx] = dev_mi;
1431 mi->members[dev_idx].last_mount = cpu_to_le64(ktime_get_real_seconds());
1432 c->disk_sb.sb->nr_devices = nr_devices;
1434 ca->disk_sb.sb->dev_idx = dev_idx;
1435 bch2_dev_attach(c, ca, dev_idx);
1437 bch2_mark_dev_superblock(c, ca, 0);
1439 bch2_write_super(c);
1440 mutex_unlock(&c->sb_lock);
1442 if (ca->mi.state == BCH_MEMBER_STATE_RW) {
1443 err = __bch2_dev_read_write(c, ca);
1448 mutex_unlock(&c->state_lock);
1452 mutex_unlock(&c->sb_lock);
1453 mutex_unlock(&c->state_lock);
1457 bch2_free_super(&sb);
1458 bch_err(c, "Unable to add device: %s", err);
1461 bch_err(c, "Error going rw after adding device: %s", err);
1465 /* Hot add existing device to running filesystem: */
1466 int bch2_dev_online(struct bch_fs *c, const char *path)
1468 struct bch_opts opts = bch2_opts_empty();
1469 struct bch_sb_handle sb = { NULL };
1470 struct bch_sb_field_members *mi;
1476 mutex_lock(&c->state_lock);
1478 ret = bch2_read_super(path, &opts, &sb);
1480 mutex_unlock(&c->state_lock);
1484 dev_idx = sb.sb->dev_idx;
1486 err = bch2_dev_in_fs(c->disk_sb.sb, sb.sb);
1490 if (bch2_dev_attach_bdev(c, &sb)) {
1491 err = "bch2_dev_attach_bdev() error";
1495 ca = bch_dev_locked(c, dev_idx);
1496 if (ca->mi.state == BCH_MEMBER_STATE_RW) {
1497 err = __bch2_dev_read_write(c, ca);
1502 mutex_lock(&c->sb_lock);
1503 mi = bch2_sb_get_members(c->disk_sb.sb);
1505 mi->members[ca->dev_idx].last_mount =
1506 cpu_to_le64(ktime_get_real_seconds());
1508 bch2_write_super(c);
1509 mutex_unlock(&c->sb_lock);
1511 mutex_unlock(&c->state_lock);
1514 mutex_unlock(&c->state_lock);
1515 bch2_free_super(&sb);
1516 bch_err(c, "error bringing %s online: %s", path, err);
1520 int bch2_dev_offline(struct bch_fs *c, struct bch_dev *ca, int flags)
1522 mutex_lock(&c->state_lock);
1524 if (!bch2_dev_is_online(ca)) {
1525 bch_err(ca, "Already offline");
1526 mutex_unlock(&c->state_lock);
1530 if (!bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_FAILED, flags)) {
1531 bch_err(ca, "Cannot offline required disk");
1532 mutex_unlock(&c->state_lock);
1536 __bch2_dev_offline(c, ca);
1538 mutex_unlock(&c->state_lock);
1542 int bch2_dev_resize(struct bch_fs *c, struct bch_dev *ca, u64 nbuckets)
1544 struct bch_member *mi;
1547 mutex_lock(&c->state_lock);
1549 if (nbuckets < ca->mi.nbuckets) {
1550 bch_err(ca, "Cannot shrink yet");
1555 if (bch2_dev_is_online(ca) &&
1556 get_capacity(ca->disk_sb.bdev->bd_disk) <
1557 ca->mi.bucket_size * nbuckets) {
1558 bch_err(ca, "New size larger than device");
1563 ret = bch2_dev_buckets_resize(c, ca, nbuckets);
1565 bch_err(ca, "Resize error: %i", ret);
1569 mutex_lock(&c->sb_lock);
1570 mi = &bch2_sb_get_members(c->disk_sb.sb)->members[ca->dev_idx];
1571 mi->nbuckets = cpu_to_le64(nbuckets);
1573 bch2_write_super(c);
1574 mutex_unlock(&c->sb_lock);
1576 bch2_recalc_capacity(c);
1578 mutex_unlock(&c->state_lock);
1582 /* return with ref on ca->ref: */
1583 struct bch_dev *bch2_dev_lookup(struct bch_fs *c, const char *path)
1591 ret = lookup_bdev(path, &dev);
1593 return ERR_PTR(ret);
1595 for_each_member_device(ca, c, i)
1596 if (ca->disk_sb.bdev->bd_dev == dev)
1599 ca = ERR_PTR(-ENOENT);
1604 /* Filesystem open: */
1606 struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices,
1607 struct bch_opts opts)
1609 struct bch_sb_handle *sb = NULL;
1610 struct bch_fs *c = NULL;
1611 unsigned i, best_sb = 0;
1615 pr_verbose_init(opts, "");
1618 c = ERR_PTR(-EINVAL);
1622 if (!try_module_get(THIS_MODULE)) {
1623 c = ERR_PTR(-ENODEV);
1627 sb = kcalloc(nr_devices, sizeof(*sb), GFP_KERNEL);
1631 for (i = 0; i < nr_devices; i++) {
1632 ret = bch2_read_super(devices[i], &opts, &sb[i]);
1636 err = bch2_sb_validate(&sb[i]);
1641 for (i = 1; i < nr_devices; i++)
1642 if (le64_to_cpu(sb[i].sb->seq) >
1643 le64_to_cpu(sb[best_sb].sb->seq))
1646 for (i = 0; i < nr_devices; i++) {
1647 err = bch2_dev_in_fs(sb[best_sb].sb, sb[i].sb);
1653 c = bch2_fs_alloc(sb[best_sb].sb, opts);
1657 err = "bch2_dev_online() error";
1658 mutex_lock(&c->state_lock);
1659 for (i = 0; i < nr_devices; i++)
1660 if (bch2_dev_attach_bdev(c, &sb[i])) {
1661 mutex_unlock(&c->state_lock);
1664 mutex_unlock(&c->state_lock);
1666 err = "insufficient devices";
1667 if (!bch2_fs_may_start(c))
1670 if (!c->opts.nostart) {
1671 err = bch2_fs_start(c);
1677 module_put(THIS_MODULE);
1679 pr_verbose_init(opts, "ret %i", PTR_ERR_OR_ZERO(c));
1682 pr_err("bch_fs_open err opening %s: %s",
1688 for (i = 0; i < nr_devices; i++)
1689 bch2_free_super(&sb[i]);
1694 static const char *__bch2_fs_open_incremental(struct bch_sb_handle *sb,
1695 struct bch_opts opts)
1699 bool allocated_fs = false;
1701 err = bch2_sb_validate(sb);
1705 mutex_lock(&bch_fs_list_lock);
1706 c = __bch2_uuid_to_fs(sb->sb->uuid);
1708 closure_get(&c->cl);
1710 err = bch2_dev_in_fs(c->disk_sb.sb, sb->sb);
1714 c = bch2_fs_alloc(sb->sb, opts);
1715 err = "cannot allocate memory";
1719 allocated_fs = true;
1722 err = "bch2_dev_online() error";
1724 mutex_lock(&c->sb_lock);
1725 if (bch2_dev_attach_bdev(c, sb)) {
1726 mutex_unlock(&c->sb_lock);
1729 mutex_unlock(&c->sb_lock);
1731 if (!c->opts.nostart && bch2_fs_may_start(c)) {
1732 err = bch2_fs_start(c);
1737 closure_put(&c->cl);
1738 mutex_unlock(&bch_fs_list_lock);
1742 mutex_unlock(&bch_fs_list_lock);
1747 closure_put(&c->cl);
1752 const char *bch2_fs_open_incremental(const char *path)
1754 struct bch_sb_handle sb;
1755 struct bch_opts opts = bch2_opts_empty();
1758 if (bch2_read_super(path, &opts, &sb))
1759 return "error reading superblock";
1761 err = __bch2_fs_open_incremental(&sb, opts);
1762 bch2_free_super(&sb);
1767 /* Global interfaces/init */
1769 static void bcachefs_exit(void)
1773 bch2_chardev_exit();
1775 kset_unregister(bcachefs_kset);
1778 static int __init bcachefs_init(void)
1780 bch2_bkey_pack_test();
1781 bch2_inode_pack_test();
1783 if (!(bcachefs_kset = kset_create_and_add("bcachefs", NULL, fs_kobj)) ||
1784 bch2_chardev_init() ||
1795 #define BCH_DEBUG_PARAM(name, description) \
1797 module_param_named(name, bch2_##name, bool, 0644); \
1798 MODULE_PARM_DESC(name, description);
1800 #undef BCH_DEBUG_PARAM
1802 unsigned bch2_metadata_version = bcachefs_metadata_version_current;
1803 module_param_named(version, bch2_metadata_version, uint, 0400);
1805 module_exit(bcachefs_exit);
1806 module_init(bcachefs_init);