From nobody Mon Sep 16 19:41:25 2024 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 34C4814BF97 for ; Tue, 23 Jul 2024 08:33:05 +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=1721723588; cv=none; b=hWBN3HafcPOjTlCm/J96PkOs8OMyV14y7KU7plBVWE8yWpbx9e9BDwif7UbN517Gcp2WeGue5bWfa2RlTumxrtPBIhfXj2NlJZG8v4bkE1RmHwxSjv2tiNxSd7IESBiGCGxZD9ReqxATq0uBg82AvE0QK7Yx+OUPLcQWZsvRmkg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721723588; c=relaxed/simple; bh=16C3qOghK8TaOTax2+QAysgUWXWtYbusUjh2y2kiDPA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oRyTkQsemyJ+b1VbDhsWYabVIQNG2EJkQ9bKyM+rvLq6vYai62ULyrIe4bpXvU+LFgV3IcWiPO9IZH3sDy1I1WT/at/rYdp6LE2gEJr1wvaooah14VF3a1KrTEewduFKeoddtelwIdC4B6LUD0Dp1tUT/m+eU65RSMVyWsSuMa4= 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.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="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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" 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/vmlinu= x.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 =3D .; =20 +#define SUBINIT_CALL \ + *(.subinitcall.init) \ + *(.subexitcall.exit) + #define CON_INITCALL \ BOUNDED_SECTION_POST_LABEL(.con_initcall.init, __con_initcall, _start, _e= nd) =20 @@ -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") =20 +#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); =20 +typedef int (*subinitcall_t)(void); +typedef void (*subexitcall_t)(void); + #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS typedef int initcall_entry_t; =20 @@ -183,7 +189,61 @@ extern struct module __this_module; #endif =20 #endif - =20 + +#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 =3D r->first_addr - sizeof(r->first_addr) * (r->ncalls= - 1); + + for (; r->ncalls--; addr +=3D sizeof(r->first_addr)) { + unsigned long *tmp =3D (void *)addr; + subexitcall_t fn =3D (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 *ro= llback, + unsigned long addr) +{ + if (!rollback->first_addr) + rollback->first_addr =3D addr; +} + +#define __subinitcall_noexit(initfn, rollback) \ +do { \ + static subinitcall_t __subinitcall_##initfn __subinit_call =3D initfn; \ + int _ret; \ + _ret =3D initfn(); \ + if (_ret < 0) { \ + __subexitcall_rollback(rollback); \ + return _ret; \ + } \ +} while (0) + +#define __subinitcall(initfn, exitfn, rollback) \ +do { \ + static subexitcall_t __subexitcall_##exitfn __subexit_call =3D exitfn; \ + set_rollback_first_addr(rollback, (unsigned long)&__subexitcall_##exitfn)= ; \ + __subinitcall_noexit(initfn, rollback); \ + set_rollback_ncalls(rollback); \ +} while (0) + +#endif /* !__ASSEMBLY__ */ + #ifndef MODULE =20 #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); =20 +/* + * 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 --=20 2.34.1 From nobody Mon Sep 16 19:41:25 2024 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (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 B838514D457 for ; Tue, 23 Jul 2024 08:33:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721723594; cv=none; b=K0dVoP8nysPCgYkb3Ha6UDjjNoPr/97QArSKy1VJi0IM/fdFYeld/kZzrUldqlYUdj+Cs1+urbv9X8+yvJOHUnQcTamA1FH+HAlDpDfxfiWkbOk83zT0ENiuqn3eS2AW9rwmASQUOuNK4K2pnuSWZ61p58/JnTtJ+T0APfHqoFg= 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.179 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" 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); } =20 -/* 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[] =3D { - { - .init_func =3D btrfs_props_init, - .exit_func =3D NULL, - }, { - .init_func =3D btrfs_init_sysfs, - .exit_func =3D btrfs_exit_sysfs, - }, { - .init_func =3D btrfs_init_compress, - .exit_func =3D btrfs_exit_compress, - }, { - .init_func =3D btrfs_init_cachep, - .exit_func =3D btrfs_destroy_cachep, - }, { - .init_func =3D btrfs_init_dio, - .exit_func =3D btrfs_destroy_dio, - }, { - .init_func =3D btrfs_transaction_init, - .exit_func =3D btrfs_transaction_exit, - }, { - .init_func =3D btrfs_ctree_init, - .exit_func =3D btrfs_ctree_exit, - }, { - .init_func =3D btrfs_free_space_init, - .exit_func =3D btrfs_free_space_exit, - }, { - .init_func =3D extent_state_init_cachep, - .exit_func =3D extent_state_free_cachep, - }, { - .init_func =3D extent_buffer_init_cachep, - .exit_func =3D extent_buffer_free_cachep, - }, { - .init_func =3D btrfs_bioset_init, - .exit_func =3D btrfs_bioset_exit, - }, { - .init_func =3D extent_map_init, - .exit_func =3D extent_map_exit, - }, { - .init_func =3D ordered_data_init, - .exit_func =3D ordered_data_exit, - }, { - .init_func =3D btrfs_delayed_inode_init, - .exit_func =3D btrfs_delayed_inode_exit, - }, { - .init_func =3D btrfs_auto_defrag_init, - .exit_func =3D btrfs_auto_defrag_exit, - }, { - .init_func =3D btrfs_delayed_ref_init, - .exit_func =3D btrfs_delayed_ref_exit, - }, { - .init_func =3D btrfs_prelim_ref_init, - .exit_func =3D btrfs_prelim_ref_exit, - }, { - .init_func =3D btrfs_interface_init, - .exit_func =3D btrfs_interface_exit, - }, { - .init_func =3D btrfs_print_mod_info, - .exit_func =3D NULL, - }, { - .init_func =3D btrfs_run_sanity_tests, - .exit_func =3D NULL, - }, { - .init_func =3D register_btrfs, - .exit_func =3D 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 =3D ARRAY_SIZE(mod_init_seq) - 1; i >=3D 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] =3D false; - } -} +static struct subexitcall_rollback rollback; =20 static void __exit exit_btrfs_fs(void) { - btrfs_exit_btrfs_fs(); + module_subexit(&rollback); btrfs_cleanup_fs_uuids(); } =20 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, &rollb= ack); + module_subinit(extent_buffer_init_cachep, extent_buffer_free_cachep, &rol= lback); + 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, &rollb= ack); + 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); =20 - for (i =3D 0; i < ARRAY_SIZE(mod_init_seq); i++) { - ASSERT(!mod_init_result[i]); - ret =3D mod_init_seq[i].init_func(); - if (ret < 0) { - btrfs_exit_btrfs_fs(); - return ret; - } - mod_init_result[i] =3D true; - } return 0; } =20 --=20 2.34.1 From nobody Mon Sep 16 19:41:25 2024 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (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 3C32A14EC41 for ; Tue, 23 Jul 2024 08:33:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721723601; cv=none; b=aN4yB+AC2X8QpdTDsWbAjIOUUaPZop30qBpErqQXy2NL2lUgoV88waYcWYeiF8gc+idYjoQ+igIpy7nI6CdSOYu84xQZnz3WmLTYMjST08LpQI/qM+mOiQSTuoE8jqMQy89dlocG0gB85gOMcXcy5mOHDg0B9TMuvlRwnxjpV74= 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.188 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" 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 =3D { }; MODULE_ALIAS_FS("ext4"); =20 +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]; =20 static int __init ext4_init_fs(void) { - int i, err; - ratelimit_state_init(&ext4_mount_msg_ratelimit, 30 * HZ, 64); ext4_li_info =3D NULL; =20 /* Build-time check for flags consistency */ ext4_check_flag_values(); =20 - for (i =3D 0; i < EXT4_WQ_HASH_SZ; i++) + for (int i =3D 0; i < EXT4_WQ_HASH_SZ; i++) init_waitqueue_head(&ext4__ioend_wq[i]); =20 - err =3D ext4_init_es(); - if (err) - return err; - - err =3D ext4_init_pending(); - if (err) - goto out7; - - err =3D ext4_init_post_read_processing(); - if (err) - goto out6; - - err =3D ext4_init_pageio(); - if (err) - goto out5; - - err =3D ext4_init_system_zone(); - if (err) - goto out4; - - err =3D ext4_init_sysfs(); - if (err) - goto out3; - - err =3D ext4_init_mballoc(); - if (err) - goto out2; - err =3D init_inodecache(); - if (err) - goto out1; - - err =3D ext4_fc_init_dentry_cache(); - if (err) - goto out05; - - register_as_ext3(); - register_as_ext2(); - err =3D 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_proces= sing, &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); =20 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(); } =20 MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, = Theodore Ts'o and others"); --=20 2.34.1 From nobody Mon Sep 16 19:41:25 2024 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) (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 8429114D2B2 for ; Tue, 23 Jul 2024 08:33:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721723608; cv=none; b=XB+DPUmw+ETmCygERG6AKl617CqkPNdAeWRrLuNHPju+HZBEsQl14rrgtNtF0FVwsxFbFmnpoWRAz4F3F1w/JBClgHws0Z26+jE0qahaNXjXDkW2+FLz5U8tCmIs3HCD/uViDiX8vqgcy0aUcgAI+LY9uA2iP0WEtOYjyyiPx50= 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.178 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" 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); } =20 -void __init f2fs_create_root_stats(void) +int __init f2fs_create_root_stats(void) { #ifdef CONFIG_DEBUG_FS f2fs_debugfs_root =3D 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; } =20 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) =20 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); =20 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); } =20 -static int __init init_f2fs_fs(void) +static int register_f2fs(void) { - int err; + return register_filesystem(&f2fs_fs_type); +} =20 - err =3D init_inodecache(); - if (err) - goto fail; - err =3D f2fs_create_node_manager_caches(); - if (err) - goto free_inodecache; - err =3D f2fs_create_segment_manager_caches(); - if (err) - goto free_node_manager_caches; - err =3D f2fs_create_checkpoint_caches(); - if (err) - goto free_segment_manager_caches; - err =3D f2fs_create_recovery_cache(); - if (err) - goto free_checkpoint_caches; - err =3D f2fs_create_extent_cache(); - if (err) - goto free_recovery_cache; - err =3D f2fs_create_garbage_collection_cache(); - if (err) - goto free_extent_cache; - err =3D f2fs_init_sysfs(); - if (err) - goto free_garbage_collection_cache; - err =3D f2fs_init_shrinker(); - if (err) - goto free_sysfs; - err =3D register_filesystem(&f2fs_fs_type); - if (err) - goto free_shrinker; - f2fs_create_root_stats(); - err =3D f2fs_init_post_read_processing(); - if (err) - goto free_root_stats; - err =3D f2fs_init_iostat_processing(); - if (err) - goto free_post_read; - err =3D f2fs_init_bio_entry_cache(); - if (err) - goto free_iostat; - err =3D f2fs_init_bioset(); - if (err) - goto free_bio_entry_cache; - err =3D f2fs_init_compress_mempool(); - if (err) - goto free_bioset; - err =3D f2fs_init_compress_cache(); - if (err) - goto free_compress_mempool; - err =3D 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; } =20 +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_m= anager_caches, &rollback); + module_subinit(f2fs_create_checkpoint_caches, f2fs_destroy_checkpoint_cac= hes, &rollback); + module_subinit(f2fs_create_recovery_cache, f2fs_destroy_recovery_cache, &= rollback); + module_subinit(f2fs_create_extent_cache, f2fs_destroy_extent_cache, &roll= back); + 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_pro= cessing, &rollback); + module_subinit(f2fs_init_iostat_processing, f2fs_destroy_iostat_processin= g, &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, &ro= llback); + module_subinit(f2fs_create_casefold_cache, f2fs_destroy_casefold_cache, &= rollback); + + return 0; } =20 module_init(init_f2fs_fs) --=20 2.34.1