linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
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 3/4] ext4: Use module_{subinit, subexit} helper macros
Date: Tue, 23 Jul 2024 16:32:38 +0800	[thread overview]
Message-ID: <20240723083239.41533-4-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/ext4/super.c | 115 ++++++++++++++----------------------------------
 1 file changed, 33 insertions(+), 82 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index e72145c4ae5a..207076e7e7f0 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -7302,103 +7302,54 @@ static struct file_system_type ext4_fs_type = {
 };
 MODULE_ALIAS_FS("ext4");
 
+static int register_ext(void)
+{
+	register_as_ext3();
+	register_as_ext2();
+	return register_filesystem(&ext4_fs_type);
+}
+
+static void unregister_ext(void)
+{
+	unregister_as_ext2();
+	unregister_as_ext3();
+	unregister_filesystem(&ext4_fs_type);
+}
+
+static struct subexitcall_rollback rollback;
+
+static void __exit ext4_exit_fs(void)
+{
+	ext4_destroy_lazyinit_thread();
+	module_subexit(&rollback);
+}
+
 /* Shared across all ext4 file systems */
 wait_queue_head_t ext4__ioend_wq[EXT4_WQ_HASH_SZ];
 
 static int __init ext4_init_fs(void)
 {
-	int i, err;
-
 	ratelimit_state_init(&ext4_mount_msg_ratelimit, 30 * HZ, 64);
 	ext4_li_info = NULL;
 
 	/* Build-time check for flags consistency */
 	ext4_check_flag_values();
 
-	for (i = 0; i < EXT4_WQ_HASH_SZ; i++)
+	for (int i = 0; i < EXT4_WQ_HASH_SZ; i++)
 		init_waitqueue_head(&ext4__ioend_wq[i]);
 
-	err = ext4_init_es();
-	if (err)
-		return err;
-
-	err = ext4_init_pending();
-	if (err)
-		goto out7;
-
-	err = ext4_init_post_read_processing();
-	if (err)
-		goto out6;
-
-	err = ext4_init_pageio();
-	if (err)
-		goto out5;
-
-	err = ext4_init_system_zone();
-	if (err)
-		goto out4;
-
-	err = ext4_init_sysfs();
-	if (err)
-		goto out3;
-
-	err = ext4_init_mballoc();
-	if (err)
-		goto out2;
-	err = init_inodecache();
-	if (err)
-		goto out1;
-
-	err = ext4_fc_init_dentry_cache();
-	if (err)
-		goto out05;
-
-	register_as_ext3();
-	register_as_ext2();
-	err = register_filesystem(&ext4_fs_type);
-	if (err)
-		goto out;
+	module_subinit(ext4_init_es, ext4_exit_es, &rollback);
+	module_subinit(ext4_init_pending, ext4_exit_pending, &rollback);
+	module_subinit(ext4_init_post_read_processing, ext4_exit_post_read_processing, &rollback);
+	module_subinit(ext4_init_pageio, ext4_exit_pageio, &rollback);
+	module_subinit(ext4_init_system_zone, ext4_exit_system_zone, &rollback);
+	module_subinit(ext4_init_sysfs, ext4_exit_sysfs, &rollback);
+	module_subinit(ext4_init_mballoc, ext4_exit_mballoc, &rollback);
+	module_subinit(init_inodecache, destroy_inodecache, &rollback);
+	module_subinit(ext4_fc_init_dentry_cache, ext4_fc_destroy_dentry_cache, &rollback);
+	module_subinit(register_ext, unregister_ext, &rollback);
 
 	return 0;
-out:
-	unregister_as_ext2();
-	unregister_as_ext3();
-	ext4_fc_destroy_dentry_cache();
-out05:
-	destroy_inodecache();
-out1:
-	ext4_exit_mballoc();
-out2:
-	ext4_exit_sysfs();
-out3:
-	ext4_exit_system_zone();
-out4:
-	ext4_exit_pageio();
-out5:
-	ext4_exit_post_read_processing();
-out6:
-	ext4_exit_pending();
-out7:
-	ext4_exit_es();
-
-	return err;
-}
-
-static void __exit ext4_exit_fs(void)
-{
-	ext4_destroy_lazyinit_thread();
-	unregister_as_ext2();
-	unregister_as_ext3();
-	unregister_filesystem(&ext4_fs_type);
-	ext4_fc_destroy_dentry_cache();
-	destroy_inodecache();
-	ext4_exit_mballoc();
-	ext4_exit_sysfs();
-	ext4_exit_system_zone();
-	ext4_exit_pageio();
-	ext4_exit_post_read_processing();
-	ext4_exit_es();
-	ext4_exit_pending();
 }
 
 MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
-- 
2.34.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

  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 ` Youling Tang [this message]
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-4-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).