Lines Matching full:c

89 void __bch2_print(struct bch_fs *c, const char *fmt, ...)  in __bch2_print()  argument
91 struct stdio_redirect *stdio = bch2_fs_stdio_redirect(c); in __bch2_print()
166 struct bch_fs *c; in bch2_dev_to_fs() local
171 list_for_each_entry(c, &bch_fs_list, list) in bch2_dev_to_fs()
172 for_each_member_device_rcu(c, ca, NULL) in bch2_dev_to_fs()
174 closure_get(&c->cl); in bch2_dev_to_fs()
177 c = NULL; in bch2_dev_to_fs()
182 return c; in bch2_dev_to_fs()
187 struct bch_fs *c; in __bch2_uuid_to_fs() local
191 list_for_each_entry(c, &bch_fs_list, list) in __bch2_uuid_to_fs()
192 if (!memcmp(&c->disk_sb.sb->uuid, &uuid, sizeof(uuid))) in __bch2_uuid_to_fs()
193 return c; in __bch2_uuid_to_fs()
200 struct bch_fs *c; in bch2_uuid_to_fs() local
203 c = __bch2_uuid_to_fs(uuid); in bch2_uuid_to_fs()
204 if (c) in bch2_uuid_to_fs()
205 closure_get(&c->cl); in bch2_uuid_to_fs()
208 return c; in bch2_uuid_to_fs()
211 static void bch2_dev_usage_journal_reserve(struct bch_fs *c) in bch2_dev_usage_journal_reserve() argument
219 for_each_member_device_rcu(c, ca, NULL) in bch2_dev_usage_journal_reserve()
223 bch2_journal_entry_res_resize(&c->journal, in bch2_dev_usage_journal_reserve()
224 &c->dev_usage_journal_res, u64s * nr); in bch2_dev_usage_journal_reserve()
244 static void __bch2_fs_read_only(struct bch_fs *c) in __bch2_fs_read_only() argument
249 bch2_fs_ec_stop(c); in __bch2_fs_read_only()
250 bch2_open_buckets_stop(c, NULL, true); in __bch2_fs_read_only()
251 bch2_rebalance_stop(c); in __bch2_fs_read_only()
252 bch2_copygc_stop(c); in __bch2_fs_read_only()
253 bch2_gc_thread_stop(c); in __bch2_fs_read_only()
254 bch2_fs_ec_flush(c); in __bch2_fs_read_only()
256 bch_verbose(c, "flushing journal and stopping allocators, journal seq %llu", in __bch2_fs_read_only()
257 journal_cur_seq(&c->journal)); in __bch2_fs_read_only()
262 if (bch2_btree_interior_updates_flush(c) || in __bch2_fs_read_only()
263 bch2_journal_flush_all_pins(&c->journal) || in __bch2_fs_read_only()
264 bch2_btree_flush_all_writes(c) || in __bch2_fs_read_only()
265 seq != atomic64_read(&c->journal.seq)) { in __bch2_fs_read_only()
266 seq = atomic64_read(&c->journal.seq); in __bch2_fs_read_only()
271 bch_verbose(c, "flushing journal and stopping allocators complete, journal seq %llu", in __bch2_fs_read_only()
272 journal_cur_seq(&c->journal)); in __bch2_fs_read_only()
274 if (test_bit(JOURNAL_REPLAY_DONE, &c->journal.flags) && in __bch2_fs_read_only()
275 !test_bit(BCH_FS_emergency_ro, &c->flags)) in __bch2_fs_read_only()
276 set_bit(BCH_FS_clean_shutdown, &c->flags); in __bch2_fs_read_only()
277 bch2_fs_journal_stop(&c->journal); in __bch2_fs_read_only()
282 for_each_member_device(c, ca) in __bch2_fs_read_only()
283 bch2_dev_allocator_remove(c, ca); in __bch2_fs_read_only()
289 struct bch_fs *c = container_of(writes, struct bch_fs, writes); in bch2_writes_disabled() local
291 set_bit(BCH_FS_write_disable_complete, &c->flags); in bch2_writes_disabled()
296 void bch2_fs_read_only(struct bch_fs *c) in bch2_fs_read_only() argument
298 if (!test_bit(BCH_FS_rw, &c->flags)) { in bch2_fs_read_only()
299 bch2_journal_reclaim_stop(&c->journal); in bch2_fs_read_only()
303 BUG_ON(test_bit(BCH_FS_write_disable_complete, &c->flags)); in bch2_fs_read_only()
305 bch_verbose(c, "going read-only"); in bch2_fs_read_only()
311 set_bit(BCH_FS_going_ro, &c->flags); in bch2_fs_read_only()
313 percpu_ref_kill(&c->writes); in bch2_fs_read_only()
316 bch2_write_ref_put(c, i); in bch2_fs_read_only()
331 test_bit(BCH_FS_write_disable_complete, &c->flags) || in bch2_fs_read_only()
332 test_bit(BCH_FS_emergency_ro, &c->flags)); in bch2_fs_read_only()
334 bool writes_disabled = test_bit(BCH_FS_write_disable_complete, &c->flags); in bch2_fs_read_only()
336 bch_verbose(c, "finished waiting for writes to stop"); in bch2_fs_read_only()
338 __bch2_fs_read_only(c); in bch2_fs_read_only()
341 test_bit(BCH_FS_write_disable_complete, &c->flags)); in bch2_fs_read_only()
344 bch_verbose(c, "finished waiting for writes to stop"); in bch2_fs_read_only()
346 clear_bit(BCH_FS_write_disable_complete, &c->flags); in bch2_fs_read_only()
347 clear_bit(BCH_FS_going_ro, &c->flags); in bch2_fs_read_only()
348 clear_bit(BCH_FS_rw, &c->flags); in bch2_fs_read_only()
350 if (!bch2_journal_error(&c->journal) && in bch2_fs_read_only()
351 !test_bit(BCH_FS_error, &c->flags) && in bch2_fs_read_only()
352 !test_bit(BCH_FS_emergency_ro, &c->flags) && in bch2_fs_read_only()
353 test_bit(BCH_FS_started, &c->flags) && in bch2_fs_read_only()
354 test_bit(BCH_FS_clean_shutdown, &c->flags) && in bch2_fs_read_only()
355 !c->opts.norecovery) { in bch2_fs_read_only()
356 BUG_ON(c->journal.last_empty_seq != journal_cur_seq(&c->journal)); in bch2_fs_read_only()
357 BUG_ON(atomic_read(&c->btree_cache.dirty)); in bch2_fs_read_only()
358 BUG_ON(atomic_long_read(&c->btree_key_cache.nr_dirty)); in bch2_fs_read_only()
359 BUG_ON(c->btree_write_buffer.inc.keys.nr); in bch2_fs_read_only()
360 BUG_ON(c->btree_write_buffer.flushing.keys.nr); in bch2_fs_read_only()
362 bch_verbose(c, "marking filesystem clean"); in bch2_fs_read_only()
363 bch2_fs_mark_clean(c); in bch2_fs_read_only()
365 bch_verbose(c, "done going read-only, filesystem not clean"); in bch2_fs_read_only()
371 struct bch_fs *c = in bch2_fs_read_only_work() local
374 down_write(&c->state_lock); in bch2_fs_read_only_work()
375 bch2_fs_read_only(c); in bch2_fs_read_only_work()
376 up_write(&c->state_lock); in bch2_fs_read_only_work()
379 static void bch2_fs_read_only_async(struct bch_fs *c) in bch2_fs_read_only_async() argument
381 queue_work(system_long_wq, &c->read_only_work); in bch2_fs_read_only_async()
384 bool bch2_fs_emergency_read_only(struct bch_fs *c) in bch2_fs_emergency_read_only() argument
386 bool ret = !test_and_set_bit(BCH_FS_emergency_ro, &c->flags); in bch2_fs_emergency_read_only()
388 bch2_journal_halt(&c->journal); in bch2_fs_emergency_read_only()
389 bch2_fs_read_only_async(c); in bch2_fs_emergency_read_only()
395 static int bch2_fs_read_write_late(struct bch_fs *c) in bch2_fs_read_write_late() argument
406 ret = bch2_copygc_start(c); in bch2_fs_read_write_late()
408 bch_err(c, "error starting copygc thread"); in bch2_fs_read_write_late()
412 ret = bch2_rebalance_start(c); in bch2_fs_read_write_late()
414 bch_err(c, "error starting rebalance thread"); in bch2_fs_read_write_late()
421 static int __bch2_fs_read_write(struct bch_fs *c, bool early) in __bch2_fs_read_write() argument
425 if (test_bit(BCH_FS_initial_gc_unfixed, &c->flags)) { in __bch2_fs_read_write()
426 bch_err(c, "cannot go rw, unfixed btree errors"); in __bch2_fs_read_write()
430 if (test_bit(BCH_FS_rw, &c->flags)) in __bch2_fs_read_write()
433 bch_info(c, "going read-write"); in __bch2_fs_read_write()
435 ret = bch2_sb_members_v2_init(c); in __bch2_fs_read_write()
439 ret = bch2_fs_mark_dirty(c); in __bch2_fs_read_write()
443 clear_bit(BCH_FS_clean_shutdown, &c->flags); in __bch2_fs_read_write()
451 set_bit(JOURNAL_NEED_FLUSH_WRITE, &c->journal.flags); in __bch2_fs_read_write()
453 for_each_rw_member(c, ca) in __bch2_fs_read_write()
454 bch2_dev_allocator_add(c, ca); in __bch2_fs_read_write()
455 bch2_recalc_capacity(c); in __bch2_fs_read_write()
457 set_bit(BCH_FS_rw, &c->flags); in __bch2_fs_read_write()
458 set_bit(BCH_FS_was_rw, &c->flags); in __bch2_fs_read_write()
461 percpu_ref_reinit(&c->writes); in __bch2_fs_read_write()
464 BUG_ON(atomic_long_read(&c->writes[i])); in __bch2_fs_read_write()
465 atomic_long_inc(&c->writes[i]); in __bch2_fs_read_write()
469 ret = bch2_gc_thread_start(c); in __bch2_fs_read_write()
471 bch_err(c, "error starting gc thread"); in __bch2_fs_read_write()
475 ret = bch2_journal_reclaim_start(&c->journal); in __bch2_fs_read_write()
480 ret = bch2_fs_read_write_late(c); in __bch2_fs_read_write()
485 bch2_do_discards(c); in __bch2_fs_read_write()
486 bch2_do_invalidates(c); in __bch2_fs_read_write()
487 bch2_do_stripe_deletes(c); in __bch2_fs_read_write()
488 bch2_do_pending_node_rewrites(c); in __bch2_fs_read_write()
491 if (test_bit(BCH_FS_rw, &c->flags)) in __bch2_fs_read_write()
492 bch2_fs_read_only(c); in __bch2_fs_read_write()
494 __bch2_fs_read_only(c); in __bch2_fs_read_write()
498 int bch2_fs_read_write(struct bch_fs *c) in bch2_fs_read_write() argument
500 if (c->opts.norecovery) in bch2_fs_read_write()
503 if (c->opts.nochanges) in bch2_fs_read_write()
506 return __bch2_fs_read_write(c, false); in bch2_fs_read_write()
509 int bch2_fs_read_write_early(struct bch_fs *c) in bch2_fs_read_write_early() argument
511 lockdep_assert_held(&c->state_lock); in bch2_fs_read_write_early()
513 return __bch2_fs_read_write(c, true); in bch2_fs_read_write_early()
518 static void __bch2_fs_free(struct bch_fs *c) in __bch2_fs_free() argument
523 bch2_time_stats_exit(&c->times[i]); in __bch2_fs_free()
525 bch2_free_pending_node_rewrites(c); in __bch2_fs_free()
526 bch2_fs_sb_errors_exit(c); in __bch2_fs_free()
527 bch2_fs_counters_exit(c); in __bch2_fs_free()
528 bch2_fs_snapshots_exit(c); in __bch2_fs_free()
529 bch2_fs_quota_exit(c); in __bch2_fs_free()
530 bch2_fs_fs_io_direct_exit(c); in __bch2_fs_free()
531 bch2_fs_fs_io_buffered_exit(c); in __bch2_fs_free()
532 bch2_fs_fsio_exit(c); in __bch2_fs_free()
533 bch2_fs_ec_exit(c); in __bch2_fs_free()
534 bch2_fs_encryption_exit(c); in __bch2_fs_free()
535 bch2_fs_nocow_locking_exit(c); in __bch2_fs_free()
536 bch2_fs_io_write_exit(c); in __bch2_fs_free()
537 bch2_fs_io_read_exit(c); in __bch2_fs_free()
538 bch2_fs_buckets_waiting_for_journal_exit(c); in __bch2_fs_free()
539 bch2_fs_btree_interior_update_exit(c); in __bch2_fs_free()
540 bch2_fs_btree_iter_exit(c); in __bch2_fs_free()
541 bch2_fs_btree_key_cache_exit(&c->btree_key_cache); in __bch2_fs_free()
542 bch2_fs_btree_cache_exit(c); in __bch2_fs_free()
543 bch2_fs_replicas_exit(c); in __bch2_fs_free()
544 bch2_fs_journal_exit(&c->journal); in __bch2_fs_free()
545 bch2_io_clock_exit(&c->io_clock[WRITE]); in __bch2_fs_free()
546 bch2_io_clock_exit(&c->io_clock[READ]); in __bch2_fs_free()
547 bch2_fs_compress_exit(c); in __bch2_fs_free()
548 bch2_journal_keys_put_initial(c); in __bch2_fs_free()
549 BUG_ON(atomic_read(&c->journal_keys.ref)); in __bch2_fs_free()
550 bch2_fs_btree_write_buffer_exit(c); in __bch2_fs_free()
551 percpu_free_rwsem(&c->mark_lock); in __bch2_fs_free()
552 free_percpu(c->online_reserved); in __bch2_fs_free()
554 darray_exit(&c->btree_roots_extra); in __bch2_fs_free()
555 free_percpu(c->pcpu); in __bch2_fs_free()
556 mempool_exit(&c->large_bkey_pool); in __bch2_fs_free()
557 mempool_exit(&c->btree_bounce_pool); in __bch2_fs_free()
558 bioset_exit(&c->btree_bio); in __bch2_fs_free()
559 mempool_exit(&c->fill_iter); in __bch2_fs_free()
561 percpu_ref_exit(&c->writes); in __bch2_fs_free()
563 kfree(rcu_dereference_protected(c->disk_groups, 1)); in __bch2_fs_free()
564 kfree(c->journal_seq_blacklist_table); in __bch2_fs_free()
565 kfree(c->unused_inode_hints); in __bch2_fs_free()
567 if (c->write_ref_wq) in __bch2_fs_free()
568 destroy_workqueue(c->write_ref_wq); in __bch2_fs_free()
569 if (c->io_complete_wq) in __bch2_fs_free()
570 destroy_workqueue(c->io_complete_wq); in __bch2_fs_free()
571 if (c->copygc_wq) in __bch2_fs_free()
572 destroy_workqueue(c->copygc_wq); in __bch2_fs_free()
573 if (c->btree_io_complete_wq) in __bch2_fs_free()
574 destroy_workqueue(c->btree_io_complete_wq); in __bch2_fs_free()
575 if (c->btree_update_wq) in __bch2_fs_free()
576 destroy_workqueue(c->btree_update_wq); in __bch2_fs_free()
578 bch2_free_super(&c->disk_sb); in __bch2_fs_free()
579 kvpfree(c, sizeof(*c)); in __bch2_fs_free()
585 struct bch_fs *c = container_of(kobj, struct bch_fs, kobj); in bch2_fs_release() local
587 __bch2_fs_free(c); in bch2_fs_release()
590 void __bch2_fs_stop(struct bch_fs *c) in __bch2_fs_stop() argument
592 bch_verbose(c, "shutting down"); in __bch2_fs_stop()
594 set_bit(BCH_FS_stopping, &c->flags); in __bch2_fs_stop()
596 cancel_work_sync(&c->journal_seq_blacklist_gc_work); in __bch2_fs_stop()
598 down_write(&c->state_lock); in __bch2_fs_stop()
599 bch2_fs_read_only(c); in __bch2_fs_stop()
600 up_write(&c->state_lock); in __bch2_fs_stop()
602 for_each_member_device(c, ca) in __bch2_fs_stop()
607 if (c->kobj.state_in_sysfs) in __bch2_fs_stop()
608 kobject_del(&c->kobj); in __bch2_fs_stop()
610 bch2_fs_debug_exit(c); in __bch2_fs_stop()
611 bch2_fs_chardev_exit(c); in __bch2_fs_stop()
613 bch2_ro_ref_put(c); in __bch2_fs_stop()
614 wait_event(c->ro_ref_wait, !refcount_read(&c->ro_ref)); in __bch2_fs_stop()
616 kobject_put(&c->counters_kobj); in __bch2_fs_stop()
617 kobject_put(&c->time_stats); in __bch2_fs_stop()
618 kobject_put(&c->opts_dir); in __bch2_fs_stop()
619 kobject_put(&c->internal); in __bch2_fs_stop()
622 bch2_btree_flush_all_reads(c); in __bch2_fs_stop()
624 for_each_member_device(c, ca) in __bch2_fs_stop()
627 cancel_work_sync(&c->read_only_work); in __bch2_fs_stop()
630 void bch2_fs_free(struct bch_fs *c) in bch2_fs_free() argument
635 list_del(&c->list); in bch2_fs_free()
638 closure_sync(&c->cl); in bch2_fs_free()
639 closure_debug_destroy(&c->cl); in bch2_fs_free()
641 for (i = 0; i < c->sb.nr_devices; i++) { in bch2_fs_free()
642 struct bch_dev *ca = rcu_dereference_protected(c->devs[i], true); in bch2_fs_free()
650 bch_verbose(c, "shutdown complete"); in bch2_fs_free()
652 kobject_put(&c->kobj); in bch2_fs_free()
655 void bch2_fs_stop(struct bch_fs *c) in bch2_fs_stop() argument
657 __bch2_fs_stop(c); in bch2_fs_stop()
658 bch2_fs_free(c); in bch2_fs_stop()
661 static int bch2_fs_online(struct bch_fs *c) in bch2_fs_online() argument
667 if (__bch2_uuid_to_fs(c->sb.uuid)) { in bch2_fs_online()
668 bch_err(c, "filesystem UUID already open"); in bch2_fs_online()
672 ret = bch2_fs_chardev_init(c); in bch2_fs_online()
674 bch_err(c, "error creating character device"); in bch2_fs_online()
678 bch2_fs_debug_init(c); in bch2_fs_online()
680 ret = kobject_add(&c->kobj, NULL, "%pU", c->sb.user_uuid.b) ?: in bch2_fs_online()
681 kobject_add(&c->internal, &c->kobj, "internal") ?: in bch2_fs_online()
682 kobject_add(&c->opts_dir, &c->kobj, "options") ?: in bch2_fs_online()
684 kobject_add(&c->time_stats, &c->kobj, "time_stats") ?: in bch2_fs_online()
686 kobject_add(&c->counters_kobj, &c->kobj, "counters") ?: in bch2_fs_online()
687 bch2_opts_create_sysfs_files(&c->opts_dir); in bch2_fs_online()
689 bch_err(c, "error creating sysfs objects"); in bch2_fs_online()
693 down_write(&c->state_lock); in bch2_fs_online()
695 for_each_member_device(c, ca) { in bch2_fs_online()
696 ret = bch2_dev_sysfs_online(c, ca); in bch2_fs_online()
698 bch_err(c, "error creating sysfs objects"); in bch2_fs_online()
704 BUG_ON(!list_empty(&c->list)); in bch2_fs_online()
705 list_add(&c->list, &bch_fs_list); in bch2_fs_online()
707 up_write(&c->state_lock); in bch2_fs_online()
713 struct bch_fs *c; in bch2_fs_alloc() local
718 c = kvpmalloc(sizeof(struct bch_fs), GFP_KERNEL|__GFP_ZERO); in bch2_fs_alloc()
719 if (!c) { in bch2_fs_alloc()
720 c = ERR_PTR(-BCH_ERR_ENOMEM_fs_alloc); in bch2_fs_alloc()
724 c->stdio = (void *)(unsigned long) opts.stdio; in bch2_fs_alloc()
728 closure_init(&c->cl, NULL); in bch2_fs_alloc()
730 c->kobj.kset = bcachefs_kset; in bch2_fs_alloc()
731 kobject_init(&c->kobj, &bch2_fs_ktype); in bch2_fs_alloc()
732 kobject_init(&c->internal, &bch2_fs_internal_ktype); in bch2_fs_alloc()
733 kobject_init(&c->opts_dir, &bch2_fs_opts_dir_ktype); in bch2_fs_alloc()
734 kobject_init(&c->time_stats, &bch2_fs_time_stats_ktype); in bch2_fs_alloc()
735 kobject_init(&c->counters_kobj, &bch2_fs_counters_ktype); in bch2_fs_alloc()
737 c->minor = -1; in bch2_fs_alloc()
738 c->disk_sb.fs_sb = true; in bch2_fs_alloc()
740 init_rwsem(&c->state_lock); in bch2_fs_alloc()
741 mutex_init(&c->sb_lock); in bch2_fs_alloc()
742 mutex_init(&c->replicas_gc_lock); in bch2_fs_alloc()
743 mutex_init(&c->btree_root_lock); in bch2_fs_alloc()
744 INIT_WORK(&c->read_only_work, bch2_fs_read_only_work); in bch2_fs_alloc()
746 refcount_set(&c->ro_ref, 1); in bch2_fs_alloc()
747 init_waitqueue_head(&c->ro_ref_wait); in bch2_fs_alloc()
748 sema_init(&c->online_fsck_mutex, 1); in bch2_fs_alloc()
750 init_rwsem(&c->gc_lock); in bch2_fs_alloc()
751 mutex_init(&c->gc_gens_lock); in bch2_fs_alloc()
752 atomic_set(&c->journal_keys.ref, 1); in bch2_fs_alloc()
753 c->journal_keys.initial_ref_held = true; in bch2_fs_alloc()
756 bch2_time_stats_init(&c->times[i]); in bch2_fs_alloc()
758 bch2_fs_copygc_init(c); in bch2_fs_alloc()
759 bch2_fs_btree_key_cache_init_early(&c->btree_key_cache); in bch2_fs_alloc()
760 bch2_fs_btree_iter_init_early(c); in bch2_fs_alloc()
761 bch2_fs_btree_interior_update_init_early(c); in bch2_fs_alloc()
762 bch2_fs_allocator_background_init(c); in bch2_fs_alloc()
763 bch2_fs_allocator_foreground_init(c); in bch2_fs_alloc()
764 bch2_fs_rebalance_init(c); in bch2_fs_alloc()
765 bch2_fs_quota_init(c); in bch2_fs_alloc()
766 bch2_fs_ec_init_early(c); in bch2_fs_alloc()
767 bch2_fs_move_init(c); in bch2_fs_alloc()
768 bch2_fs_sb_errors_init_early(c); in bch2_fs_alloc()
770 INIT_LIST_HEAD(&c->list); in bch2_fs_alloc()
772 mutex_init(&c->usage_scratch_lock); in bch2_fs_alloc()
774 mutex_init(&c->bio_bounce_pages_lock); in bch2_fs_alloc()
775 mutex_init(&c->snapshot_table_lock); in bch2_fs_alloc()
776 init_rwsem(&c->snapshot_create_lock); in bch2_fs_alloc()
778 spin_lock_init(&c->btree_write_error_lock); in bch2_fs_alloc()
780 INIT_WORK(&c->journal_seq_blacklist_gc_work, in bch2_fs_alloc()
783 INIT_LIST_HEAD(&c->journal_iters); in bch2_fs_alloc()
785 INIT_LIST_HEAD(&c->fsck_error_msgs); in bch2_fs_alloc()
786 mutex_init(&c->fsck_error_msgs_lock); in bch2_fs_alloc()
788 seqcount_init(&c->gc_pos_lock); in bch2_fs_alloc()
790 seqcount_init(&c->usage_lock); in bch2_fs_alloc()
792 sema_init(&c->io_in_flight, 128); in bch2_fs_alloc()
794 INIT_LIST_HEAD(&c->vfs_inodes_list); in bch2_fs_alloc()
795 mutex_init(&c->vfs_inodes_lock); in bch2_fs_alloc()
797 c->copy_gc_enabled = 1; in bch2_fs_alloc()
798 c->rebalance.enabled = 1; in bch2_fs_alloc()
799 c->promote_whole_extents = true; in bch2_fs_alloc()
801 c->journal.flush_write_time = &c->times[BCH_TIME_journal_flush_write]; in bch2_fs_alloc()
802 c->journal.noflush_write_time = &c->times[BCH_TIME_journal_noflush_write]; in bch2_fs_alloc()
803 c->journal.flush_seq_time = &c->times[BCH_TIME_journal_flush_seq]; in bch2_fs_alloc()
805 bch2_fs_btree_cache_init_early(&c->btree_cache); in bch2_fs_alloc()
807 mutex_init(&c->sectors_available_lock); in bch2_fs_alloc()
809 ret = percpu_init_rwsem(&c->mark_lock); in bch2_fs_alloc()
813 mutex_lock(&c->sb_lock); in bch2_fs_alloc()
814 ret = bch2_sb_to_fs(c, sb); in bch2_fs_alloc()
815 mutex_unlock(&c->sb_lock); in bch2_fs_alloc()
820 pr_uuid(&name, c->sb.user_uuid.b); in bch2_fs_alloc()
821 strscpy(c->name, name.buf, sizeof(c->name)); in bch2_fs_alloc()
837 c->opts = bch2_opts_default; in bch2_fs_alloc()
838 ret = bch2_opts_from_sb(&c->opts, sb); in bch2_fs_alloc()
842 bch2_opts_apply(&c->opts, opts); in bch2_fs_alloc()
844 c->btree_key_cache_btrees |= 1U << BTREE_ID_alloc; in bch2_fs_alloc()
845 if (c->opts.inodes_use_key_cache) in bch2_fs_alloc()
846 c->btree_key_cache_btrees |= 1U << BTREE_ID_inodes; in bch2_fs_alloc()
847 c->btree_key_cache_btrees |= 1U << BTREE_ID_logged_ops; in bch2_fs_alloc()
849 c->block_bits = ilog2(block_sectors(c)); in bch2_fs_alloc()
850 c->btree_foreground_merge_threshold = BTREE_FOREGROUND_MERGE_THRESHOLD(c); in bch2_fs_alloc()
853 bch_err(c, "fs_alloc fault injected"); in bch2_fs_alloc()
859 (btree_blocks(c) + 1) * 2 * in bch2_fs_alloc()
862 c->inode_shard_bits = ilog2(roundup_pow_of_two(num_possible_cpus())); in bch2_fs_alloc()
864 if (!(c->btree_update_wq = alloc_workqueue("bcachefs", in bch2_fs_alloc()
866 !(c->btree_io_complete_wq = alloc_workqueue("bcachefs_btree_io", in bch2_fs_alloc()
868 !(c->copygc_wq = alloc_workqueue("bcachefs_copygc", in bch2_fs_alloc()
870 !(c->io_complete_wq = alloc_workqueue("bcachefs_io", in bch2_fs_alloc()
872 !(c->write_ref_wq = alloc_workqueue("bcachefs_write_ref", in bch2_fs_alloc()
875 percpu_ref_init(&c->writes, bch2_writes_disabled, in bch2_fs_alloc()
878 mempool_init_kmalloc_pool(&c->fill_iter, 1, iter_size) || in bch2_fs_alloc()
879 bioset_init(&c->btree_bio, 1, in bch2_fs_alloc()
883 !(c->pcpu = alloc_percpu(struct bch_fs_pcpu)) || in bch2_fs_alloc()
884 !(c->online_reserved = alloc_percpu(u64)) || in bch2_fs_alloc()
885 mempool_init_kvpmalloc_pool(&c->btree_bounce_pool, 1, in bch2_fs_alloc()
886 c->opts.btree_node_size) || in bch2_fs_alloc()
887 mempool_init_kmalloc_pool(&c->large_bkey_pool, 1, 2048) || in bch2_fs_alloc()
888 !(c->unused_inode_hints = kcalloc(1U << c->inode_shard_bits, in bch2_fs_alloc()
894 ret = bch2_fs_counters_init(c) ?: in bch2_fs_alloc()
895 bch2_fs_sb_errors_init(c) ?: in bch2_fs_alloc()
896 bch2_io_clock_init(&c->io_clock[READ]) ?: in bch2_fs_alloc()
897 bch2_io_clock_init(&c->io_clock[WRITE]) ?: in bch2_fs_alloc()
898 bch2_fs_journal_init(&c->journal) ?: in bch2_fs_alloc()
899 bch2_fs_replicas_init(c) ?: in bch2_fs_alloc()
900 bch2_fs_btree_cache_init(c) ?: in bch2_fs_alloc()
901 bch2_fs_btree_key_cache_init(&c->btree_key_cache) ?: in bch2_fs_alloc()
902 bch2_fs_btree_iter_init(c) ?: in bch2_fs_alloc()
903 bch2_fs_btree_interior_update_init(c) ?: in bch2_fs_alloc()
904 bch2_fs_buckets_waiting_for_journal_init(c) ?: in bch2_fs_alloc()
905 bch2_fs_btree_write_buffer_init(c) ?: in bch2_fs_alloc()
906 bch2_fs_subvolumes_init(c) ?: in bch2_fs_alloc()
907 bch2_fs_io_read_init(c) ?: in bch2_fs_alloc()
908 bch2_fs_io_write_init(c) ?: in bch2_fs_alloc()
909 bch2_fs_nocow_locking_init(c) ?: in bch2_fs_alloc()
910 bch2_fs_encryption_init(c) ?: in bch2_fs_alloc()
911 bch2_fs_compress_init(c) ?: in bch2_fs_alloc()
912 bch2_fs_ec_init(c) ?: in bch2_fs_alloc()
913 bch2_fs_fsio_init(c) ?: in bch2_fs_alloc()
914 bch2_fs_fs_io_buffered_init(c) ?: in bch2_fs_alloc()
915 bch2_fs_fs_io_direct_init(c); in bch2_fs_alloc()
919 for (i = 0; i < c->sb.nr_devices; i++) in bch2_fs_alloc()
920 if (bch2_dev_exists(c->disk_sb.sb, i) && in bch2_fs_alloc()
921 bch2_dev_alloc(c, i)) { in bch2_fs_alloc()
926 bch2_journal_entry_res_resize(&c->journal, in bch2_fs_alloc()
927 &c->btree_root_journal_res, in bch2_fs_alloc()
929 bch2_dev_usage_journal_reserve(c); in bch2_fs_alloc()
930 bch2_journal_entry_res_resize(&c->journal, in bch2_fs_alloc()
931 &c->clock_journal_res, in bch2_fs_alloc()
935 ret = bch2_fs_online(c); in bch2_fs_alloc()
941 return c; in bch2_fs_alloc()
943 bch2_fs_free(c); in bch2_fs_alloc()
944 c = ERR_PTR(ret); in bch2_fs_alloc()
949 static void print_mount_opts(struct bch_fs *c) in print_mount_opts() argument
956 bch2_version_to_text(&p, c->sb.version); in print_mount_opts()
958 if (c->opts.read_only) { in print_mount_opts()
966 u64 v = bch2_opt_get_by_id(&c->opts, i); in print_mount_opts()
976 bch2_opt_to_text(&p, c, c->disk_sb.sb, opt, v, OPT_SHOW_MOUNT_STYLE); in print_mount_opts()
979 bch_info(c, "%s", p.buf); in print_mount_opts()
983 int bch2_fs_start(struct bch_fs *c) in bch2_fs_start() argument
988 print_mount_opts(c); in bch2_fs_start()
990 down_write(&c->state_lock); in bch2_fs_start()
992 BUG_ON(test_bit(BCH_FS_started, &c->flags)); in bch2_fs_start()
994 mutex_lock(&c->sb_lock); in bch2_fs_start()
996 ret = bch2_sb_members_v2_init(c); in bch2_fs_start()
998 mutex_unlock(&c->sb_lock); in bch2_fs_start()
1002 for_each_online_member(c, ca) in bch2_fs_start()
1003 bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx)->last_mount = cpu_to_le64(now); in bch2_fs_start()
1005 mutex_unlock(&c->sb_lock); in bch2_fs_start()
1007 for_each_rw_member(c, ca) in bch2_fs_start()
1008 bch2_dev_allocator_add(c, ca); in bch2_fs_start()
1009 bch2_recalc_capacity(c); in bch2_fs_start()
1011 ret = BCH_SB_INITIALIZED(c->disk_sb.sb) in bch2_fs_start()
1012 ? bch2_fs_recovery(c) in bch2_fs_start()
1013 : bch2_fs_initialize(c); in bch2_fs_start()
1017 ret = bch2_opts_check_may_set(c); in bch2_fs_start()
1022 bch_err(c, "fs_start fault injected"); in bch2_fs_start()
1027 set_bit(BCH_FS_started, &c->flags); in bch2_fs_start()
1029 if (c->opts.read_only) { in bch2_fs_start()
1030 bch2_fs_read_only(c); in bch2_fs_start()
1032 ret = !test_bit(BCH_FS_rw, &c->flags) in bch2_fs_start()
1033 ? bch2_fs_read_write(c) in bch2_fs_start()
1034 : bch2_fs_read_write_late(c); in bch2_fs_start()
1042 bch_err_msg(c, ret, "starting filesystem"); in bch2_fs_start()
1044 bch_verbose(c, "done starting filesystem"); in bch2_fs_start()
1045 up_write(&c->state_lock); in bch2_fs_start()
1049 static int bch2_dev_may_add(struct bch_sb *sb, struct bch_fs *c) in bch2_dev_may_add() argument
1053 if (le16_to_cpu(sb->block_size) != block_sectors(c)) in bch2_dev_may_add()
1057 BCH_SB_BTREE_NODE_SIZE(c->disk_sb.sb)) in bch2_dev_may_add()
1179 static void __bch2_dev_offline(struct bch_fs *c, struct bch_dev *ca) in __bch2_dev_offline() argument
1182 lockdep_assert_held(&c->state_lock); in __bch2_dev_offline()
1187 __bch2_dev_read_only(c, ca); in __bch2_dev_offline()
1216 static int bch2_dev_sysfs_online(struct bch_fs *c, struct bch_dev *ca) in bch2_dev_sysfs_online() argument
1220 if (!c->kobj.state_in_sysfs) in bch2_dev_sysfs_online()
1224 ret = kobject_add(&ca->kobj, &c->kobj, in bch2_dev_sysfs_online()
1245 static struct bch_dev *__bch2_dev_alloc(struct bch_fs *c, in __bch2_dev_alloc() argument
1274 ca->mi.bucket_size / btree_sectors(c)); in __bch2_dev_alloc()
1281 bch2_dev_buckets_alloc(c, ca) || in __bch2_dev_alloc()
1293 static void bch2_dev_attach(struct bch_fs *c, struct bch_dev *ca, in bch2_dev_attach() argument
1300 ca->fs = c; in bch2_dev_attach()
1301 rcu_assign_pointer(c->devs[ca->dev_idx], ca); in bch2_dev_attach()
1303 if (bch2_dev_sysfs_online(c, ca)) in bch2_dev_attach()
1307 static int bch2_dev_alloc(struct bch_fs *c, unsigned dev_idx) in bch2_dev_alloc() argument
1309 struct bch_member member = bch2_sb_member_get(c->disk_sb.sb, dev_idx); in bch2_dev_alloc()
1316 ca = __bch2_dev_alloc(c, &member); in bch2_dev_alloc()
1320 ca->fs = c; in bch2_dev_alloc()
1322 bch2_dev_attach(c, ca, dev_idx); in bch2_dev_alloc()
1363 static int bch2_dev_attach_bdev(struct bch_fs *c, struct bch_sb_handle *sb) in bch2_dev_attach_bdev() argument
1368 lockdep_assert_held(&c->state_lock); in bch2_dev_attach_bdev()
1371 le64_to_cpu(c->disk_sb.sb->seq)) in bch2_dev_attach_bdev()
1372 bch2_sb_to_fs(c, sb->sb); in bch2_dev_attach_bdev()
1374 BUG_ON(sb->sb->dev_idx >= c->sb.nr_devices || in bch2_dev_attach_bdev()
1375 !c->devs[sb->sb->dev_idx]); in bch2_dev_attach_bdev()
1377 ca = bch_dev_locked(c, sb->sb->dev_idx); in bch2_dev_attach_bdev()
1383 bch2_dev_sysfs_online(c, ca); in bch2_dev_attach_bdev()
1388 if (c->sb.nr_devices == 1) in bch2_dev_attach_bdev()
1389 strscpy(c->name, name.buf, sizeof(c->name)); in bch2_dev_attach_bdev()
1394 rebalance_wakeup(c); in bch2_dev_attach_bdev()
1409 bool bch2_dev_state_allowed(struct bch_fs *c, struct bch_dev *ca, in bch2_dev_state_allowed() argument
1415 lockdep_assert_held(&c->state_lock); in bch2_dev_state_allowed()
1425 for_each_member_device(c, ca2) in bch2_dev_state_allowed()
1430 ? c->opts.metadata_replicas in bch2_dev_state_allowed()
1431 : metadata_replicas_required(c), in bch2_dev_state_allowed()
1433 ? c->opts.data_replicas in bch2_dev_state_allowed()
1434 : data_replicas_required(c)); in bch2_dev_state_allowed()
1444 new_online_devs = bch2_online_devs(c); in bch2_dev_state_allowed()
1447 return bch2_have_enough_devs(c, new_online_devs, flags, false); in bch2_dev_state_allowed()
1453 static bool bch2_fs_may_start(struct bch_fs *c) in bch2_fs_may_start() argument
1458 if (c->opts.very_degraded) in bch2_fs_may_start()
1461 if (c->opts.degraded) in bch2_fs_may_start()
1464 if (!c->opts.degraded && in bch2_fs_may_start()
1465 !c->opts.very_degraded) { in bch2_fs_may_start()
1466 mutex_lock(&c->sb_lock); in bch2_fs_may_start()
1468 for (i = 0; i < c->disk_sb.sb->nr_devices; i++) { in bch2_fs_may_start()
1469 if (!bch2_dev_exists(c->disk_sb.sb, i)) in bch2_fs_may_start()
1472 ca = bch_dev_locked(c, i); in bch2_fs_may_start()
1477 mutex_unlock(&c->sb_lock); in bch2_fs_may_start()
1481 mutex_unlock(&c->sb_lock); in bch2_fs_may_start()
1484 return bch2_have_enough_devs(c, bch2_online_devs(c), flags, true); in bch2_fs_may_start()
1487 static void __bch2_dev_read_only(struct bch_fs *c, struct bch_dev *ca) in __bch2_dev_read_only() argument
1492 bch2_dev_allocator_remove(c, ca); in __bch2_dev_read_only()
1493 bch2_dev_journal_stop(&c->journal, ca); in __bch2_dev_read_only()
1496 static void __bch2_dev_read_write(struct bch_fs *c, struct bch_dev *ca) in __bch2_dev_read_write() argument
1498 lockdep_assert_held(&c->state_lock); in __bch2_dev_read_write()
1502 bch2_dev_allocator_add(c, ca); in __bch2_dev_read_write()
1503 bch2_recalc_capacity(c); in __bch2_dev_read_write()
1506 int __bch2_dev_set_state(struct bch_fs *c, struct bch_dev *ca, in __bch2_dev_set_state() argument
1515 if (!bch2_dev_state_allowed(c, ca, new_state, flags)) in __bch2_dev_set_state()
1519 __bch2_dev_read_only(c, ca); in __bch2_dev_set_state()
1523 mutex_lock(&c->sb_lock); in __bch2_dev_set_state()
1524 m = bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx); in __bch2_dev_set_state()
1526 bch2_write_super(c); in __bch2_dev_set_state()
1527 mutex_unlock(&c->sb_lock); in __bch2_dev_set_state()
1530 __bch2_dev_read_write(c, ca); in __bch2_dev_set_state()
1532 rebalance_wakeup(c); in __bch2_dev_set_state()
1537 int bch2_dev_set_state(struct bch_fs *c, struct bch_dev *ca, in bch2_dev_set_state() argument
1542 down_write(&c->state_lock); in bch2_dev_set_state()
1543 ret = __bch2_dev_set_state(c, ca, new_state, flags); in bch2_dev_set_state()
1544 up_write(&c->state_lock); in bch2_dev_set_state()
1551 static int bch2_dev_remove_alloc(struct bch_fs *c, struct bch_dev *ca) in bch2_dev_remove_alloc() argument
1561 ret = bch2_btree_delete_range(c, BTREE_ID_lru, start, end, in bch2_dev_remove_alloc()
1563 bch2_btree_delete_range(c, BTREE_ID_need_discard, start, end, in bch2_dev_remove_alloc()
1565 bch2_btree_delete_range(c, BTREE_ID_freespace, start, end, in bch2_dev_remove_alloc()
1567 bch2_btree_delete_range(c, BTREE_ID_backpointers, start, end, in bch2_dev_remove_alloc()
1569 bch2_btree_delete_range(c, BTREE_ID_alloc, start, end, in bch2_dev_remove_alloc()
1571 bch2_btree_delete_range(c, BTREE_ID_bucket_gens, start, end, in bch2_dev_remove_alloc()
1573 bch_err_msg(c, ret, "removing dev alloc info"); in bch2_dev_remove_alloc()
1577 int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags) in bch2_dev_remove() argument
1583 down_write(&c->state_lock); in bch2_dev_remove()
1591 if (!bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_failed, flags)) { in bch2_dev_remove()
1597 __bch2_dev_read_only(c, ca); in bch2_dev_remove()
1599 ret = bch2_dev_data_drop(c, ca->dev_idx, flags); in bch2_dev_remove()
1604 ret = bch2_dev_remove_alloc(c, ca); in bch2_dev_remove()
1609 ret = bch2_journal_flush_device_pins(&c->journal, ca->dev_idx); in bch2_dev_remove()
1614 ret = bch2_journal_flush(&c->journal); in bch2_dev_remove()
1619 ret = bch2_replicas_gc2(c); in bch2_dev_remove()
1624 data = bch2_dev_has_data(c, ca); in bch2_dev_remove()
1635 __bch2_dev_offline(c, ca); in bch2_dev_remove()
1637 mutex_lock(&c->sb_lock); in bch2_dev_remove()
1638 rcu_assign_pointer(c->devs[ca->dev_idx], NULL); in bch2_dev_remove()
1639 mutex_unlock(&c->sb_lock); in bch2_dev_remove()
1655 bch2_journal_flush_all_pins(&c->journal); in bch2_dev_remove()
1661 mutex_lock(&c->sb_lock); in bch2_dev_remove()
1662 m = bch2_members_v2_get_mut(c->disk_sb.sb, dev_idx); in bch2_dev_remove()
1665 bch2_write_super(c); in bch2_dev_remove()
1667 mutex_unlock(&c->sb_lock); in bch2_dev_remove()
1668 up_write(&c->state_lock); in bch2_dev_remove()
1670 bch2_dev_usage_journal_reserve(c); in bch2_dev_remove()
1675 __bch2_dev_read_write(c, ca); in bch2_dev_remove()
1676 up_write(&c->state_lock); in bch2_dev_remove()
1681 int bch2_dev_add(struct bch_fs *c, const char *path) in bch2_dev_add() argument
1694 bch_err_msg(c, ret, "reading super"); in bch2_dev_add()
1708 ret = bch2_dev_may_add(sb.sb, c); in bch2_dev_add()
1712 ca = __bch2_dev_alloc(c, &dev_mi); in bch2_dev_add()
1725 bch_err_msg(c, ret, "allocating journal"); in bch2_dev_add()
1729 down_write(&c->state_lock); in bch2_dev_add()
1730 mutex_lock(&c->sb_lock); in bch2_dev_add()
1732 ret = bch2_sb_from_fs(c, ca); in bch2_dev_add()
1733 bch_err_msg(c, ret, "setting up new superblock"); in bch2_dev_add()
1741 if (!bch2_dev_exists(c->disk_sb.sb, dev_idx)) in bch2_dev_add()
1745 bch_err_msg(c, ret, "setting up new superblock"); in bch2_dev_add()
1749 nr_devices = max_t(unsigned, dev_idx + 1, c->sb.nr_devices); in bch2_dev_add()
1751 mi = bch2_sb_field_get(c->disk_sb.sb, members_v2); in bch2_dev_add()
1755 mi = bch2_sb_field_resize(&c->disk_sb, members_v2, u64s); in bch2_dev_add()
1758 bch_err_msg(c, ret, "setting up new superblock"); in bch2_dev_add()
1761 struct bch_member *m = bch2_members_v2_get_mut(c->disk_sb.sb, dev_idx); in bch2_dev_add()
1767 c->disk_sb.sb->nr_devices = nr_devices; in bch2_dev_add()
1770 bch2_dev_attach(c, ca, dev_idx); in bch2_dev_add()
1773 ret = __bch2_dev_group_set(c, ca, label.buf); in bch2_dev_add()
1774 bch_err_msg(c, ret, "creating new label"); in bch2_dev_add()
1779 bch2_write_super(c); in bch2_dev_add()
1780 mutex_unlock(&c->sb_lock); in bch2_dev_add()
1782 bch2_dev_usage_journal_reserve(c); in bch2_dev_add()
1784 ret = bch2_trans_mark_dev_sb(c, ca); in bch2_dev_add()
1789 ret = bch2_fs_freespace_init(c); in bch2_dev_add()
1797 __bch2_dev_read_write(c, ca); in bch2_dev_add()
1799 up_write(&c->state_lock); in bch2_dev_add()
1803 mutex_unlock(&c->sb_lock); in bch2_dev_add()
1804 up_write(&c->state_lock); in bch2_dev_add()
1811 bch_err_fn(c, ret); in bch2_dev_add()
1814 up_write(&c->state_lock); in bch2_dev_add()
1820 int bch2_dev_online(struct bch_fs *c, const char *path) in bch2_dev_online() argument
1828 down_write(&c->state_lock); in bch2_dev_online()
1832 up_write(&c->state_lock); in bch2_dev_online()
1838 ret = bch2_dev_in_fs(&c->disk_sb, &sb); in bch2_dev_online()
1839 bch_err_msg(c, ret, "bringing %s online", path); in bch2_dev_online()
1843 ret = bch2_dev_attach_bdev(c, &sb); in bch2_dev_online()
1847 ca = bch_dev_locked(c, dev_idx); in bch2_dev_online()
1849 ret = bch2_trans_mark_dev_sb(c, ca); in bch2_dev_online()
1850 bch_err_msg(c, ret, "bringing %s online: error from bch2_trans_mark_dev_sb", path); in bch2_dev_online()
1855 __bch2_dev_read_write(c, ca); in bch2_dev_online()
1858 ret = bch2_dev_freespace_init(c, ca, 0, ca->mi.nbuckets); in bch2_dev_online()
1871 mutex_lock(&c->sb_lock); in bch2_dev_online()
1872 bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx)->last_mount = in bch2_dev_online()
1874 bch2_write_super(c); in bch2_dev_online()
1875 mutex_unlock(&c->sb_lock); in bch2_dev_online()
1877 up_write(&c->state_lock); in bch2_dev_online()
1880 up_write(&c->state_lock); in bch2_dev_online()
1885 int bch2_dev_offline(struct bch_fs *c, struct bch_dev *ca, int flags) in bch2_dev_offline() argument
1887 down_write(&c->state_lock); in bch2_dev_offline()
1891 up_write(&c->state_lock); in bch2_dev_offline()
1895 if (!bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_failed, flags)) { in bch2_dev_offline()
1897 up_write(&c->state_lock); in bch2_dev_offline()
1901 __bch2_dev_offline(c, ca); in bch2_dev_offline()
1903 up_write(&c->state_lock); in bch2_dev_offline()
1907 int bch2_dev_resize(struct bch_fs *c, struct bch_dev *ca, u64 nbuckets) in bch2_dev_resize() argument
1913 down_write(&c->state_lock); in bch2_dev_resize()
1930 ret = bch2_dev_buckets_resize(c, ca, nbuckets); in bch2_dev_resize()
1935 ret = bch2_trans_mark_dev_sb(c, ca); in bch2_dev_resize()
1939 mutex_lock(&c->sb_lock); in bch2_dev_resize()
1940 m = bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx); in bch2_dev_resize()
1943 bch2_write_super(c); in bch2_dev_resize()
1944 mutex_unlock(&c->sb_lock); in bch2_dev_resize()
1947 ret = bch2_dev_freespace_init(c, ca, old_nbuckets, nbuckets); in bch2_dev_resize()
1958 bch2_recalc_capacity(c); in bch2_dev_resize()
1960 up_write(&c->state_lock); in bch2_dev_resize()
1965 struct bch_dev *bch2_dev_lookup(struct bch_fs *c, const char *name) in bch2_dev_lookup() argument
1968 for_each_member_device_rcu(c, ca, NULL) in bch2_dev_lookup()
1989 struct bch_fs *c = NULL; in bch2_fs_open() local
2041 c = bch2_fs_alloc(best->sb, opts); in bch2_fs_open()
2042 ret = PTR_ERR_OR_ZERO(c); in bch2_fs_open()
2046 down_write(&c->state_lock); in bch2_fs_open()
2048 ret = bch2_dev_attach_bdev(c, sb); in bch2_fs_open()
2050 up_write(&c->state_lock); in bch2_fs_open()
2054 up_write(&c->state_lock); in bch2_fs_open()
2056 if (!bch2_fs_may_start(c)) { in bch2_fs_open()
2061 if (!c->opts.nostart) { in bch2_fs_open()
2062 ret = bch2_fs_start(c); in bch2_fs_open()
2072 return c; in bch2_fs_open()
2077 if (!IS_ERR_OR_NULL(c)) in bch2_fs_open()
2078 bch2_fs_stop(c); in bch2_fs_open()
2079 c = ERR_PTR(ret); in bch2_fs_open()