bcachefs: Move various init code to _init_early()
authorKent Overstreet <kent.overstreet@linux.dev>
Sat, 5 Apr 2025 23:30:43 +0000 (19:30 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:14:02 +0000 (20:14 -0400)
_init_early() is for initialization that cannot fail, and often must
happen for teardown partway through initialization to work.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_gc.c
fs/bcachefs/btree_gc.h
fs/bcachefs/btree_write_buffer.c
fs/bcachefs/btree_write_buffer.h
fs/bcachefs/journal.c
fs/bcachefs/journal.h
fs/bcachefs/nocow_locking.c
fs/bcachefs/nocow_locking.h
fs/bcachefs/subvolume.c
fs/bcachefs/subvolume.h
fs/bcachefs/super.c

index 37b69d89341f4ff9bfb223196551ef711ea2ed90..1f02d28c175c3b1e95b4d6f62ded6a251ce04dd5 100644 (file)
@@ -1266,16 +1266,11 @@ void bch2_gc_gens_async(struct bch_fs *c)
                bch2_write_ref_put(c, BCH_WRITE_REF_gc_gens);
 }
 
-void bch2_fs_btree_gc_exit(struct bch_fs *c)
-{
-}
-
-int bch2_fs_btree_gc_init(struct bch_fs *c)
+void bch2_fs_btree_gc_init_early(struct bch_fs *c)
 {
        seqcount_init(&c->gc_pos_lock);
        INIT_WORK(&c->gc_gens_work, bch2_gc_gens_work);
 
        init_rwsem(&c->gc_lock);
        mutex_init(&c->gc_gens_lock);
-       return 0;
 }
index 9693a90a48a2f11bcfc7f21c9f5e00a32769d34f..ec77662369a2f53924d069cd8459f18b3acb6e12 100644 (file)
@@ -83,7 +83,6 @@ void bch2_gc_pos_to_text(struct printbuf *, struct gc_pos *);
 int bch2_gc_gens(struct bch_fs *);
 void bch2_gc_gens_async(struct bch_fs *);
 
-void bch2_fs_btree_gc_exit(struct bch_fs *);
-int bch2_fs_btree_gc_init(struct bch_fs *);
+void bch2_fs_btree_gc_init_early(struct bch_fs *);
 
 #endif /* _BCACHEFS_BTREE_GC_H */
index 0941fb2c026d546fcbf61fbf1e80d78b7ddcb532..68ab48af40f0abf948563896974b93fb757577fd 100644 (file)
@@ -866,13 +866,18 @@ void bch2_fs_btree_write_buffer_exit(struct bch_fs *c)
        darray_exit(&wb->inc.keys);
 }
 
