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 2/4] btrfs: Use module_subinit{_noexit} and module_subeixt helper macros
Date: Tue, 23 Jul 2024 16:32:37 +0800 [thread overview]
Message-ID: <20240723083239.41533-3-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/btrfs/super.c | 123 +++++++++--------------------------------------
1 file changed, 23 insertions(+), 100 deletions(-)
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 08d33cb372fb..620493b3f319 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -2490,115 +2490,38 @@ static void unregister_btrfs(void)
unregister_filesystem(&btrfs_fs_type);
}
-/* Helper structure for long init/exit functions. */
-struct init_sequence {
- int (*init_func)(void);
- /* Can be NULL if the init_func doesn't need cleanup. */
- void (*exit_func)(void);
-};
-
-static const struct init_sequence mod_init_seq[] = {
- {
- .init_func = btrfs_props_init,
- .exit_func = NULL,
- }, {
- .init_func = btrfs_init_sysfs,
- .exit_func = btrfs_exit_sysfs,
- }, {
- .init_func = btrfs_init_compress,
- .exit_func = btrfs_exit_compress,
- }, {
- .init_func = btrfs_init_cachep,
- .exit_func = btrfs_destroy_cachep,
- }, {
- .init_func = btrfs_init_dio,
- .exit_func = btrfs_destroy_dio,
- }, {
- .init_func = btrfs_transaction_init,
- .exit_func = btrfs_transaction_exit,
- }, {
- .init_func = btrfs_ctree_init,
- .exit_func = btrfs_ctree_exit,
- }, {
- .init_func = btrfs_free_space_init,
- .exit_func = btrfs_free_space_exit,
- }, {
- .init_func = extent_state_init_cachep,
- .exit_func = extent_state_free_cachep,
- }, {
- .init_func = extent_buffer_init_cachep,
- .exit_func = extent_buffer_free_cachep,
- }, {
- .init_func = btrfs_bioset_init,
- .exit_func = btrfs_bioset_exit,
- }, {
- .init_func = extent_map_init,
- .exit_func = extent_map_exit,
- }, {
- .init_func = ordered_data_init,
- .exit_func = ordered_data_exit,
- }, {
- .init_func = btrfs_delayed_inode_init,
- .exit_func = btrfs_delayed_inode_exit,
- }, {
- .init_func = btrfs_auto_defrag_init,
- .exit_func = btrfs_auto_defrag_exit,
- }, {
- .init_func = btrfs_delayed_ref_init,
- .exit_func = btrfs_delayed_ref_exit,
- }, {
- .init_func = btrfs_prelim_ref_init,
- .exit_func = btrfs_prelim_ref_exit,
- }, {
- .init_func = btrfs_interface_init,
- .exit_func = btrfs_interface_exit,
- }, {
- .init_func = btrfs_print_mod_info,
- .exit_func = NULL,
- }, {
- .init_func = btrfs_run_sanity_tests,
- .exit_func = NULL,
- }, {
- .init_func = register_btrfs,
- .exit_func = unregister_btrfs,
- }
-};
-
-static bool mod_init_result[ARRAY_SIZE(mod_init_seq)];
-
-static __always_inline void btrfs_exit_btrfs_fs(void)
-{
- int i;
-
- for (i = ARRAY_SIZE(mod_init_seq) - 1; i >= 0; i--) {
- if (!mod_init_result[i])
- continue;
- if (mod_init_seq[i].exit_func)
- mod_init_seq[i].exit_func();
- mod_init_result[i] = false;
- }
-}
+static struct subexitcall_rollback rollback;
static void __exit exit_btrfs_fs(void)
{
- btrfs_exit_btrfs_fs();
+ module_subexit(&rollback);
btrfs_cleanup_fs_uuids();
}
static int __init init_btrfs_fs(void)
{
- int ret;
- int i;
+ module_subinit_noexit(btrfs_props_init, &rollback);
+ module_subinit(btrfs_init_sysfs, btrfs_exit_sysfs, &rollback);
+ module_subinit(btrfs_init_compress, btrfs_exit_compress, &rollback);
+ module_subinit(btrfs_init_cachep, btrfs_destroy_cachep, &rollback);
+ module_subinit(btrfs_init_dio, btrfs_destroy_dio, &rollback);
+ module_subinit(btrfs_transaction_init, btrfs_transaction_exit, &rollback);
+ module_subinit(btrfs_ctree_init, btrfs_ctree_exit, &rollback);
+ module_subinit(btrfs_free_space_init, btrfs_free_space_exit, &rollback);
+ module_subinit(extent_state_init_cachep, extent_state_free_cachep, &rollback);
+ module_subinit(extent_buffer_init_cachep, extent_buffer_free_cachep, &rollback);
+ module_subinit(btrfs_bioset_init, btrfs_bioset_exit, &rollback);
+ module_subinit(extent_map_init, extent_map_exit, &rollback);
+ module_subinit(ordered_data_init, ordered_data_exit, &rollback);
+ module_subinit(btrfs_delayed_inode_init, btrfs_delayed_inode_exit, &rollback);
+ module_subinit(btrfs_auto_defrag_init, btrfs_auto_defrag_exit, &rollback);
+ module_subinit(btrfs_delayed_ref_init, btrfs_delayed_ref_exit, &rollback);
+ module_subinit(btrfs_prelim_ref_init, btrfs_prelim_ref_exit, &rollback);
+ module_subinit(btrfs_interface_init, btrfs_interface_exit, &rollback);
+ module_subinit_noexit(btrfs_print_mod_info, &rollback);
+ module_subinit_noexit(btrfs_run_sanity_tests, &rollback);
+ module_subinit(register_btrfs, unregister_btrfs, &rollback);
- for (i = 0; i < ARRAY_SIZE(mod_init_seq); i++) {
- ASSERT(!mod_init_result[i]);
- ret = mod_init_seq[i].init_func();
- if (ret < 0) {
- btrfs_exit_btrfs_fs();
- return ret;
- }
- mod_init_result[i] = true;
- }
return 0;
}
--
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 ` Youling Tang [this message]
2024-07-23 22:24 ` [f2fs-dev] [PATCH 2/4] btrfs: Use " 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 ` [f2fs-dev] [PATCH 4/4] f2fs: Use module_{subinit, subeixt} " Youling Tang
2024-07-23 18:51 ` 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-3-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).