Lines Matching full:c
85 void bch2_print_str(struct bch_fs *c, const char *str) in bch2_print_str() argument
88 struct stdio_redirect *stdio = bch2_fs_stdio_redirect(c); in bch2_print_str()
123 void __bch2_print(struct bch_fs *c, const char *fmt, ...) in __bch2_print() argument
125 struct stdio_redirect *stdio = bch2_fs_stdio_redirect(c); in __bch2_print()
189 struct bch_fs *c; in bch2_dev_to_fs() local
194 list_for_each_entry(c, &bch_fs_list, list) in bch2_dev_to_fs()
195 for_each_member_device_rcu(c, ca, NULL) in bch2_dev_to_fs()
197 closure_get(&c->cl); in bch2_dev_to_fs()
200 c = NULL; in bch2_dev_to_fs()
205 return c; in bch2_dev_to_fs()
210 struct bch_fs *c; in __bch2_uuid_to_fs() local
214 list_for_each_entry(c, &bch_fs_list, list) in __bch2_uuid_to_fs()
215 if (!memcmp(&c->disk_sb.sb->uuid, &uuid, sizeof(uuid))) in __bch2_uuid_to_fs()
216 return c; in __bch2_uuid_to_fs()
223 struct bch_fs *c; in bch2_uuid_to_fs() local
226 c = __bch2_uuid_to_fs(uuid); in bch2_uuid_to_fs()
227 if (c) in bch2_uuid_to_fs()
228 closure_get(&c->cl); in bch2_uuid_to_fs()
231 return c; in bch2_uuid_to_fs()
251 static void __bch2_fs_read_only(struct bch_fs *c) in __bch2_fs_read_only() argument
256 bch2_fs_ec_stop(c); in __bch2_fs_read_only()
257 bch2_open_buckets_stop(c, NULL, true); in __bch2_fs_read_only()
258 bch2_rebalance_stop(c); in __bch2_fs_read_only()
259 bch2_copygc_stop(c); in __bch2_fs_read_only()
260 bch2_fs_ec_flush(c); in __bch2_fs_read_only()
262 bch_verbose(c, "flushing journal and stopping allocators, journal seq %llu", in __bch2_fs_read_only()
263 journal_cur_seq(&c->journal)); in __bch2_fs_read_only()
268 if (bch2_btree_interior_updates_flush(c) || in __bch2_fs_read_only()
269 bch2_btree_write_buffer_flush_going_ro(c) || in __bch2_fs_read_only()
270 bch2_journal_flush_all_pins(&c->journal) || in __bch2_fs_read_only()
271 bch2_btree_flush_all_writes(c) || in __bch2_fs_read_only()
272 seq != atomic64_read(&c->journal.seq)) { in __bch2_fs_read_only()
273 seq = atomic64_read(&c->journal.seq); in __bch2_fs_read_only()
278 bch_verbose(c, "flushing journal and stopping allocators complete, journal seq %llu", in __bch2_fs_read_only()
279 journal_cur_seq(&c->journal)); in __bch2_fs_read_only()
281 if (test_bit(JOURNAL_replay_done, &c->journal.flags) && in __bch2_fs_read_only()
282 !test_bit(BCH_FS_emergency_ro, &c->flags)) in __bch2_fs_read_only()
283 set_bit(BCH_FS_clean_shutdown, &c->flags); in __bch2_fs_read_only()
285 bch2_fs_journal_stop(&c->journal); in __bch2_fs_read_only()
287 bch_info(c, "%sclean shutdown complete, journal seq %llu", in __bch2_fs_read_only()
288 test_bit(BCH_FS_clean_shutdown, &c->flags) ? "" : "un", in __bch2_fs_read_only()
289 c->journal.seq_ondisk); in __bch2_fs_read_only()
294 for_each_member_device(c, ca) { in __bch2_fs_read_only()
296 bch2_dev_allocator_remove(c, ca); in __bch2_fs_read_only()
303 struct bch_fs *c = container_of(writes, struct bch_fs, writes); in bch2_writes_disabled() local
305 set_bit(BCH_FS_write_disable_complete, &c->flags); in bch2_writes_disabled()
310 void bch2_fs_read_only(struct bch_fs *c) in bch2_fs_read_only() argument
312 if (!test_bit(BCH_FS_rw, &c->flags)) { in bch2_fs_read_only()
313 bch2_journal_reclaim_stop(&c->journal); in bch2_fs_read_only()
317 BUG_ON(test_bit(BCH_FS_write_disable_complete, &c->flags)); in bch2_fs_read_only()
319 bch_verbose(c, "going read-only"); in bch2_fs_read_only()
325 set_bit(BCH_FS_going_ro, &c->flags); in bch2_fs_read_only()
327 percpu_ref_kill(&c->writes); in bch2_fs_read_only()
330 bch2_write_ref_put(c, i); in bch2_fs_read_only()
345 test_bit(BCH_FS_write_disable_complete, &c->flags) || in bch2_fs_read_only()
346 test_bit(BCH_FS_emergency_ro, &c->flags)); in bch2_fs_read_only()
348 bool writes_disabled = test_bit(BCH_FS_write_disable_complete, &c->flags); in bch2_fs_read_only()
350 bch_verbose(c, "finished waiting for writes to stop"); in bch2_fs_read_only()
352 __bch2_fs_read_only(c); in bch2_fs_read_only()
355 test_bit(BCH_FS_write_disable_complete, &c->flags)); in bch2_fs_read_only()
358 bch_verbose(c, "finished waiting for writes to stop"); in bch2_fs_read_only()
360 clear_bit(BCH_FS_write_disable_complete, &c->flags); in bch2_fs_read_only()
361 clear_bit(BCH_FS_going_ro, &c->flags); in bch2_fs_read_only()
362 clear_bit(BCH_FS_rw, &c->flags); in bch2_fs_read_only()
364 if (!bch2_journal_error(&c->journal) && in bch2_fs_read_only()
365 !test_bit(BCH_FS_error, &c->flags) && in bch2_fs_read_only()
366 !test_bit(BCH_FS_emergency_ro, &c->flags) && in bch2_fs_read_only()
367 test_bit(BCH_FS_started, &c->flags) && in bch2_fs_read_only()
368 test_bit(BCH_FS_clean_shutdown, &c->flags) && in bch2_fs_read_only()
369 c->recovery_pass_done >= BCH_RECOVERY_PASS_journal_replay) { in bch2_fs_read_only()
370 BUG_ON(c->journal.last_empty_seq != journal_cur_seq(&c->journal)); in bch2_fs_read_only()
371 BUG_ON(atomic_long_read(&c->btree_cache.nr_dirty)); in bch2_fs_read_only()
372 BUG_ON(atomic_long_read(&c->btree_key_cache.nr_dirty)); in bch2_fs_read_only()
373 BUG_ON(c->btree_write_buffer.inc.keys.nr); in bch2_fs_read_only()
374 BUG_ON(c->btree_write_buffer.flushing.keys.nr); in bch2_fs_read_only()
375 bch2_verify_accounting_clean(c); in bch2_fs_read_only()
377 bch_verbose(c, "marking filesystem clean"); in bch2_fs_read_only()
378 bch2_fs_mark_clean(c); in bch2_fs_read_only()
381 mutex_lock(&c->sb_lock); in bch2_fs_read_only()
382 bch2_write_super(c); in bch2_fs_read_only()
383 mutex_unlock(&c->sb_lock); in bch2_fs_read_only()
385 bch_verbose(c, "done going read-only, filesystem not clean"); in bch2_fs_read_only()
391 struct bch_fs *c = in bch2_fs_read_only_work() local
394 down_write(&c->state_lock); in bch2_fs_read_only_work()
395 bch2_fs_read_only(c); in bch2_fs_read_only_work()
396 up_write(&c->state_lock); in bch2_fs_read_only_work()
399 static void bch2_fs_read_only_async(struct bch_fs *c) in bch2_fs_read_only_async() argument
401 queue_work(system_long_wq, &c->read_only_work); in bch2_fs_read_only_async()
404 bool bch2_fs_emergency_read_only(struct bch_fs *c) in bch2_fs_emergency_read_only() argument
406 bool ret = !test_and_set_bit(BCH_FS_emergency_ro, &c->flags); in bch2_fs_emergency_read_only()
408 bch2_journal_halt(&c->journal); in bch2_fs_emergency_read_only()
409 bch2_fs_read_only_async(c); in bch2_fs_emergency_read_only()
415 bool bch2_fs_emergency_read_only_locked(struct bch_fs *c) in bch2_fs_emergency_read_only_locked() argument
417 bool ret = !test_and_set_bit(BCH_FS_emergency_ro, &c->flags); in bch2_fs_emergency_read_only_locked()
419 bch2_journal_halt_locked(&c->journal); in bch2_fs_emergency_read_only_locked()
420 bch2_fs_read_only_async(c); in bch2_fs_emergency_read_only_locked()
426 static int __bch2_fs_read_write(struct bch_fs *c, bool early) in __bch2_fs_read_write() argument
430 BUG_ON(!test_bit(BCH_FS_may_go_rw, &c->flags)); in __bch2_fs_read_write()
432 if (test_bit(BCH_FS_initial_gc_unfixed, &c->flags)) { in __bch2_fs_read_write()
433 bch_err(c, "cannot go rw, unfixed btree errors"); in __bch2_fs_read_write()
437 if (test_bit(BCH_FS_rw, &c->flags)) in __bch2_fs_read_write()
440 bch_info(c, "going read-write"); in __bch2_fs_read_write()
442 ret = bch2_sb_members_v2_init(c); in __bch2_fs_read_write()
446 clear_bit(BCH_FS_clean_shutdown, &c->flags); in __bch2_fs_read_write()
448 __for_each_online_member(c, ca, BIT(BCH_MEMBER_STATE_rw), READ) { in __bch2_fs_read_write()
449 bch2_dev_allocator_add(c, ca); in __bch2_fs_read_write()
452 bch2_recalc_capacity(c); in __bch2_fs_read_write()
460 spin_lock(&c->journal.lock); in __bch2_fs_read_write()
461 set_bit(JOURNAL_need_flush_write, &c->journal.flags); in __bch2_fs_read_write()
462 set_bit(JOURNAL_running, &c->journal.flags); in __bch2_fs_read_write()
463 bch2_journal_space_available(&c->journal); in __bch2_fs_read_write()
464 spin_unlock(&c->journal.lock); in __bch2_fs_read_write()
466 ret = bch2_fs_mark_dirty(c); in __bch2_fs_read_write()
470 ret = bch2_journal_reclaim_start(&c->journal); in __bch2_fs_read_write()
474 set_bit(BCH_FS_rw, &c->flags); in __bch2_fs_read_write()
475 set_bit(BCH_FS_was_rw, &c->flags); in __bch2_fs_read_write()
478 percpu_ref_reinit(&c->writes); in __bch2_fs_read_write()
481 BUG_ON(atomic_long_read(&c->writes[i])); in __bch2_fs_read_write()
482 atomic_long_inc(&c->writes[i]); in __bch2_fs_read_write()
486 ret = bch2_copygc_start(c); in __bch2_fs_read_write()
488 bch_err_msg(c, ret, "error starting copygc thread"); in __bch2_fs_read_write()
492 ret = bch2_rebalance_start(c); in __bch2_fs_read_write()
494 bch_err_msg(c, ret, "error starting rebalance thread"); in __bch2_fs_read_write()
498 bch2_do_discards(c); in __bch2_fs_read_write()
499 bch2_do_invalidates(c); in __bch2_fs_read_write()
500 bch2_do_stripe_deletes(c); in __bch2_fs_read_write()
501 bch2_do_pending_node_rewrites(c); in __bch2_fs_read_write()
504 if (test_bit(BCH_FS_rw, &c->flags)) in __bch2_fs_read_write()
505 bch2_fs_read_only(c); in __bch2_fs_read_write()
507 __bch2_fs_read_only(c); in __bch2_fs_read_write()
511 int bch2_fs_read_write(struct bch_fs *c) in bch2_fs_read_write() argument
513 if (c->opts.recovery_pass_last && in bch2_fs_read_write()
514 c->opts.recovery_pass_last < BCH_RECOVERY_PASS_journal_replay) in bch2_fs_read_write()
517 if (c->opts.nochanges) in bch2_fs_read_write()
520 return __bch2_fs_read_write(c, false); in bch2_fs_read_write()
523 int bch2_fs_read_write_early(struct bch_fs *c) in bch2_fs_read_write_early() argument
525 down_write(&c->state_lock); in bch2_fs_read_write_early()
526 int ret = __bch2_fs_read_write(c, true); in bch2_fs_read_write_early()
527 up_write(&c->state_lock); in bch2_fs_read_write_early()
534 static void __bch2_fs_free(struct bch_fs *c) in __bch2_fs_free() argument
537 bch2_time_stats_exit(&c->times[i]); in __bch2_fs_free()
540 utf8_unload(c->cf_encoding); in __bch2_fs_free()
543 bch2_find_btree_nodes_exit(&c->found_btree_nodes); in __bch2_fs_free()
544 bch2_free_pending_node_rewrites(c); in __bch2_fs_free()
545 bch2_free_fsck_errs(c); in __bch2_fs_free()
546 bch2_fs_accounting_exit(c); in __bch2_fs_free()
547 bch2_fs_sb_errors_exit(c); in __bch2_fs_free()
548 bch2_fs_counters_exit(c); in __bch2_fs_free()
549 bch2_fs_snapshots_exit(c); in __bch2_fs_free()
550 bch2_fs_quota_exit(c); in __bch2_fs_free()
551 bch2_fs_fs_io_direct_exit(c); in __bch2_fs_free()
552 bch2_fs_fs_io_buffered_exit(c); in __bch2_fs_free()
553 bch2_fs_fsio_exit(c); in __bch2_fs_free()
554 bch2_fs_vfs_exit(c); in __bch2_fs_free()
555 bch2_fs_ec_exit(c); in __bch2_fs_free()
556 bch2_fs_encryption_exit(c); in __bch2_fs_free()
557 bch2_fs_nocow_locking_exit(c); in __bch2_fs_free()
558 bch2_fs_io_write_exit(c); in __bch2_fs_free()
559 bch2_fs_io_read_exit(c); in __bch2_fs_free()
560 bch2_fs_buckets_waiting_for_journal_exit(c); in __bch2_fs_free()
561 bch2_fs_btree_interior_update_exit(c); in __bch2_fs_free()
562 bch2_fs_btree_key_cache_exit(&c->btree_key_cache); in __bch2_fs_free()
563 bch2_fs_btree_cache_exit(c); in __bch2_fs_free()
564 bch2_fs_btree_iter_exit(c); in __bch2_fs_free()
565 bch2_fs_replicas_exit(c); in __bch2_fs_free()
566 bch2_fs_journal_exit(&c->journal); in __bch2_fs_free()
567 bch2_io_clock_exit(&c->io_clock[WRITE]); in __bch2_fs_free()
568 bch2_io_clock_exit(&c->io_clock[READ]); in __bch2_fs_free()
569 bch2_fs_compress_exit(c); in __bch2_fs_free()
570 bch2_fs_btree_gc_exit(c); in __bch2_fs_free()
571 bch2_journal_keys_put_initial(c); in __bch2_fs_free()
572 bch2_find_btree_nodes_exit(&c->found_btree_nodes); in __bch2_fs_free()
573 BUG_ON(atomic_read(&c->journal_keys.ref)); in __bch2_fs_free()
574 bch2_fs_btree_write_buffer_exit(c); in __bch2_fs_free()
575 percpu_free_rwsem(&c->mark_lock); in __bch2_fs_free()
576 if (c->online_reserved) { in __bch2_fs_free()
577 u64 v = percpu_u64_get(c->online_reserved); in __bch2_fs_free()
579 free_percpu(c->online_reserved); in __bch2_fs_free()
582 darray_exit(&c->incompat_versions_requested); in __bch2_fs_free()
583 darray_exit(&c->btree_roots_extra); in __bch2_fs_free()
584 free_percpu(c->pcpu); in __bch2_fs_free()
585 free_percpu(c->usage); in __bch2_fs_free()
586 mempool_exit(&c->large_bkey_pool); in __bch2_fs_free()
587 mempool_exit(&c->btree_bounce_pool); in __bch2_fs_free()
588 bioset_exit(&c->btree_bio); in __bch2_fs_free()
589 mempool_exit(&c->fill_iter); in __bch2_fs_free()
591 percpu_ref_exit(&c->writes); in __bch2_fs_free()
593 kfree(rcu_dereference_protected(c->disk_groups, 1)); in __bch2_fs_free()
594 kfree(c->journal_seq_blacklist_table); in __bch2_fs_free()
596 if (c->write_ref_wq) in __bch2_fs_free()
597 destroy_workqueue(c->write_ref_wq); in __bch2_fs_free()
598 if (c->btree_write_submit_wq) in __bch2_fs_free()
599 destroy_workqueue(c->btree_write_submit_wq); in __bch2_fs_free()
600 if (c->btree_read_complete_wq) in __bch2_fs_free()
601 destroy_workqueue(c->btree_read_complete_wq); in __bch2_fs_free()
602 if (c->copygc_wq) in __bch2_fs_free()
603 destroy_workqueue(c->copygc_wq); in __bch2_fs_free()
604 if (c->btree_io_complete_wq) in __bch2_fs_free()
605 destroy_workqueue(c->btree_io_complete_wq); in __bch2_fs_free()
606 if (c->btree_update_wq) in __bch2_fs_free()
607 destroy_workqueue(c->btree_update_wq); in __bch2_fs_free()
609 bch2_free_super(&c->disk_sb); in __bch2_fs_free()
610 kvfree(c); in __bch2_fs_free()
616 struct bch_fs *c = container_of(kobj, struct bch_fs, kobj); in bch2_fs_release() local
618 __bch2_fs_free(c); in bch2_fs_release()
621 void __bch2_fs_stop(struct bch_fs *c) in __bch2_fs_stop() argument
623 bch_verbose(c, "shutting down"); in __bch2_fs_stop()
625 set_bit(BCH_FS_stopping, &c->flags); in __bch2_fs_stop()
627 down_write(&c->state_lock); in __bch2_fs_stop()
628 bch2_fs_read_only(c); in __bch2_fs_stop()
629 up_write(&c->state_lock); in __bch2_fs_stop()
631 for_each_member_device(c, ca) in __bch2_fs_stop()
634 if (c->kobj.state_in_sysfs) in __bch2_fs_stop()
635 kobject_del(&c->kobj); in __bch2_fs_stop()
637 bch2_fs_debug_exit(c); in __bch2_fs_stop()
638 bch2_fs_chardev_exit(c); in __bch2_fs_stop()
640 bch2_ro_ref_put(c); in __bch2_fs_stop()
641 wait_event(c->ro_ref_wait, !refcount_read(&c->ro_ref)); in __bch2_fs_stop()
643 kobject_put(&c->counters_kobj); in __bch2_fs_stop()
644 kobject_put(&c->time_stats); in __bch2_fs_stop()
645 kobject_put(&c->opts_dir); in __bch2_fs_stop()
646 kobject_put(&c->internal); in __bch2_fs_stop()
649 bch2_btree_flush_all_reads(c); in __bch2_fs_stop()
651 for_each_member_device(c, ca) in __bch2_fs_stop()
654 cancel_work_sync(&c->read_only_work); in __bch2_fs_stop()
657 void bch2_fs_free(struct bch_fs *c) in bch2_fs_free() argument
662 list_del(&c->list); in bch2_fs_free()
665 closure_sync(&c->cl); in bch2_fs_free()
666 closure_debug_destroy(&c->cl); in bch2_fs_free()
668 for (i = 0; i < c->sb.nr_devices; i++) { in bch2_fs_free()
669 struct bch_dev *ca = rcu_dereference_protected(c->devs[i], true); in bch2_fs_free()
679 bch_verbose(c, "shutdown complete"); in bch2_fs_free()
681 kobject_put(&c->kobj); in bch2_fs_free()
684 void bch2_fs_stop(struct bch_fs *c) in bch2_fs_stop() argument
686 __bch2_fs_stop(c); in bch2_fs_stop()
687 bch2_fs_free(c); in bch2_fs_stop()
690 static int bch2_fs_online(struct bch_fs *c) in bch2_fs_online() argument
696 if (__bch2_uuid_to_fs(c->sb.uuid)) { in bch2_fs_online()
697 bch_err(c, "filesystem UUID already open"); in bch2_fs_online()
701 ret = bch2_fs_chardev_init(c); in bch2_fs_online()
703 bch_err(c, "error creating character device"); in bch2_fs_online()
707 bch2_fs_debug_init(c); in bch2_fs_online()
709 ret = kobject_add(&c->kobj, NULL, "%pU", c->sb.user_uuid.b) ?: in bch2_fs_online()
710 kobject_add(&c->internal, &c->kobj, "internal") ?: in bch2_fs_online()
711 kobject_add(&c->opts_dir, &c->kobj, "options") ?: in bch2_fs_online()
713 kobject_add(&c->time_stats, &c->kobj, "time_stats") ?: in bch2_fs_online()
715 kobject_add(&c->counters_kobj, &c->kobj, "counters") ?: in bch2_fs_online()
716 bch2_opts_create_sysfs_files(&c->opts_dir, OPT_FS); in bch2_fs_online()
718 bch_err(c, "error creating sysfs objects"); in bch2_fs_online()
722 down_write(&c->state_lock); in bch2_fs_online()
724 for_each_member_device(c, ca) { in bch2_fs_online()
725 ret = bch2_dev_sysfs_online(c, ca); in bch2_fs_online()
727 bch_err(c, "error creating sysfs objects"); in bch2_fs_online()
733 BUG_ON(!list_empty(&c->list)); in bch2_fs_online()
734 list_add(&c->list, &bch_fs_list); in bch2_fs_online()
736 up_write(&c->state_lock); in bch2_fs_online()
742 struct bch_fs *c; in bch2_fs_alloc() local
747 c = kvmalloc(sizeof(struct bch_fs), GFP_KERNEL|__GFP_ZERO); in bch2_fs_alloc()
748 if (!c) { in bch2_fs_alloc()
749 c = ERR_PTR(-BCH_ERR_ENOMEM_fs_alloc); in bch2_fs_alloc()
753 c->stdio = (void *)(unsigned long) opts.stdio; in bch2_fs_alloc()
757 closure_init(&c->cl, NULL); in bch2_fs_alloc()
759 c->kobj.kset = bcachefs_kset; in bch2_fs_alloc()
760 kobject_init(&c->kobj, &bch2_fs_ktype); in bch2_fs_alloc()
761 kobject_init(&c->internal, &bch2_fs_internal_ktype); in bch2_fs_alloc()
762 kobject_init(&c->opts_dir, &bch2_fs_opts_dir_ktype); in bch2_fs_alloc()
763 kobject_init(&c->time_stats, &bch2_fs_time_stats_ktype); in bch2_fs_alloc()
764 kobject_init(&c->counters_kobj, &bch2_fs_counters_ktype); in bch2_fs_alloc()
766 c->minor = -1; in bch2_fs_alloc()
767 c->disk_sb.fs_sb = true; in bch2_fs_alloc()
769 init_rwsem(&c->state_lock); in bch2_fs_alloc()
770 mutex_init(&c->sb_lock); in bch2_fs_alloc()
771 mutex_init(&c->replicas_gc_lock); in bch2_fs_alloc()
772 mutex_init(&c->btree_root_lock); in bch2_fs_alloc()
773 INIT_WORK(&c->read_only_work, bch2_fs_read_only_work); in bch2_fs_alloc()
775 refcount_set(&c->ro_ref, 1); in bch2_fs_alloc()
776 init_waitqueue_head(&c->ro_ref_wait); in bch2_fs_alloc()
777 spin_lock_init(&c->recovery_pass_lock); in bch2_fs_alloc()
778 sema_init(&c->online_fsck_mutex, 1); in bch2_fs_alloc()
781 bch2_time_stats_init(&c->times[i]); in bch2_fs_alloc()
783 bch2_fs_copygc_init(c); in bch2_fs_alloc()
784 bch2_fs_btree_key_cache_init_early(&c->btree_key_cache); in bch2_fs_alloc()
785 bch2_fs_btree_iter_init_early(c); in bch2_fs_alloc()
786 bch2_fs_btree_interior_update_init_early(c); in bch2_fs_alloc()
787 bch2_fs_journal_keys_init(c); in bch2_fs_alloc()
788 bch2_fs_allocator_background_init(c); in bch2_fs_alloc()
789 bch2_fs_allocator_foreground_init(c); in bch2_fs_alloc()
790 bch2_fs_rebalance_init(c); in bch2_fs_alloc()
791 bch2_fs_quota_init(c); in bch2_fs_alloc()
792 bch2_fs_ec_init_early(c); in bch2_fs_alloc()
793 bch2_fs_move_init(c); in bch2_fs_alloc()
794 bch2_fs_sb_errors_init_early(c); in bch2_fs_alloc()
796 INIT_LIST_HEAD(&c->list); in bch2_fs_alloc()
798 mutex_init(&c->bio_bounce_pages_lock); in bch2_fs_alloc()
799 mutex_init(&c->snapshot_table_lock); in bch2_fs_alloc()
800 init_rwsem(&c->snapshot_create_lock); in bch2_fs_alloc()
802 spin_lock_init(&c->btree_write_error_lock); in bch2_fs_alloc()
804 INIT_LIST_HEAD(&c->journal_iters); in bch2_fs_alloc()
806 INIT_LIST_HEAD(&c->fsck_error_msgs); in bch2_fs_alloc()
807 mutex_init(&c->fsck_error_msgs_lock); in bch2_fs_alloc()
809 seqcount_init(&c->usage_lock); in bch2_fs_alloc()
811 sema_init(&c->io_in_flight, 128); in bch2_fs_alloc()
813 INIT_LIST_HEAD(&c->vfs_inodes_list); in bch2_fs_alloc()
814 mutex_init(&c->vfs_inodes_lock); in bch2_fs_alloc()
816 c->journal.flush_write_time = &c->times[BCH_TIME_journal_flush_write]; in bch2_fs_alloc()
817 c->journal.noflush_write_time = &c->times[BCH_TIME_journal_noflush_write]; in bch2_fs_alloc()
818 c->journal.flush_seq_time = &c->times[BCH_TIME_journal_flush_seq]; in bch2_fs_alloc()
820 bch2_fs_btree_cache_init_early(&c->btree_cache); in bch2_fs_alloc()
822 mutex_init(&c->sectors_available_lock); in bch2_fs_alloc()
824 ret = percpu_init_rwsem(&c->mark_lock); in bch2_fs_alloc()
828 mutex_lock(&c->sb_lock); in bch2_fs_alloc()
829 ret = bch2_sb_to_fs(c, sb); in bch2_fs_alloc()
830 mutex_unlock(&c->sb_lock); in bch2_fs_alloc()
835 pr_uuid(&name, c->sb.user_uuid.b); in bch2_fs_alloc()
840 strscpy(c->name, name.buf, sizeof(c->name)); in bch2_fs_alloc()
852 c->opts = bch2_opts_default; in bch2_fs_alloc()
853 ret = bch2_opts_from_sb(&c->opts, sb); in bch2_fs_alloc()
857 bch2_opts_apply(&c->opts, opts); in bch2_fs_alloc()
859 c->btree_key_cache_btrees |= 1U << BTREE_ID_alloc; in bch2_fs_alloc()
860 if (c->opts.inodes_use_key_cache) in bch2_fs_alloc()
861 c->btree_key_cache_btrees |= 1U << BTREE_ID_inodes; in bch2_fs_alloc()
862 c->btree_key_cache_btrees |= 1U << BTREE_ID_logged_ops; in bch2_fs_alloc()
864 c->block_bits = ilog2(block_sectors(c)); in bch2_fs_alloc()
865 c->btree_foreground_merge_threshold = BTREE_FOREGROUND_MERGE_THRESHOLD(c); in bch2_fs_alloc()
868 bch_err(c, "fs_alloc fault injected"); in bch2_fs_alloc()
874 (btree_blocks(c) + 1) * 2 * in bch2_fs_alloc()
877 if (!(c->btree_update_wq = alloc_workqueue("bcachefs", in bch2_fs_alloc()
879 !(c->btree_io_complete_wq = alloc_workqueue("bcachefs_btree_io", in bch2_fs_alloc()
881 !(c->copygc_wq = alloc_workqueue("bcachefs_copygc", in bch2_fs_alloc()
883 !(c->btree_read_complete_wq = alloc_workqueue("bcachefs_btree_read_complete", in bch2_fs_alloc()
885 !(c->btree_write_submit_wq = alloc_workqueue("bcachefs_btree_write_sumit", in bch2_fs_alloc()
887 !(c->write_ref_wq = alloc_workqueue("bcachefs_write_ref", in bch2_fs_alloc()
890 percpu_ref_init(&c->writes, bch2_writes_disabled, in bch2_fs_alloc()
893 mempool_init_kmalloc_pool(&c->fill_iter, 1, iter_size) || in bch2_fs_alloc()
894 bioset_init(&c->btree_bio, 1, in bch2_fs_alloc()
898 !(c->pcpu = alloc_percpu(struct bch_fs_pcpu)) || in bch2_fs_alloc()
899 !(c->usage = alloc_percpu(struct bch_fs_usage_base)) || in bch2_fs_alloc()
900 !(c->online_reserved = alloc_percpu(u64)) || in bch2_fs_alloc()
901 mempool_init_kvmalloc_pool(&c->btree_bounce_pool, 1, in bch2_fs_alloc()
902 c->opts.btree_node_size) || in bch2_fs_alloc()
903 mempool_init_kmalloc_pool(&c->large_bkey_pool, 1, 2048)) { in bch2_fs_alloc()
908 ret = bch2_fs_counters_init(c) ?: in bch2_fs_alloc()
909 bch2_fs_sb_errors_init(c) ?: in bch2_fs_alloc()
910 bch2_io_clock_init(&c->io_clock[READ]) ?: in bch2_fs_alloc()
911 bch2_io_clock_init(&c->io_clock[WRITE]) ?: in bch2_fs_alloc()
912 bch2_fs_journal_init(&c->journal) ?: in bch2_fs_alloc()
913 bch2_fs_btree_iter_init(c) ?: in bch2_fs_alloc()
914 bch2_fs_btree_cache_init(c) ?: in bch2_fs_alloc()
915 bch2_fs_btree_key_cache_init(&c->btree_key_cache) ?: in bch2_fs_alloc()
916 bch2_fs_btree_interior_update_init(c) ?: in bch2_fs_alloc()
917 bch2_fs_btree_gc_init(c) ?: in bch2_fs_alloc()
918 bch2_fs_buckets_waiting_for_journal_init(c) ?: in bch2_fs_alloc()
919 bch2_fs_btree_write_buffer_init(c) ?: in bch2_fs_alloc()
920 bch2_fs_subvolumes_init(c) ?: in bch2_fs_alloc()
921 bch2_fs_io_read_init(c) ?: in bch2_fs_alloc()
922 bch2_fs_io_write_init(c) ?: in bch2_fs_alloc()
923 bch2_fs_nocow_locking_init(c) ?: in bch2_fs_alloc()
924 bch2_fs_encryption_init(c) ?: in bch2_fs_alloc()
925 bch2_fs_compress_init(c) ?: in bch2_fs_alloc()
926 bch2_fs_ec_init(c) ?: in bch2_fs_alloc()
927 bch2_fs_vfs_init(c) ?: in bch2_fs_alloc()
928 bch2_fs_fsio_init(c) ?: in bch2_fs_alloc()
929 bch2_fs_fs_io_buffered_init(c) ?: in bch2_fs_alloc()
930 bch2_fs_fs_io_direct_init(c); in bch2_fs_alloc()
936 c->cf_encoding = utf8_load(BCH_FS_DEFAULT_UTF8_ENCODING); in bch2_fs_alloc()
937 if (IS_ERR(c->cf_encoding)) { in bch2_fs_alloc()
945 bch_info(c, "Using encoding defined by superblock: utf8-%u.%u.%u", in bch2_fs_alloc()
950 if (c->sb.features & BIT_ULL(BCH_FEATURE_casefolding)) { in bch2_fs_alloc()
957 for (i = 0; i < c->sb.nr_devices; i++) { in bch2_fs_alloc()
958 if (!bch2_member_exists(c->disk_sb.sb, i)) in bch2_fs_alloc()
960 ret = bch2_dev_alloc(c, i); in bch2_fs_alloc()
965 bch2_journal_entry_res_resize(&c->journal, in bch2_fs_alloc()
966 &c->btree_root_journal_res, in bch2_fs_alloc()
968 bch2_journal_entry_res_resize(&c->journal, in bch2_fs_alloc()
969 &c->clock_journal_res, in bch2_fs_alloc()
973 ret = bch2_fs_online(c); in bch2_fs_alloc()
979 return c; in bch2_fs_alloc()
981 bch2_fs_free(c); in bch2_fs_alloc()
982 c = ERR_PTR(ret); in bch2_fs_alloc()
987 static void print_mount_opts(struct bch_fs *c) in print_mount_opts() argument
994 bch2_version_to_text(&p, c->sb.version); in print_mount_opts()
998 u64 v = bch2_opt_get_by_id(&c->opts, i); in print_mount_opts()
1008 bch2_opt_to_text(&p, c, c->disk_sb.sb, opt, v, OPT_SHOW_MOUNT_STYLE); in print_mount_opts()
1011 if (c->sb.version_incompat_allowed != c->sb.version) { in print_mount_opts()
1013 bch2_version_to_text(&p, c->sb.version_incompat_allowed); in print_mount_opts()
1016 bch_info(c, "%s", p.buf); in print_mount_opts()
1020 static bool bch2_fs_may_start(struct bch_fs *c) in bch2_fs_may_start() argument
1025 if (c->opts.very_degraded) in bch2_fs_may_start()
1028 if (c->opts.degraded) in bch2_fs_may_start()
1031 if (!c->opts.degraded && in bch2_fs_may_start()
1032 !c->opts.very_degraded) { in bch2_fs_may_start()
1033 mutex_lock(&c->sb_lock); in bch2_fs_may_start()
1035 for (i = 0; i < c->disk_sb.sb->nr_devices; i++) { in bch2_fs_may_start()
1036 if (!bch2_member_exists(c->disk_sb.sb, i)) in bch2_fs_may_start()
1039 ca = bch2_dev_locked(c, i); in bch2_fs_may_start()
1044 mutex_unlock(&c->sb_lock); in bch2_fs_may_start()
1048 mutex_unlock(&c->sb_lock); in bch2_fs_may_start()
1051 return bch2_have_enough_devs(c, bch2_online_devs(c), flags, true); in bch2_fs_may_start()
1054 int bch2_fs_start(struct bch_fs *c) in bch2_fs_start() argument
1059 print_mount_opts(c); in bch2_fs_start()
1061 if (!bch2_fs_may_start(c)) in bch2_fs_start()
1064 down_write(&c->state_lock); in bch2_fs_start()
1065 mutex_lock(&c->sb_lock); in bch2_fs_start()
1067 BUG_ON(test_bit(BCH_FS_started, &c->flags)); in bch2_fs_start()
1069 if (!bch2_sb_field_get_minsize(&c->disk_sb, ext, in bch2_fs_start()
1071 mutex_unlock(&c->sb_lock); in bch2_fs_start()
1072 up_write(&c->state_lock); in bch2_fs_start()
1077 ret = bch2_sb_members_v2_init(c); in bch2_fs_start()
1079 mutex_unlock(&c->sb_lock); in bch2_fs_start()
1080 up_write(&c->state_lock); in bch2_fs_start()
1084 for_each_online_member(c, ca) in bch2_fs_start()
1085 bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx)->last_mount = cpu_to_le64(now); in bch2_fs_start()
1087 mutex_unlock(&c->sb_lock); in bch2_fs_start()
1089 for_each_rw_member(c, ca) in bch2_fs_start()
1090 bch2_dev_allocator_add(c, ca); in bch2_fs_start()
1091 bch2_recalc_capacity(c); in bch2_fs_start()
1092 up_write(&c->state_lock); in bch2_fs_start()
1094 c->recovery_task = current; in bch2_fs_start()
1095 ret = BCH_SB_INITIALIZED(c->disk_sb.sb) in bch2_fs_start()
1096 ? bch2_fs_recovery(c) in bch2_fs_start()
1097 : bch2_fs_initialize(c); in bch2_fs_start()
1098 c->recovery_task = NULL; in bch2_fs_start()
1103 ret = bch2_opts_check_may_set(c); in bch2_fs_start()
1112 set_bit(BCH_FS_started, &c->flags); in bch2_fs_start()
1113 wake_up(&c->ro_ref_wait); in bch2_fs_start()
1115 down_write(&c->state_lock); in bch2_fs_start()
1116 if (c->opts.read_only) in bch2_fs_start()
1117 bch2_fs_read_only(c); in bch2_fs_start()
1118 else if (!test_bit(BCH_FS_rw, &c->flags)) in bch2_fs_start()
1119 ret = bch2_fs_read_write(c); in bch2_fs_start()
1120 up_write(&c->state_lock); in bch2_fs_start()
1124 bch_err_msg(c, ret, "starting filesystem"); in bch2_fs_start()
1126 bch_verbose(c, "done starting filesystem"); in bch2_fs_start()
1130 static int bch2_dev_may_add(struct bch_sb *sb, struct bch_fs *c) in bch2_dev_may_add() argument
1134 if (le16_to_cpu(sb->block_size) != block_sectors(c)) in bch2_dev_may_add()
1138 BCH_SB_BTREE_NODE_SIZE(c->disk_sb.sb)) in bch2_dev_may_add()
1282 static void __bch2_dev_offline(struct bch_fs *c, struct bch_dev *ca) in __bch2_dev_offline() argument
1285 lockdep_assert_held(&c->state_lock); in __bch2_dev_offline()
1290 __bch2_dev_read_only(c, ca); in __bch2_dev_offline()
1332 * code doesn't appear to provide a good method and block/holder.c is in bch2_dev_unlink()
1343 static int bch2_dev_sysfs_online(struct bch_fs *c, struct bch_dev *ca) in bch2_dev_sysfs_online() argument
1347 if (!c->kobj.state_in_sysfs) in bch2_dev_sysfs_online()
1351 ret = kobject_add(&ca->kobj, &c->kobj, "dev-%u", ca->dev_idx) ?: in bch2_dev_sysfs_online()
1372 static struct bch_dev *__bch2_dev_alloc(struct bch_fs *c, in __bch2_dev_alloc() argument
1400 ca->mi.bucket_size / btree_sectors(c)); in __bch2_dev_alloc()
1416 bch2_dev_buckets_alloc(c, ca) || in __bch2_dev_alloc()
1426 static void bch2_dev_attach(struct bch_fs *c, struct bch_dev *ca, in bch2_dev_attach() argument
1433 ca->fs = c; in bch2_dev_attach()
1434 rcu_assign_pointer(c->devs[ca->dev_idx], ca); in bch2_dev_attach()
1436 if (bch2_dev_sysfs_online(c, ca)) in bch2_dev_attach()
1440 static int bch2_dev_alloc(struct bch_fs *c, unsigned dev_idx) in bch2_dev_alloc() argument
1442 struct bch_member member = bch2_sb_member_get(c->disk_sb.sb, dev_idx); in bch2_dev_alloc()
1448 ca = __bch2_dev_alloc(c, &member); in bch2_dev_alloc()
1452 ca->fs = c; in bch2_dev_alloc()
1454 bch2_dev_attach(c, ca, dev_idx); in bch2_dev_alloc()
1492 ca->disk_sb.holder->c = ca->fs; in __bch2_dev_attach_bdev()
1501 static int bch2_dev_attach_bdev(struct bch_fs *c, struct bch_sb_handle *sb) in bch2_dev_attach_bdev() argument
1506 lockdep_assert_held(&c->state_lock); in bch2_dev_attach_bdev()
1509 le64_to_cpu(c->disk_sb.sb->seq)) in bch2_dev_attach_bdev()
1510 bch2_sb_to_fs(c, sb->sb); in bch2_dev_attach_bdev()
1512 BUG_ON(!bch2_dev_exists(c, sb->sb->dev_idx)); in bch2_dev_attach_bdev()
1514 ca = bch2_dev_locked(c, sb->sb->dev_idx); in bch2_dev_attach_bdev()
1520 bch2_dev_sysfs_online(c, ca); in bch2_dev_attach_bdev()
1525 if (c->sb.nr_devices == 1) in bch2_dev_attach_bdev()
1526 strscpy(c->name, name.buf, sizeof(c->name)); in bch2_dev_attach_bdev()
1531 bch2_rebalance_wakeup(c); in bch2_dev_attach_bdev()
1546 bool bch2_dev_state_allowed(struct bch_fs *c, struct bch_dev *ca, in bch2_dev_state_allowed() argument
1552 lockdep_assert_held(&c->state_lock); in bch2_dev_state_allowed()
1562 for_each_member_device(c, ca2) in bch2_dev_state_allowed()
1567 ? c->opts.metadata_replicas in bch2_dev_state_allowed()
1568 : metadata_replicas_required(c), in bch2_dev_state_allowed()
1570 ? c->opts.data_replicas in bch2_dev_state_allowed()
1571 : data_replicas_required(c)); in bch2_dev_state_allowed()
1581 new_online_devs = bch2_online_devs(c); in bch2_dev_state_allowed()
1584 return bch2_have_enough_devs(c, new_online_devs, flags, false); in bch2_dev_state_allowed()
1590 static void __bch2_dev_read_only(struct bch_fs *c, struct bch_dev *ca) in __bch2_dev_read_only() argument
1597 bch2_dev_allocator_remove(c, ca); in __bch2_dev_read_only()
1598 bch2_recalc_capacity(c); in __bch2_dev_read_only()
1599 bch2_dev_journal_stop(&c->journal, ca); in __bch2_dev_read_only()
1602 static void __bch2_dev_read_write(struct bch_fs *c, struct bch_dev *ca) in __bch2_dev_read_write() argument
1604 lockdep_assert_held(&c->state_lock); in __bch2_dev_read_write()
1608 bch2_dev_allocator_add(c, ca); in __bch2_dev_read_write()
1609 bch2_recalc_capacity(c); in __bch2_dev_read_write()
1617 int __bch2_dev_set_state(struct bch_fs *c, struct bch_dev *ca, in __bch2_dev_set_state() argument
1626 if (!bch2_dev_state_allowed(c, ca, new_state, flags)) in __bch2_dev_set_state()
1630 __bch2_dev_read_only(c, ca); in __bch2_dev_set_state()
1634 mutex_lock(&c->sb_lock); in __bch2_dev_set_state()
1635 m = bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx); in __bch2_dev_set_state()
1637 bch2_write_super(c); in __bch2_dev_set_state()
1638 mutex_unlock(&c->sb_lock); in __bch2_dev_set_state()
1641 __bch2_dev_read_write(c, ca); in __bch2_dev_set_state()
1643 bch2_rebalance_wakeup(c); in __bch2_dev_set_state()
1648 int bch2_dev_set_state(struct bch_fs *c, struct bch_dev *ca, in bch2_dev_set_state() argument
1653 down_write(&c->state_lock); in bch2_dev_set_state()
1654 ret = __bch2_dev_set_state(c, ca, new_state, flags); in bch2_dev_set_state()
1655 up_write(&c->state_lock); in bch2_dev_set_state()
1662 int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags) in bch2_dev_remove() argument
1668 down_write(&c->state_lock); in bch2_dev_remove()
1676 if (!bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_failed, flags)) { in bch2_dev_remove()
1682 __bch2_dev_read_only(c, ca); in bch2_dev_remove()
1684 ret = bch2_dev_data_drop(c, ca->dev_idx, flags); in bch2_dev_remove()
1689 ret = bch2_dev_remove_alloc(c, ca); in bch2_dev_remove()
1698 bch2_journal_flush_all_pins(&c->journal); in bch2_dev_remove()
1704 ret = bch2_journal_flush_device_pins(&c->journal, ca->dev_idx); in bch2_dev_remove()
1709 ret = bch2_journal_flush(&c->journal); in bch2_dev_remove()
1714 ret = bch2_replicas_gc2(c); in bch2_dev_remove()
1719 data = bch2_dev_has_data(c, ca); in bch2_dev_remove()
1730 __bch2_dev_offline(c, ca); in bch2_dev_remove()
1732 mutex_lock(&c->sb_lock); in bch2_dev_remove()
1733 rcu_assign_pointer(c->devs[ca->dev_idx], NULL); in bch2_dev_remove()
1734 mutex_unlock(&c->sb_lock); in bch2_dev_remove()
1750 mutex_lock(&c->sb_lock); in bch2_dev_remove()
1751 m = bch2_members_v2_get_mut(c->disk_sb.sb, dev_idx); in bch2_dev_remove()
1754 bch2_write_super(c); in bch2_dev_remove()
1756 mutex_unlock(&c->sb_lock); in bch2_dev_remove()
1757 up_write(&c->state_lock); in bch2_dev_remove()
1760 if (test_bit(BCH_FS_rw, &c->flags) && in bch2_dev_remove()
1763 __bch2_dev_read_write(c, ca); in bch2_dev_remove()
1764 up_write(&c->state_lock); in bch2_dev_remove()
1769 int bch2_dev_add(struct bch_fs *c, const char *path) in bch2_dev_add() argument
1779 bch_err_msg(c, ret, "reading super"); in bch2_dev_add()
1793 ret = bch2_dev_may_add(sb.sb, c); in bch2_dev_add()
1797 ca = __bch2_dev_alloc(c, &dev_mi); in bch2_dev_add()
1807 down_write(&c->state_lock); in bch2_dev_add()
1808 mutex_lock(&c->sb_lock); in bch2_dev_add()
1810 ret = bch2_sb_from_fs(c, ca); in bch2_dev_add()
1811 bch_err_msg(c, ret, "setting up new superblock"); in bch2_dev_add()
1818 ret = bch2_sb_member_alloc(c); in bch2_dev_add()
1820 bch_err_msg(c, ret, "setting up new superblock"); in bch2_dev_add()
1828 *bch2_members_v2_get_mut(c->disk_sb.sb, dev_idx) = dev_mi; in bch2_dev_add()
1831 bch2_dev_attach(c, ca, dev_idx); in bch2_dev_add()
1834 ret = __bch2_dev_group_set(c, ca, label.buf); in bch2_dev_add()
1835 bch_err_msg(c, ret, "creating new label"); in bch2_dev_add()
1840 bch2_write_super(c); in bch2_dev_add()
1841 mutex_unlock(&c->sb_lock); in bch2_dev_add()
1847 ret = bch2_trans_mark_dev_sb(c, ca, BTREE_TRIGGER_transactional); in bch2_dev_add()
1852 ret = bch2_fs_freespace_init(c); in bch2_dev_add()
1858 __bch2_dev_read_write(c, ca); in bch2_dev_add()
1861 bch_err_msg(c, ret, "allocating journal"); in bch2_dev_add()
1865 up_write(&c->state_lock); in bch2_dev_add()
1869 bch_err_fn(c, ret); in bch2_dev_add()
1873 mutex_unlock(&c->sb_lock); in bch2_dev_add()
1874 up_write(&c->state_lock); in bch2_dev_add()
1881 up_write(&c->state_lock); in bch2_dev_add()
1887 int bch2_dev_online(struct bch_fs *c, const char *path) in bch2_dev_online() argument
1895 down_write(&c->state_lock); in bch2_dev_online()
1899 up_write(&c->state_lock); in bch2_dev_online()
1905 ret = bch2_dev_in_fs(&c->disk_sb, &sb, &c->opts); in bch2_dev_online()
1906 bch_err_msg(c, ret, "bringing %s online", path); in bch2_dev_online()
1910 ret = bch2_dev_attach_bdev(c, &sb); in bch2_dev_online()
1914 ca = bch2_dev_locked(c, dev_idx); in bch2_dev_online()
1916 ret = bch2_trans_mark_dev_sb(c, ca, BTREE_TRIGGER_transactional); in bch2_dev_online()
1917 bch_err_msg(c, ret, "bringing %s online: error from bch2_trans_mark_dev_sb", path); in bch2_dev_online()
1922 __bch2_dev_read_write(c, ca); in bch2_dev_online()
1925 ret = bch2_dev_freespace_init(c, ca, 0, ca->mi.nbuckets); in bch2_dev_online()
1938 mutex_lock(&c->sb_lock); in bch2_dev_online()
1939 bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx)->last_mount = in bch2_dev_online()
1941 bch2_write_super(c); in bch2_dev_online()
1942 mutex_unlock(&c->sb_lock); in bch2_dev_online()
1944 up_write(&c->state_lock); in bch2_dev_online()
1947 up_write(&c->state_lock); in bch2_dev_online()
1952 int bch2_dev_offline(struct bch_fs *c, struct bch_dev *ca, int flags) in bch2_dev_offline() argument
1954 down_write(&c->state_lock); in bch2_dev_offline()
1958 up_write(&c->state_lock); in bch2_dev_offline()
1962 if (!bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_failed, flags)) { in bch2_dev_offline()
1964 up_write(&c->state_lock); in bch2_dev_offline()
1968 __bch2_dev_offline(c, ca); in bch2_dev_offline()
1970 up_write(&c->state_lock); in bch2_dev_offline()
1974 int bch2_dev_resize(struct bch_fs *c, struct bch_dev *ca, u64 nbuckets) in bch2_dev_resize() argument
1980 down_write(&c->state_lock); in bch2_dev_resize()
2004 ret = bch2_dev_buckets_resize(c, ca, nbuckets); in bch2_dev_resize()
2009 ret = bch2_trans_mark_dev_sb(c, ca, BTREE_TRIGGER_transactional); in bch2_dev_resize()
2013 mutex_lock(&c->sb_lock); in bch2_dev_resize()
2014 m = bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx); in bch2_dev_resize()
2017 bch2_write_super(c); in bch2_dev_resize()
2018 mutex_unlock(&c->sb_lock); in bch2_dev_resize()
2027 bch2_dev_freespace_init(c, ca, old_nbuckets, nbuckets); in bch2_dev_resize()
2032 bch2_recalc_capacity(c); in bch2_dev_resize()
2034 up_write(&c->state_lock); in bch2_dev_resize()
2039 struct bch_dev *bch2_dev_lookup(struct bch_fs *c, const char *name) in bch2_dev_lookup() argument
2044 for_each_member_device(c, ca) in bch2_dev_lookup()
2056 struct bch_fs *c = holder->c; in bdev_get_fs() local
2058 if (c && !bch2_ro_ref_tryget(c)) in bdev_get_fs()
2059 c = NULL; in bdev_get_fs()
2063 if (c) in bdev_get_fs()
2064 wait_event(c->ro_ref_wait, test_bit(BCH_FS_started, &c->flags)); in bdev_get_fs()
2065 return c; in bdev_get_fs()
2069 static struct bch_dev *bdev_to_bch_dev(struct bch_fs *c, struct block_device *bdev) in bdev_to_bch_dev() argument
2071 for_each_member_device(c, ca) in bdev_to_bch_dev()
2079 struct bch_fs *c = bdev_get_fs(bdev); in bch2_fs_bdev_mark_dead() local
2080 if (!c) in bch2_fs_bdev_mark_dead()
2083 struct super_block *sb = c->vfs_sb; in bch2_fs_bdev_mark_dead()
2086 * Not necessary, c->ro_ref guards against the filesystem being in bch2_fs_bdev_mark_dead()
2093 down_write(&c->state_lock); in bch2_fs_bdev_mark_dead()
2094 struct bch_dev *ca = bdev_to_bch_dev(c, bdev); in bch2_fs_bdev_mark_dead()
2098 if (bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_failed, BCH_FORCE_IF_DEGRADED)) { in bch2_fs_bdev_mark_dead()
2099 __bch2_dev_offline(c, ca); in bch2_fs_bdev_mark_dead()
2108 bch2_journal_flush(&c->journal); in bch2_fs_bdev_mark_dead()
2109 bch2_fs_emergency_read_only(c); in bch2_fs_bdev_mark_dead()
2116 up_write(&c->state_lock); in bch2_fs_bdev_mark_dead()
2117 bch2_ro_ref_put(c); in bch2_fs_bdev_mark_dead()
2122 struct bch_fs *c = bdev_get_fs(bdev); in bch2_fs_bdev_sync() local
2123 if (!c) in bch2_fs_bdev_sync()
2126 struct super_block *sb = c->vfs_sb; in bch2_fs_bdev_sync()
2129 * Not necessary, c->ro_ref guards against the filesystem being in bch2_fs_bdev_sync()
2138 bch2_ro_ref_put(c); in bch2_fs_bdev_sync()
2158 struct bch_fs *c = NULL; in bch2_fs_open() local
2210 c = bch2_fs_alloc(best->sb, opts); in bch2_fs_open()
2211 ret = PTR_ERR_OR_ZERO(c); in bch2_fs_open()
2215 down_write(&c->state_lock); in bch2_fs_open()
2217 ret = bch2_dev_attach_bdev(c, sb); in bch2_fs_open()
2219 up_write(&c->state_lock); in bch2_fs_open()
2223 up_write(&c->state_lock); in bch2_fs_open()
2225 if (!c->opts.nostart) { in bch2_fs_open()
2226 ret = bch2_fs_start(c); in bch2_fs_open()
2236 return c; in bch2_fs_open()
2241 if (!IS_ERR_OR_NULL(c)) in bch2_fs_open()
2242 bch2_fs_stop(c); in bch2_fs_open()
2243 c = ERR_PTR(ret); in bch2_fs_open()