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 39974f4b441f3ecc39cfb5a25f6d98268e4ea5cc..fec3d618bcefc37d7ac7c424af2334edb7beb912 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 8cae730bd5ba1bf50801619a13e80a88286faf92..54f50784aefa001320c942b6557db689560000e0 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 5942b93840884564d24477da400c04e49dbe1c7f..8fe2fdb167a71331c4186ca688d3e9b905e6d3bc 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 d1f1da6820fb0d51ee8deb349ffb42a3e57e59fe..ae7d4aca771d7246e069a36b029b8245a122b4a4 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 970ff316069dd238789b844a554567bdd795f75d..1332f193b800322e4c76f70bc729786620b9f4c8 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