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: 13739713 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED0C614BF89; Tue, 23 Jul 2024 08:33:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721723587; cv=none; b=MP35L3y9rUKB6euArMWifi+LvuymjCJ4Vm6q/Tjq3uE/up2PorNyVwX8tQBQrCVqui2fPvHWlBppIg/RN0DRM41UX62bZSs77iomH6v8XIe6xmYPrDD9W+3ZV8WqILYPoHXNikCjmJFGwZ32FlGghWMy1dUfaqK5Y9wDytu2PXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721723587; c=relaxed/simple; bh=16C3qOghK8TaOTax2+QAysgUWXWtYbusUjh2y2kiDPA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BoBo1uFY58ibIItjcfnM/TksxJW8UaC3Wm/2vdbP0Jc7AsGU9hOLrzlciwHAiMVSrVU8t3BXfX7hFnZVQLJJoTPwy44KaU76ykcNXtlS+1oFSB4CoDZJ0FZZLZ9wEpyZbOx4rEYl8/cmLmtNxidEer3X54xy373fxL6tE80dQZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=cQx+gVTP; arc=none smtp.client-ip=91.218.175.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="cQx+gVTP" 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 Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, youling.tang@linux.dev, Youling Tang Subject: [PATCH 1/4] module: Add module_subinit{_noexit} and module_subeixt helper macros 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> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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: 13739714 Received: from out-187.mta0.migadu.com (out-187.mta0.migadu.com [91.218.175.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C497214D6E1 for ; Tue, 23 Jul 2024 08:33:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721723594; cv=none; b=b/czm3siH7of1Mu+5681QkzBZPs5BiRiGHc1sPyEK070ni88L1EyJoWjz/NvX2YkzF0V7o8vFyi3Kpqa9nnliQxSkwPy8gN6qaISO4JvQnL1YA8oBdpP7KI0smWl/EEZdzaxfPH1KPMzmI4KI9AJQC8UzJ02P3XPKMqQfCQzrP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721723594; c=relaxed/simple; bh=aUtYHLJ/I++YuGgw+lRjcbWtMgEMqa2dApBe1d3FQcA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DG+KTR119RcOaksh+why+xxDnoR3sm8QtGcnaKoBgBTCR+ThqpV6kMQrsfdvKO1dzJsr7HeI9CeINVWTmjHL18w2c7qr6JCoQaeSW/3mGMA2yRlzCPQCVjs9zN1UWMTgcImdzdMTCebXBM8VBCjfjeR1yBCjbpsniKlYU5/14vA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=obXgWZdd; arc=none smtp.client-ip=91.218.175.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="obXgWZdd" 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 Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, youling.tang@linux.dev, Youling Tang Subject: [PATCH 2/4] btrfs: Use module_subinit{_noexit} and module_subeixt helper macros 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> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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: 13739715 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B8D414EC40 for ; Tue, 23 Jul 2024 08:33:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721723601; cv=none; b=haJQ7PaktSptMijfh49MULcCdPRisU811s5Ce1VkMo+f9bKwIqV9wm1E7aVStsn/7iNwLWFZ70j9+DGzRxjASa89LQRrYI4bfROXhe/wCITpSYz6EQTDWhlDf4Xq9uXaMfPwvHMnQOCbKwfWgESJfM90c/3AriNxCsafssdOZ+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721723601; c=relaxed/simple; bh=/mwN5SsbhIgDMwi2o5jzaWYzFJunRtJZ5k7XEtLZcxQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KyQUNY0Q5IqU0zZE5+7YnkCeR+OxPWz3wPJnD+y1DSjnhNGO+TMIPv0MAFyycZjbYuF6i0URz37I+MpIFK64yid3RMi8usUrp59sYAmDjWmpEZ6kEjIKDOjpN+mL3xgAh5J64IP08WjYuV4kAWBr1UoO+A5NI5PJ/puLoTFAS+s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=d+j7TsDH; arc=none smtp.client-ip=91.218.175.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="d+j7TsDH" 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 Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, youling.tang@linux.dev, Youling Tang Subject: [PATCH 3/4] ext4: Use module_{subinit, subexit} helper macros 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> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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: 13739716 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9696C14D283; Tue, 23 Jul 2024 08:33:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721723608; cv=none; b=fdMtyd06SqrHgNRJNDlzDUL6LetQ0wdKBuwTQRypX0GkDL5dhDzLmKQdLcck8Xm7wNOV1XaVX6KfG0T7NLOTqjBIn7rAVEVOft4G99RAkYyBC538oY+0qkXIfS55OA3uqLTyGsCUDRT2u32SMH9NuTRlL38QqlNBwu+MzdWcGuc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721723608; c=relaxed/simple; bh=8qpU8QvLN6vXVX/x53G5eEe50VLRRBnIA+358suYNzQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hP8Vof/SwnlHU5ZcAnZ2TvLOHIEDT/iDyA5RP8tzJ9Qih+OJOemoFDoVUMTQ5/xDGTIRNeb/2lZ6/FaYKEJYWzHFqO1M9/dlAxN6PFw7B37bppdb8PzHYVQhPPfZebHXi09CcCIVkL0PxTuqXmwEAELWy4gFhUMto/OXON6hqZE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=N70Hycgd; arc=none smtp.client-ip=91.218.175.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="N70Hycgd" 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 Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, youling.tang@linux.dev, Youling Tang Subject: [PATCH 4/4] f2fs: Use module_{subinit, subeixt} helper macros 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> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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)