From patchwork Tue Jul 23 08:32:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Youling Tang X-Patchwork-Id: 13739708 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A240AC3DA63 for ; Tue, 23 Jul 2024 08:33:18 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sWAxS-0003Y5-9I; Tue, 23 Jul 2024 08:33:18 +0000 Received: from [172.30.29.67] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sWAxR-0003Xz-0d for linux-f2fs-devel@lists.sourceforge.net; Tue, 23 Jul 2024 08:33:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=3VCZOZWRmGd8xL5SN+J0EY1zI5GAsbkGIgLsBKI32rY=; b=SCkEdYs0STtsBLLyZwKO2PqaJ4 WX8yuSjcxEsnlzbcw0UJ//3qx1j0KYgXuGvxU6yE5krqxm+gVIcnObL+6VFM5Aw0O9/OyqDXlNHqE VAWf/McnFNuAFXfE9rRHjKJSp1I8RAdYZw9qjZe+ah0UDCIxI7hkcuZ1GfZHV5kSGwqo=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=3VCZOZWRmGd8xL5SN+J0EY1zI5GAsbkGIgLsBKI32rY=; b=RjtdkOreP0i7gEMS0q65NbVXVk Ymq/imSRLwHf7i0zECxqPlpnd33EYq5NyPsmfcElTwQXUHbdHWK0L9a8GI6CO3qYFlCo0+aZ7DEyD tBOk7WgsXFgtV4mp+RwiNEH6zvNdSb+GYhzu7pjnxmkiaq5pTTvwuTZrf9RvlCZ2b8CE=; Received: from out-177.mta0.migadu.com ([91.218.175.177]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sWAxP-0003rW-Nj for linux-f2fs-devel@lists.sourceforge.net; Tue, 23 Jul 2024 08:33:16 +0000 X-Envelope-To: arnd@arndb.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1721723584; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3VCZOZWRmGd8xL5SN+J0EY1zI5GAsbkGIgLsBKI32rY=; b=cQx+gVTPFpYaKvaHYXeReUXRhKDPTWx/sb5DeYOwR8gRsNRrwJFY99FHH1UzFuoA6giSAU /S7ZkQOGJ63xrCh96+rIE9S1wWbRPni1uyscrvGEAXhmVxohVvd7OpcuqyO8XTXotjZH2w UFvUkVqKYobrZYhSNeojetonj1chNhg= X-Envelope-To: mcgrof@kernel.org X-Envelope-To: clm@fb.com X-Envelope-To: josef@toxicpanda.com X-Envelope-To: dsterba@suse.com X-Envelope-To: tytso@mit.edu X-Envelope-To: adilger.kernel@dilger.ca X-Envelope-To: jaegeuk@kernel.org X-Envelope-To: chao@kernel.org X-Envelope-To: hch@infradead.org X-Envelope-To: linux-arch@vger.kernel.org X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: linux-modules@vger.kernel.org X-Envelope-To: linux-btrfs@vger.kernel.org X-Envelope-To: linux-ext4@vger.kernel.org X-Envelope-To: linux-f2fs-devel@lists.sourceforge.net X-Envelope-To: youling.tang@linux.dev X-Envelope-To: tangyouling@kylinos.cn X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Youling Tang To: Arnd Bergmann , Luis Chamberlain , Chris Mason , Josef Bacik , David Sterba , tytso@mit.edu, Andreas Dilger , Jaegeuk Kim , Chao Yu , Christoph Hellwig Date: Tue, 23 Jul 2024 16:32:36 +0800 Message-Id: <20240723083239.41533-2-youling.tang@linux.dev> In-Reply-To: <20240723083239.41533-1-youling.tang@linux.dev> References: <20240723083239.41533-1-youling.tang@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Headers-End: 1sWAxP-0003rW-Nj Subject: [f2fs-dev] [PATCH 1/4] module: Add module_subinit{_noexit} and module_subeixt helper macros X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Youling Tang , 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 Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Youling Tang In theory init/exit should match their sequence, thus normally they should look like this: -------------------------+------------------------ init_A(); | init_B(); | init_C(); | | exit_C(); | exit_B(); | exit_A(); Providing module_subinit{_noexit} and module_subeixt helps macros ensure that modules init/exit match their order, while also simplifying the code. The three macros are defined as follows: - module_subinit(initfn, exitfn,rollback) - module_subinit_noexit(initfn, rollback) - module_subexit(rollback) `initfn` is the initialization function and `exitfn` is the corresponding exit function. Signed-off-by: Youling Tang --- include/asm-generic/vmlinux.lds.h | 5 +++ include/linux/init.h | 62 ++++++++++++++++++++++++++++++- include/linux/module.h | 22 +++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 677315e51e54..48ccac7c6448 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -927,6 +927,10 @@ INIT_CALLS_LEVEL(7) \ __initcall_end = .; +#define SUBINIT_CALL \ + *(.subinitcall.init) \ + *(.subexitcall.exit) + #define CON_INITCALL \ BOUNDED_SECTION_POST_LABEL(.con_initcall.init, __con_initcall, _start, _end) @@ -1155,6 +1159,7 @@ INIT_DATA \ INIT_SETUP(initsetup_align) \ INIT_CALLS \ + SUBINIT_CALL \ CON_INITCALL \ INIT_RAM_FS \ } diff --git a/include/linux/init.h b/include/linux/init.h index ee1309473bc6..e8689ff2cb6c 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -55,6 +55,9 @@ #define __exitdata __section(".exit.data") #define __exit_call __used __section(".exitcall.exit") +#define __subinit_call __used __section(".subinitcall.init") +#define __subexit_call __used __section(".subexitcall.exit") + /* * modpost check for section mismatches during the kernel build. * A section mismatch happens when there are references from a @@ -115,6 +118,9 @@ typedef int (*initcall_t)(void); typedef void (*exitcall_t)(void); +typedef int (*subinitcall_t)(void); +typedef void (*subexitcall_t)(void); + #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS typedef int initcall_entry_t; @@ -183,7 +189,61 @@ extern struct module __this_module; #endif #endif - + +#ifndef __ASSEMBLY__ +struct subexitcall_rollback { + /* + * Records the address of the first sub-initialization function in the + * ".subexitcall.exit" section + */ + unsigned long first_addr; + int ncalls; +}; + +static inline void __subexitcall_rollback(struct subexitcall_rollback *r) +{ + unsigned long addr = r->first_addr - sizeof(r->first_addr) * (r->ncalls - 1); + + for (; r->ncalls--; addr += sizeof(r->first_addr)) { + unsigned long *tmp = (void *)addr; + subexitcall_t fn = (subexitcall_t)*tmp; + fn(); + } +} + +static inline void set_rollback_ncalls(struct subexitcall_rollback *r) +{ + r->ncalls++; +} + +static inline void set_rollback_first_addr(struct subexitcall_rollback *rollback, + unsigned long addr) +{ + if (!rollback->first_addr) + rollback->first_addr = addr; +} + +#define __subinitcall_noexit(initfn, rollback) \ +do { \ + static subinitcall_t __subinitcall_##initfn __subinit_call = initfn; \ + int _ret; \ + _ret = initfn(); \ + if (_ret < 0) { \ + __subexitcall_rollback(rollback); \ + return _ret; \ + } \ +} while (0) + +#define __subinitcall(initfn, exitfn, rollback) \ +do { \ + static subexitcall_t __subexitcall_##exitfn __subexit_call = exitfn; \ + set_rollback_first_addr(rollback, (unsigned long)&__subexitcall_##exitfn); \ + __subinitcall_noexit(initfn, rollback); \ + set_rollback_ncalls(rollback); \ +} while (0) + +#endif /* !__ASSEMBLY__ */ + #ifndef MODULE #ifndef __ASSEMBLY__ diff --git a/include/linux/module.h b/include/linux/module.h index 4213d8993cd8..95f7c60dede9 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -76,6 +76,28 @@ extern struct module_attribute module_uevent; extern int init_module(void); extern void cleanup_module(void); +/* + * module_subinit() - Called when the driver is subinitialized + * @initfn: The subinitialization function that is called + * @exitfn: Corresponding exit function + * @rollback: Record information when the subinitialization failed + * or the driver was removed + * + * Use module_subinit_noexit() when there is only an subinitialization + * function but no corresponding exit function. + */ +#define module_subinit(initfn, exitfn, rollback) \ + __subinitcall(initfn, exitfn, rollback); + +#define module_subinit_noexit(initfn, rollback) \ + __subinitcall_noexit(initfn, rollback); + +/* + * module_subexit() - Called when the driver exits + */ +#define module_subexit(rollback) \ + __subexitcall_rollback(rollback); + #ifndef MODULE /** * module_init() - driver initialization entry point From patchwork Tue Jul 23 08:32:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Youling Tang X-Patchwork-Id: 13739709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C761EC3DA49 for ; Tue, 23 Jul 2024 08:33:20 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sWAxU-0002cF-Ex; Tue, 23 Jul 2024 08:33:19 +0000 Received: from [172.30.29.67] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sWAxT-0002c6-EQ for linux-f2fs-devel@lists.sourceforge.net; Tue, 23 Jul 2024 08:33:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=OxA91QkgOX+0VUDnwCt0xfORmuQFDgxjT+SW/I9SKQs=; b=h8aNySBS9uq6QNqKjP5/DSt0aN iZVqtIQ0CQukhF4b2fF+rJHgBSMlT/yczRFe4o7c8UCg0wPoNRtCdwb/Ah8mDaX0mGU5xrGy7pSRz ATnEQElVLsWSrJUmWRHVnMtt9N4RjJtIApjWqvqa7vL7MVVz30yLwESvKU1EJuOkLz3s=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=OxA91QkgOX+0VUDnwCt0xfORmuQFDgxjT+SW/I9SKQs=; b=bdU4+1YUx0BhjWfzouodQVzX5h 2L+gR4gEIEY3U2l/tIdui5tsbLEiP4GHteDqTqn+6jPUu0m9ejQwlQMx/duJefl+oAkei4fB6tw0p LGLEwEfACj0bV+g3e7t1MLoYUSpSG4QFrea3c7g00rIo5BV8A4h4U27+hT3Ewivoax6g=; Received: from out-174.mta0.migadu.com ([91.218.175.174]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sWAxR-0003rp-FX for linux-f2fs-devel@lists.sourceforge.net; Tue, 23 Jul 2024 08:33:18 +0000 X-Envelope-To: arnd@arndb.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1721723591; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OxA91QkgOX+0VUDnwCt0xfORmuQFDgxjT+SW/I9SKQs=; b=obXgWZddWdqx+zVOxSS8TJb8HANTxzSQNfsDVMfOVZnMmH1e7jW+1BRdsrBuqvRXHSoZJf 1UPvBvOVTl8nd0O9wFzheyPT6A0hV9oinYwkFSkY1Mw54TOjhHHnOcfIqBO5NSyKXy9cyH GbznrE8Sg3iLW2RTf6CypTVG1MEHpyU= X-Envelope-To: mcgrof@kernel.org X-Envelope-To: clm@fb.com X-Envelope-To: josef@toxicpanda.com X-Envelope-To: dsterba@suse.com X-Envelope-To: tytso@mit.edu X-Envelope-To: adilger.kernel@dilger.ca X-Envelope-To: jaegeuk@kernel.org X-Envelope-To: chao@kernel.org X-Envelope-To: hch@infradead.org X-Envelope-To: linux-arch@vger.kernel.org X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: linux-modules@vger.kernel.org X-Envelope-To: linux-btrfs@vger.kernel.org X-Envelope-To: linux-ext4@vger.kernel.org X-Envelope-To: linux-f2fs-devel@lists.sourceforge.net X-Envelope-To: youling.tang@linux.dev X-Envelope-To: tangyouling@kylinos.cn X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Youling Tang To: Arnd Bergmann , Luis Chamberlain , Chris Mason , Josef Bacik , David Sterba , tytso@mit.edu, Andreas Dilger , Jaegeuk Kim , Chao Yu , Christoph Hellwig Date: Tue, 23 Jul 2024 16:32:37 +0800 Message-Id: <20240723083239.41533-3-youling.tang@linux.dev> In-Reply-To: <20240723083239.41533-1-youling.tang@linux.dev> References: <20240723083239.41533-1-youling.tang@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Headers-End: 1sWAxR-0003rp-FX Subject: [f2fs-dev] [PATCH 2/4] btrfs: Use module_subinit{_noexit} and module_subeixt helper macros X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Youling Tang , 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 Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Youling Tang Use module_{subinit, subinit} to ensure that modules init and exit are in sequence and to simplify the code. Signed-off-by: Youling Tang --- 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; } From patchwork Tue Jul 23 08:32:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Youling Tang X-Patchwork-Id: 13739710 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 30BF0C3DA63 for ; Tue, 23 Jul 2024 08:33:33 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sWAxh-0002dK-1L; Tue, 23 Jul 2024 08:33:32 +0000 Received: from [172.30.29.67] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sWAxe-0002d9-SF for linux-f2fs-devel@lists.sourceforge.net; Tue, 23 Jul 2024 08:33:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=2FpchObtj1bgKZan3q5qtLR0pzIfvv/hdOK5gMl3pYc=; b=FqcPL5HwoM3b7IakjMAk4pbXSq zhy1oPL+6NfvVtypJ1k3l4m03Ceg1l1xGBUwXfnSKmU7ddAsrY6wkeRf2hitXL1tQTo6sJd99wOtm JLhvavRwYnNWqFxOBRCh5mX1iH1RHygoyDDkOBX/Qj7TFCOyCzNzhc8fvo/ZkGsoksow=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=2FpchObtj1bgKZan3q5qtLR0pzIfvv/hdOK5gMl3pYc=; b=IVIwi5DjWTMFtQ7s69hgSoyLmi kZxDm/IA5eRT3P7SwLm10a1FPJ+C4vlqkjk8vh3+TCAtUYoJ48zZ1BSF5umBSXvejOZlzHCRF/Fm1 YbCdik3ixmlM4FsPyUelxa+9XZ/Wm2zGSZbCZtSr/mLft8bBZ/W/5tY8Z3y4MtC0ZVq8=; Received: from out-185.mta0.migadu.com ([91.218.175.185]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sWAxc-0003tf-VG for linux-f2fs-devel@lists.sourceforge.net; Tue, 23 Jul 2024 08:33:30 +0000 X-Envelope-To: arnd@arndb.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1721723597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2FpchObtj1bgKZan3q5qtLR0pzIfvv/hdOK5gMl3pYc=; b=d+j7TsDHafpzbLmS3vv6N/qkImQhjEqmin45ALNJBaRxl0qHDTvOB+rqR+HlCL96wm0LOF eA2U2qzRIYTczg0xNz8D9dMn0NWdsVOeb8S60GRVOWIpHir2+okklwMqcuf8x5jN+lBWRl uhgkDt50wo+N4yrygEF4KSBzYqB6z2U= X-Envelope-To: mcgrof@kernel.org X-Envelope-To: clm@fb.com X-Envelope-To: josef@toxicpanda.com X-Envelope-To: dsterba@suse.com X-Envelope-To: tytso@mit.edu X-Envelope-To: adilger.kernel@dilger.ca X-Envelope-To: jaegeuk@kernel.org X-Envelope-To: chao@kernel.org X-Envelope-To: hch@infradead.org X-Envelope-To: linux-arch@vger.kernel.org X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: linux-modules@vger.kernel.org X-Envelope-To: linux-btrfs@vger.kernel.org X-Envelope-To: linux-ext4@vger.kernel.org X-Envelope-To: linux-f2fs-devel@lists.sourceforge.net X-Envelope-To: youling.tang@linux.dev X-Envelope-To: tangyouling@kylinos.cn X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Youling Tang To: Arnd Bergmann , Luis Chamberlain , Chris Mason , Josef Bacik , David Sterba , tytso@mit.edu, Andreas Dilger , Jaegeuk Kim , Chao Yu , Christoph Hellwig Date: Tue, 23 Jul 2024 16:32:38 +0800 Message-Id: <20240723083239.41533-4-youling.tang@linux.dev> In-Reply-To: <20240723083239.41533-1-youling.tang@linux.dev> References: <20240723083239.41533-1-youling.tang@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Headers-End: 1sWAxc-0003tf-VG Subject: [f2fs-dev] [PATCH 3/4] ext4: Use module_{subinit, subexit} helper macros X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Youling Tang , 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 Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Youling Tang Use module_{subinit, subinit} to ensure that modules init and exit are in sequence and to simplify the code. Signed-off-by: Youling Tang --- 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"); From patchwork Tue Jul 23 08:32:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Youling Tang X-Patchwork-Id: 13739711 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A4560C3DA49 for ; Tue, 23 Jul 2024 08:33:33 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sWAxh-0005oJ-8P; Tue, 23 Jul 2024 08:33:33 +0000 Received: from [172.30.29.67] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sWAxg-0005o3-BO for linux-f2fs-devel@lists.sourceforge.net; Tue, 23 Jul 2024 08:33:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Cje3Y5ms0q2wZZ3qNUkIwaPZ+RsvLH8H4iju91pzTbQ=; b=lnpZ0y1Osoq8vRvNS6U22EMd9z bwtAyDkuq+Pr4FOe6iDgZn+pOo1t3KG5TVVyiXmhWDaQoF0IbEttTB9O//fJmG90NCYLlBO5EIBRL /d22hNF5b4IGrkK+VHQSvmaGhy4M6oDBk0aBV6YMYVoGk3wLjsakOno0jCaei9uafMDg=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Cje3Y5ms0q2wZZ3qNUkIwaPZ+RsvLH8H4iju91pzTbQ=; b=imoEgsY4cGr5xI7S1s23YtWVh3 l1ChDOqyJ7iUnqsrX6JpWgfbv+doJykOVinzyxisHRMHL8Q9PxwXdFe98GJOeyNxi9m4tmpvR2qcZ Sz3ADf/w2i81ihA3Glas0j4HNvbjcQ+uJIhqsVUDIr+ERvBMBuFtJu0qARZcauMKPsIo=; Received: from out-179.mta0.migadu.com ([91.218.175.179]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sWAxf-0003tr-71 for linux-f2fs-devel@lists.sourceforge.net; Tue, 23 Jul 2024 08:33:32 +0000 X-Envelope-To: arnd@arndb.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1721723604; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Cje3Y5ms0q2wZZ3qNUkIwaPZ+RsvLH8H4iju91pzTbQ=; b=N70HycgdIR3ibRzffZLSSKoDwX0DMnfVNAP+94kP0Xckzmrh1ehHKiU2DX7lqmSsF2JTQ5 aW8Lczzik40cmq6WMH0uY9KDoAMZ73kYcxd03FbPixjXXddnWVkoK9zAL6DSsO07vAiecE XydOC3tGCZiWKDPxNjOO63qsWY0TBFg= X-Envelope-To: mcgrof@kernel.org X-Envelope-To: clm@fb.com X-Envelope-To: josef@toxicpanda.com X-Envelope-To: dsterba@suse.com X-Envelope-To: tytso@mit.edu X-Envelope-To: adilger.kernel@dilger.ca X-Envelope-To: jaegeuk@kernel.org X-Envelope-To: chao@kernel.org X-Envelope-To: hch@infradead.org X-Envelope-To: linux-arch@vger.kernel.org X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: linux-modules@vger.kernel.org X-Envelope-To: linux-btrfs@vger.kernel.org X-Envelope-To: linux-ext4@vger.kernel.org X-Envelope-To: linux-f2fs-devel@lists.sourceforge.net X-Envelope-To: youling.tang@linux.dev X-Envelope-To: tangyouling@kylinos.cn X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Youling Tang To: Arnd Bergmann , Luis Chamberlain , Chris Mason , Josef Bacik , David Sterba , tytso@mit.edu, Andreas Dilger , Jaegeuk Kim , Chao Yu , Christoph Hellwig Date: Tue, 23 Jul 2024 16:32:39 +0800 Message-Id: <20240723083239.41533-5-youling.tang@linux.dev> In-Reply-To: <20240723083239.41533-1-youling.tang@linux.dev> References: <20240723083239.41533-1-youling.tang@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Headers-End: 1sWAxf-0003tr-71 Subject: [f2fs-dev] [PATCH 4/4] f2fs: Use module_{subinit, subeixt} helper macros X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Youling Tang , 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 Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Youling Tang Use module_{subinit, subinit} to ensure that modules init and exit are in sequence and to simplify the code. Signed-off-by: Youling Tang --- 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)