From: Youling Tang <youling.tang@linux.dev>
To: Arnd Bergmann <arnd@arndb.de>,
Luis Chamberlain <mcgrof@kernel.org>, Chris Mason <clm@fb.com>,
Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>,
tytso@mit.edu, Andreas Dilger <adilger.kernel@dilger.ca>,
Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <chao@kernel.org>,
Christoph Hellwig <hch@infradead.org>
Cc: linux-arch@vger.kernel.org, Youling Tang <tangyouling@kylinos.cn>,
linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net,
linux-modules@vger.kernel.org, youling.tang@linux.dev,
linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org
Subject: [f2fs-dev] [PATCH 4/4] f2fs: Use module_{subinit, subeixt} helper macros
Date: Tue, 23 Jul 2024 16:32:39 +0800 [thread overview]
Message-ID: <20240723083239.41533-5-youling.tang@linux.dev> (raw)
In-Reply-To: <20240723083239.41533-1-youling.tang@linux.dev>
From: Youling Tang <tangyouling@kylinos.cn>
Use module_{subinit, subinit} to ensure that modules init and exit
are in sequence and to simplify the code.
Signed-off-by: Youling Tang <tangyouling@kylinos.cn>
---
fs/f2fs/debug.c | 3 +-
fs/f2fs/f2fs.h | 4 +-
fs/f2fs/super.c | 139 +++++++++++-------------------------------------
3 files changed, 36 insertions(+), 110 deletions(-)
diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
index 8b0e1e71b667..c08ecf807066 100644
--- a/fs/f2fs/debug.c
+++ b/fs/f2fs/debug.c
@@ -727,7 +727,7 @@ void f2fs_destroy_stats(struct f2fs_sb_info *sbi)
kfree(si);
}
-void __init f2fs_create_root_stats(void)
+int __init f2fs_create_root_stats(void)
{
#ifdef CONFIG_DEBUG_FS
f2fs_debugfs_root = debugfs_create_dir("f2fs", NULL);
@@ -735,6 +735,7 @@ void __init f2fs_create_root_stats(void)
debugfs_create_file("status", 0444, f2fs_debugfs_root, NULL,
&stat_fops);
#endif
+ return 0;
}
void f2fs_destroy_root_stats(void)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 8a9d910aa552..b2909383bcd9 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -4100,7 +4100,7 @@ static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
int f2fs_build_stats(struct f2fs_sb_info *sbi);
void f2fs_destroy_stats(struct f2fs_sb_info *sbi);
-void __init f2fs_create_root_stats(void);
+int __init f2fs_create_root_stats(void);
void f2fs_destroy_root_stats(void);
void f2fs_update_sit_info(struct f2fs_sb_info *sbi);
#else
@@ -4142,7 +4142,7 @@ void f2fs_update_sit_info(struct f2fs_sb_info *sbi);
static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
-static inline void __init f2fs_create_root_stats(void) { }
+static inline int __init f2fs_create_root_stats(void) { }
static inline void f2fs_destroy_root_stats(void) { }
static inline void f2fs_update_sit_info(struct f2fs_sb_info *sbi) {}
#endif
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index df4cf31f93df..162ec1005b22 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -4940,120 +4940,45 @@ static void destroy_inodecache(void)
kmem_cache_destroy(f2fs_inode_cachep);
}
-static int __init init_f2fs_fs(void)
+static int register_f2fs(void)
{
- int err;
+ return register_filesystem(&f2fs_fs_type);
+}
- err = init_inodecache();
- if (err)
- goto fail;
- err = f2fs_create_node_manager_caches();
- if (err)
- goto free_inodecache;
- err = f2fs_create_segment_manager_caches();
- if (err)
- goto free_node_manager_caches;
- err = f2fs_create_checkpoint_caches();
- if (err)
- goto free_segment_manager_caches;
- err = f2fs_create_recovery_cache();
- if (err)
- goto free_checkpoint_caches;
- err = f2fs_create_extent_cache();
- if (err)
- goto free_recovery_cache;
- err = f2fs_create_garbage_collection_cache();
- if (err)
- goto free_extent_cache;
- err = f2fs_init_sysfs();
- if (err)
- goto free_garbage_collection_cache;
- err = f2fs_init_shrinker();
- if (err)
- goto free_sysfs;
- err = register_filesystem(&f2fs_fs_type);
- if (err)
- goto free_shrinker;
- f2fs_create_root_stats();
- err = f2fs_init_post_read_processing();
- if (err)
- goto free_root_stats;
- err = f2fs_init_iostat_processing();
- if (err)
- goto free_post_read;
- err = f2fs_init_bio_entry_cache();
- if (err)
- goto free_iostat;
- err = f2fs_init_bioset();
- if (err)
- goto free_bio_entry_cache;
- err = f2fs_init_compress_mempool();
- if (err)
- goto free_bioset;
- err = f2fs_init_compress_cache();
- if (err)
- goto free_compress_mempool;
- err = f2fs_create_casefold_cache();
- if (err)
- goto free_compress_cache;
- return 0;
-free_compress_cache:
- f2fs_destroy_compress_cache();
-free_compress_mempool:
- f2fs_destroy_compress_mempool();
-free_bioset:
- f2fs_destroy_bioset();
-free_bio_entry_cache:
- f2fs_destroy_bio_entry_cache();
-free_iostat:
- f2fs_destroy_iostat_processing();
-free_post_read:
- f2fs_destroy_post_read_processing();
-free_root_stats:
- f2fs_destroy_root_stats();
+static void unregister_f2fs(void)
+{
unregister_filesystem(&f2fs_fs_type);
-free_shrinker:
- f2fs_exit_shrinker();
-free_sysfs:
- f2fs_exit_sysfs();
-free_garbage_collection_cache:
- f2fs_destroy_garbage_collection_cache();
-free_extent_cache:
- f2fs_destroy_extent_cache();
-free_recovery_cache:
- f2fs_destroy_recovery_cache();
-free_checkpoint_caches:
- f2fs_destroy_checkpoint_caches();
-free_segment_manager_caches:
- f2fs_destroy_segment_manager_caches();
-free_node_manager_caches:
- f2fs_destroy_node_manager_caches();
-free_inodecache:
- destroy_inodecache();
-fail:
- return err;
}
+static struct subexitcall_rollback rollback;
+
static void __exit exit_f2fs_fs(void)
{
- f2fs_destroy_casefold_cache();
- f2fs_destroy_compress_cache();
- f2fs_destroy_compress_mempool();
- f2fs_destroy_bioset();
- f2fs_destroy_bio_entry_cache();
- f2fs_destroy_iostat_processing();
- f2fs_destroy_post_read_processing();
- f2fs_destroy_root_stats();
- unregister_filesystem(&f2fs_fs_type);
- f2fs_exit_shrinker();
- f2fs_exit_sysfs();
- f2fs_destroy_garbage_collection_cache();
- f2fs_destroy_extent_cache();
- f2fs_destroy_recovery_cache();
- f2fs_destroy_checkpoint_caches();
- f2fs_destroy_segment_manager_caches();
- f2fs_destroy_node_manager_caches();
- destroy_inodecache();
+ module_subexit(&rollback);
+}
+
+static int __init init_f2fs_fs(void)
+{
+ module_subinit(init_inodecache, destroy_inodecache, &rollback);
+ module_subinit(f2fs_create_node_manager_caches, f2fs_destroy_node_manager_caches, &rollback);
+ module_subinit(f2fs_create_segment_manager_caches, f2fs_destroy_segment_manager_caches, &rollback);
+ module_subinit(f2fs_create_checkpoint_caches, f2fs_destroy_checkpoint_caches, &rollback);
+ module_subinit(f2fs_create_recovery_cache, f2fs_destroy_recovery_cache, &rollback);
+ module_subinit(f2fs_create_extent_cache, f2fs_destroy_extent_cache, &rollback);
+ module_subinit(f2fs_create_garbage_collection_cache, f2fs_destroy_garbage_collection_cache, &rollback);
+ module_subinit(f2fs_init_sysfs, f2fs_exit_sysfs, &rollback);
+ module_subinit(f2fs_init_shrinker, f2fs_exit_shrinker, &rollback);
+ module_subinit(register_f2fs, unregister_f2fs, &rollback);
+ module_subinit(f2fs_create_root_stats, f2fs_destroy_root_stats, &rollback);
+ module_subinit(f2fs_init_post_read_processing, f2fs_destroy_post_read_processing, &rollback);
+ module_subinit(f2fs_init_iostat_processing, f2fs_destroy_iostat_processing, &rollback);
+ module_subinit(f2fs_init_bio_entry_cache, f2fs_destroy_bio_entry_cache, &rollback);
+ module_subinit(f2fs_init_bioset, f2fs_destroy_bioset, &rollback);
+ module_subinit(f2fs_init_compress_mempool, f2fs_destroy_compress_mempool, &rollback);
+ module_subinit(f2fs_init_compress_cache, f2fs_destroy_compress_cache, &rollback);
+ module_subinit(f2fs_create_casefold_cache, f2fs_destroy_casefold_cache, &rollback);
+
+ return 0;
}
module_init(init_f2fs_fs)
--
2.34.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2024-07-23 8:33 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-23 8:32 [f2fs-dev] [PATCH 0/4] Add module_subinit{_noexit} and module_subeixt helper macros Youling Tang
2024-07-23 8:32 ` [f2fs-dev] [PATCH 1/4] module: " Youling Tang
2024-07-23 9:58 ` Mika Penttilä
2024-07-24 1:20 ` Youling Tang
2024-07-23 14:33 ` Christoph Hellwig
2024-07-24 1:57 ` Youling Tang
2024-07-24 15:43 ` Christoph Hellwig
2024-07-25 3:01 ` Youling Tang
2024-07-25 14:39 ` Christoph Hellwig
2024-07-25 15:30 ` Arnd Bergmann
2024-07-25 15:34 ` Christoph Hellwig
2024-07-25 17:14 ` Goffredo Baroncelli via Linux-f2fs-devel
2024-07-25 19:46 ` Christoph Hellwig
2024-07-26 8:54 ` Youling Tang
2024-07-26 14:04 ` Christoph Hellwig
2024-07-26 15:22 ` David Sterba
2024-07-26 17:58 ` Theodore Ts'o
2024-07-26 18:09 ` Christoph Hellwig
2024-07-26 22:45 ` David Sterba
2024-07-27 14:52 ` Theodore Ts'o
2024-07-29 1:46 ` Youling Tang
2024-07-29 2:44 ` Theodore Ts'o
2024-07-29 3:01 ` Youling Tang
2024-07-29 18:57 ` Christoph Hellwig
2024-07-23 8:32 ` [f2fs-dev] [PATCH 2/4] btrfs: Use " Youling Tang
2024-07-23 22:24 ` kernel test robot
2024-07-24 6:29 ` Youling Tang
2024-07-23 8:32 ` [f2fs-dev] [PATCH 3/4] ext4: Use module_{subinit, subexit} " Youling Tang
2024-07-23 8:32 ` Youling Tang [this message]
2024-07-23 18:51 ` [f2fs-dev] [PATCH 4/4] f2fs: Use module_{subinit, subeixt} " kernel test robot
2024-07-24 2:14 ` Youling Tang
2024-07-23 21:31 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240723083239.41533-5-youling.tang@linux.dev \
--to=youling.tang@linux.dev \
--cc=adilger.kernel@dilger.ca \
--cc=arnd@arndb.de \
--cc=chao@kernel.org \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=hch@infradead.org \
--cc=jaegeuk@kernel.org \
--cc=josef@toxicpanda.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=tangyouling@kylinos.cn \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).