btrfs: move trans_handle_cachep out of ctree.h
authorJosef Bacik <josef@toxicpanda.com>
Wed, 14 Sep 2022 15:06:37 +0000 (11:06 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 5 Dec 2022 17:00:37 +0000 (18:00 +0100)
This is local to the transaction code, remove it from ctree.h and
inode.c, create new helpers in the transaction to handle the init work
and move the cachep locally to transaction.c.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.h
fs/btrfs/inode.c
fs/btrfs/super.c
fs/btrfs/transaction.c
fs/btrfs/transaction.h

index 39974f4..fec3d61 100644 (file)
@@ -41,7 +41,6 @@ struct btrfs_pending_snapshot;
 struct btrfs_delayed_ref_root;
 struct btrfs_space_info;
 struct btrfs_block_group;
-extern struct kmem_cache *btrfs_trans_handle_cachep;
 extern struct kmem_cache *btrfs_path_cachep;
 extern struct kmem_cache *btrfs_free_space_cachep;
 extern struct kmem_cache *btrfs_free_space_bitmap_cachep;
index 8cae730..54f5078 100644 (file)
@@ -107,7 +107,6 @@ static const struct address_space_operations btrfs_aops;
 static const struct file_operations btrfs_dir_file_operations;
 
 static struct kmem_cache *btrfs_inode_cachep;
-struct kmem_cache *btrfs_trans_handle_cachep;
 struct kmem_cache *btrfs_path_cachep;
 struct kmem_cache *btrfs_free_space_cachep;
 struct kmem_cache *btrfs_free_space_bitmap_cachep;
@@ -8926,7 +8925,6 @@ void __cold btrfs_destroy_cachep(void)
        rcu_barrier();
        bioset_exit(&btrfs_dio_bioset);
        kmem_cache_destroy(btrfs_inode_cachep);
-       kmem_cache_destroy(btrfs_trans_handle_cachep);
        kmem_cache_destroy(btrfs_path_cachep);
        kmem_cache_destroy(btrfs_free_space_cachep);
        kmem_cache_destroy(btrfs_free_space_bitmap_cachep);
@@ -8941,12 +8939,6 @@ int __init btrfs_init_cachep(void)
        if (!btrfs_inode_cachep)
                goto fail;
 
-       btrfs_trans_handle_cachep = kmem_cache_create("btrfs_trans_handle",
-                       sizeof(struct btrfs_trans_handle), 0,
-                       SLAB_TEMPORARY | SLAB_MEM_SPREAD, NULL);
-       if (!btrfs_trans_handle_cachep)
-               goto fail;
-
        btrfs_path_cachep = kmem_cache_create("btrfs_path",
                        sizeof(struct btrfs_path), 0,
                        SLAB_MEM_SPREAD, NULL);
index 5942b93..8fe2fdb 100644 (file)
@@ -2739,10 +2739,14 @@ static int __init init_btrfs_fs(void)
        if (err)
                goto free_compress;
 
-       err = extent_state_init_cachep();
+       err = btrfs_transaction_init();
        if (err)
                goto free_cachep;
 
+       err = extent_state_init_cachep();
+       if (err)
+               goto free_transaction;
+
        err = extent_buffer_init_cachep();
        if (err)
                goto free_extent_cachep;
@@ -2811,6 +2815,8 @@ free_eb_cachep:
        extent_buffer_free_cachep();
 free_extent_cachep:
        extent_state_free_cachep();
+free_transaction:
+       btrfs_transaction_exit();
 free_cachep:
        btrfs_destroy_cachep();
 free_compress:
@@ -2822,6 +2828,7 @@ free_compress:
 
 static void __exit exit_btrfs_fs(void)
 {
+       btrfs_transaction_exit();
        btrfs_destroy_cachep();
        btrfs_delayed_ref_exit();
        btrfs_auto_defrag_exit();
index d1f1da6..ae7d4ac 100644 (file)
@@ -24,6 +24,8 @@
 #include "space-info.h"
 #include "zoned.h"
 
+static struct kmem_cache *btrfs_trans_handle_cachep;
+
 #define BTRFS_ROOT_TRANS_TAG 0
 
 /*
@@ -2600,3 +2602,18 @@ void btrfs_apply_pending_changes(struct btrfs_fs_info *fs_info)
                btrfs_warn(fs_info,
                        "unknown pending changes left 0x%lx, ignoring", prev);
 }
+
+int __init btrfs_transaction_init(void)
+{
+       btrfs_trans_handle_cachep = kmem_cache_create("btrfs_trans_handle",
+                       sizeof(struct btrfs_trans_handle), 0,
+                       SLAB_TEMPORARY | SLAB_MEM_SPREAD, NULL);
+       if (!btrfs_trans_handle_cachep)
+               return -ENOMEM;
+       return 0;
+}
+
+void __cold btrfs_transaction_exit(void)
+{
+       kmem_cache_destroy(btrfs_trans_handle_cachep);
+}
index 970ff31..1332f19 100644 (file)
@@ -236,4 +236,7 @@ void btrfs_add_dropped_root(struct btrfs_trans_handle *trans,
                            struct btrfs_root *root);
 void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans);
 
+int __init btrfs_transaction_init(void);
+void __cold btrfs_transaction_exit(void);
+
 #endif