-int bch2_fs_btree_write_buffer_init(struct bch_fs *c)
+void bch2_fs_btree_write_buffer_init_early(struct bch_fs *c)
 {
        struct btree_write_buffer *wb = &c->btree_write_buffer;
 
        mutex_init(&wb->inc.lock);
        mutex_init(&wb->flushing.lock);
        INIT_WORK(&wb->flush_work, bch2_btree_write_buffer_flush_work);
+}
+
+int bch2_fs_btree_write_buffer_init(struct bch_fs *c)
+{
+       struct btree_write_buffer *wb = &c->btree_write_buffer;
 
        /* Will be resized by journal as needed: */
        unsigned initial_size = 1 << 16;
index d535cea28bde99bdbec5eb3b9bce48372b3bee9c..05f56fd1eed0365aa9502920bc0e0c686a9117f8 100644 (file)
@@ -101,6 +101,7 @@ int bch2_journal_keys_to_write_buffer_end(struct bch_fs *, struct journal_keys_t
 
 int bch2_btree_write_buffer_resize(struct bch_fs *, size_t);
 void bch2_fs_btree_write_buffer_exit(struct bch_fs *);
+void bch2_fs_btree_write_buffer_init_early(struct bch_fs *);
 int bch2_fs_btree_write_buffer_init(struct bch_fs *);
 
 #endif /* _BCACHEFS_BTREE_WRITE_BUFFER_H */
index e10f9b930aa6a1c278268a72dc8cdf5b3c40d15b..7522a618b9c97aa72ea9494c625b0b706cf37dac 100644 (file)
@@ -1588,7 +1588,7 @@ void bch2_fs_journal_exit(struct journal *j)
        free_fifo(&j->pin);
 }
 
-int bch2_fs_journal_init(struct journal *j)
+void bch2_fs_journal_init_early(struct journal *j)
 {
        static struct lock_class_key res_key;
 
@@ -1607,7 +1607,10 @@ int bch2_fs_journal_init(struct journal *j)
        atomic64_set(&j->reservations.counter,
                ((union journal_res_state)
                 { .cur_entry_offset = JOURNAL_ENTRY_CLOSED_VAL }).v);
+}
 
+int bch2_fs_journal_init(struct journal *j)
+{
        j->free_buf_size = j->buf_size_want = JOURNAL_ENTRY_SIZE_MIN;
        j->free_buf = kvmalloc(j->free_buf_size, GFP_KERNEL);
        if (!j->free_buf)
index 641e20c05a147d8cab51940a528492f1b748cc59..886ffd9c0db63a3c2370c25d0406998170d94f6a 100644 (file)
@@ -458,6 +458,7 @@ void bch2_journal_set_replay_done(struct journal *);
 void bch2_dev_journal_exit(struct bch_dev *);
 int bch2_dev_journal_init(struct bch_dev *, struct bch_sb *);
 void bch2_fs_journal_exit(struct journal *);
+void bch2_fs_journal_init_early(struct journal *);
 int bch2_fs_journal_init(struct journal *);
 
 #endif /* _BCACHEFS_JOURNAL_H */
index 3c21981a4a1c09f9c70596876ef71fdef72cddcb..962218fa68ec01eb942e91df40b0a8bd05921a19 100644 (file)
@@ -133,12 +133,10 @@ void bch2_fs_nocow_locking_exit(struct bch_fs *c)
                        BUG_ON(atomic_read(&l->l[j]));
 }
 
-int bch2_fs_nocow_locking_init(struct bch_fs *c)
+void bch2_fs_nocow_locking_init_early(struct bch_fs *c)
 {
        struct bucket_nocow_lock_table *t = &c->nocow_locks;
 
        for (struct nocow_lock_bucket *l = t->l; l < t->l + ARRAY_SIZE(t->l); l++)
                spin_lock_init(&l->lock);
-
-       return 0;
 }
index f9d6a426a960c4949902c72f2019bd76bd308676..48b8a003c0d25a5d29ee780a9d6705f2bf6034ec 100644 (file)
@@ -45,6 +45,6 @@ static inline bool bch2_bucket_nocow_trylock(struct bucket_nocow_lock_table *t,
 void bch2_nocow_locks_to_text(struct printbuf *, struct bucket_nocow_lock_table *);
 
 void bch2_fs_nocow_locking_exit(struct bch_fs *);
-int bch2_fs_nocow_locking_init(struct bch_fs *);
+void bch2_fs_nocow_locking_init_early(struct bch_fs *);
 
 #endif /* _BCACHEFS_NOCOW_LOCKING_H */
index 239ea783698c17a64eeb3d4e1dfdcbdff2b99cd3..0421ffc1128f99cfdccc689d8e4e34079aafbea9 100644 (file)
@@ -714,11 +714,10 @@ int bch2_fs_upgrade_for_subvolumes(struct bch_fs *c)
        return ret;
 }
 
-int bch2_fs_subvolumes_init(struct bch_fs *c)
+void bch2_fs_subvolumes_init_early(struct bch_fs *c)
 {
        INIT_WORK(&c->snapshot_delete_work, bch2_delete_dead_snapshots_work);
        INIT_WORK(&c->snapshot_wait_for_pagecache_and_delete_work,
                  bch2_subvolume_wait_for_pagecache_and_delete);
        mutex_init(&c->snapshots_unlinked_lock);
-       return 0;
 }
index f640c1e3d63909905fc64e4d8c1b792d607a47ae..ee5e4e5a0fc8db4a0132803152b520d440dcdb96 100644 (file)
@@ -86,6 +86,6 @@ int bch2_subvolume_create(struct btree_trans *, u64, u32, u32, u32 *, u32 *, boo
 int bch2_initialize_subvolumes(struct bch_fs *);
 int bch2_fs_upgrade_for_subvolumes(struct bch_fs *);
 
-int bch2_fs_subvolumes_init(struct bch_fs *);
+void bch2_fs_subvolumes_init_early(struct bch_fs *);
 
 #endif /* _BCACHEFS_SUBVOLUME_H */
index 93ba6fef40b81e50956c5f482451004ea0d60278..9cff32bde7a464628053cb0b48d4b1e17747f04a 100644 (file)
@@ -567,7 +567,6 @@ static void __bch2_fs_free(struct bch_fs *c)
        bch2_io_clock_exit(&c->io_clock[WRITE]);
        bch2_io_clock_exit(&c->io_clock[READ]);
        bch2_fs_compress_exit(c);
-       bch2_fs_btree_gc_exit(c);
        bch2_journal_keys_put_initial(c);
        bch2_find_btree_nodes_exit(&c->found_btree_nodes);
        BUG_ON(atomic_read(&c->journal_keys.ref));
@@ -783,16 +782,21 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
        bch2_fs_allocator_background_init(c);
        bch2_fs_allocator_foreground_init(c);
        bch2_fs_btree_cache_init_early(&c->btree_cache);
+       bch2_fs_btree_gc_init_early(c);
        bch2_fs_btree_interior_update_init_early(c);
        bch2_fs_btree_iter_init_early(c);
        bch2_fs_btree_key_cache_init_early(&c->btree_key_cache);
+       bch2_fs_btree_write_buffer_init_early(c);
        bch2_fs_copygc_init(c);
        bch2_fs_ec_init_early(c);
+       bch2_fs_journal_init_early(&c->journal);
        bch2_fs_journal_keys_init(c);
        bch2_fs_move_init(c);
+       bch2_fs_nocow_locking_init_early(c);
        bch2_fs_quota_init(c);
        bch2_fs_rebalance_init(c);
        bch2_fs_sb_errors_init_early(c);
+       bch2_fs_subvolumes_init_early(c);
 
        INIT_LIST_HEAD(&c->list);
 
@@ -906,7 +910,6 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
 
        ret =
            bch2_fs_btree_cache_init(c) ?:
-           bch2_fs_btree_gc_init(c) ?:
            bch2_fs_btree_iter_init(c) ?:
            bch2_fs_btree_interior_update_init(c) ?:
            bch2_fs_btree_key_cache_init(&c->btree_key_cache) ?:
@@ -924,9 +927,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
            bch2_fs_io_read_init(c) ?:
            bch2_fs_io_write_init(c) ?:
            bch2_fs_journal_init(&c->journal) ?:
-           bch2_fs_nocow_locking_init(c) ?:
            bch2_fs_sb_errors_init(c) ?:
-           bch2_fs_subvolumes_init(c) ?:
            bch2_fs_vfs_init(c);
        if (ret)
                goto err;