[PATCH 05/31] btrfs: separate out the extent state and extent buffer init code

Josef Bacik
2022-09-02T20:17:08Z

In order to help separate the extent buffer from the extent io tree code
we need to break up the init functions.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
fs/btrfs/extent-io-tree.h | 4 ++--
fs/btrfs/extent_io.c | 21 ++++++++++++++-------
fs/btrfs/extent_io.h | 3 +++
fs/btrfs/super.c | 17 ++++++++++++-----
4 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h
index ee2ba4b6e4a1..6c2016db304b 100644
--- a/fs/btrfs/extent-io-tree.h
+++ b/fs/btrfs/extent-io-tree.h
@@ -108,8 +108,8 @@ static inline int lock_extent(struct extent_io_tree *tree, u64 start, u64 end)

int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end);

-int __init extent_io_init(void);
-void __cold extent_io_exit(void);
+int __init extent_state_init_cachep(void);
+void __cold extent_state_free_cachep(void);

u64 count_range_bits(struct extent_io_tree *tree,
u64 *start, u64 search_end,
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 598cb66f65df..d95f0779676b 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -230,7 +230,7 @@ static void submit_write_bio(struct extent_page_data *epd, int ret)
}
}

-int __init extent_io_init(void)
+int __init extent_state_init_cachep(void)
{
extent_state_cache = kmem_cache_create("btrfs_extent_state",
sizeof(struct extent_state), 0,
@@ -238,18 +238,27 @@ int __init extent_io_init(void)
if (!extent_state_cache)
return -ENOMEM;

+ return 0;
+}
+
+int __init extent_buffer_init_cachep(void)
+{
extent_buffer_cache = kmem_cache_create("btrfs_extent_buffer",
sizeof(struct extent_buffer), 0,
SLAB_MEM_SPREAD, NULL);
- if (!extent_buffer_cache) {
- kmem_cache_destroy(extent_state_cache);
+ if (!extent_buffer_cache)
return -ENOMEM;
- }

return 0;
}

-void __cold extent_io_exit(void)
+void __cold extent_state_free_cachep(void)
+{
+ btrfs_extent_state_leak_debug_check();
+ kmem_cache_destroy(extent_state_cache);
+}
+
+void __cold extent_buffer_free_cachep(void)
{
/*
* Make sure all delayed rcu free are flushed before we
@@ -257,8 +266,6 @@ void __cold extent_io_exit(void)
*/
rcu_barrier();
kmem_cache_destroy(extent_buffer_cache);
- btrfs_extent_state_leak_debug_check();
- kmem_cache_destroy(extent_state_cache);
}

/*
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index 879f8a60cd6f..52e4dfea2164 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -64,6 +64,9 @@ struct btrfs_fs_info;
struct io_failure_record;
struct extent_io_tree;

+int __init extent_buffer_init_cachep(void);
+void __cold extent_buffer_free_cachep(void);
+
typedef void (submit_bio_hook_t)(struct inode *inode, struct bio *bio,
int mirror_num,
enum btrfs_compression_type compress_type);
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 767b86e7fe82..1593d4479dde 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -2736,13 +2736,17 @@ static int __init init_btrfs_fs(void)
if (err)
goto free_compress;

- err = extent_io_init();
+ err = extent_state_init_cachep();
if (err)
goto free_cachep;

+ err = extent_buffer_init_cachep();
+ if (err)
+ goto free_extent_cachep;
+
err = btrfs_bioset_init();
if (err)
- goto free_extent_io;
+ goto free_eb_cachep;

err = extent_map_init();
if (err)
@@ -2800,8 +2804,10 @@ static int __init init_btrfs_fs(void)
extent_map_exit();
free_bioset:
btrfs_bioset_exit();
-free_extent_io:
- extent_io_exit();
+free_eb_cachep:
+ extent_buffer_free_cachep();
+free_extent_cachep:
+ extent_state_free_cachep();
free_cachep:
btrfs_destroy_cachep();
free_compress:
@@ -2821,7 +2827,8 @@ static void __exit exit_btrfs_fs(void)
ordered_data_exit();
extent_map_exit();
btrfs_bioset_exit();
- extent_io_exit();
+ extent_state_free_cachep();
+ extent_buffer_free_cachep();
btrfs_interface_exit();
unregister_filesystem(&btrfs_fs_type);
btrfs_exit_sysfs();
--
2.26.3