From patchwork Thu Jul 11 07:48:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Youling Tang X-Patchwork-Id: 1959121 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=V1czT8TX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=mail.ozlabs.org; envelope-from=srs0=rkyt=ol=vger.kernel.org=linux-ext4+bounces-3189-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WKRhW1CbKz1xqj for ; Thu, 11 Jul 2024 17:49:47 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4WKRhW0nQrz4w2J for ; Thu, 11 Jul 2024 17:49:47 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4WKRhW0kKtz4wnx; Thu, 11 Jul 2024 17:49:47 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=V1czT8TX; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-ext4+bounces-3189-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4WKRhV3NJCz4w2J for ; Thu, 11 Jul 2024 17:49:46 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C50DB1F22BE3 for ; Thu, 11 Jul 2024 07:49:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8330614B06C; Thu, 11 Jul 2024 07:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="V1czT8TX" X-Original-To: linux-ext4@vger.kernel.org Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.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 665A714883C for ; Thu, 11 Jul 2024 07:49:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720684181; cv=none; b=g3SeAvsUcX1TZiDILDCgg80YGu5CFeRivcUrFxqVf8XZwqoGCJFAoXij7HQ5L+omEBOao1HfNKRWDk20gW21GitFPqrs21RM9LugiDJ43kHfIq8p6n7dCH/5Pn6F6JcASPZmiD6WFj4gp5kRZHPOcJJFO0ZoqgZXXYB2njvYRFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720684181; c=relaxed/simple; bh=t8D1/JWAZsYhyEFIpC9YhtGy7mBtuQi1FWOchWEysSE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PYeF/zbCV4tBkxQr+6XnSmGkezWsZu+zUZfyMZKkCSWnAvmJIsIL/xGOHLrz7HVE4hC44M0h/910sccBITQdXoP2pnhEJeqNKMzjjristisHFn0sbWgfVxF61DJbBTPFcWCgaHXaY2PInNNnvcK/5+B7O0NYOnEp7qyJEGBXg4Q= 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=V1czT8TX; arc=none smtp.client-ip=95.215.58.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 X-Envelope-To: viro@zeniv.linux.org.uk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1720684177; 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=B0Pv6QDalGXk7IOv6qaWwK0TM7yMO9uy++QJx87szJ0=; b=V1czT8TX/qHoOVV8Aij2cRLFZZ5RmeOmF3oEKog+Us0DDoT3Ko9CoG+7KpK6NA0BPi8Ksb MGq3naYYb2Ev1uSSVGcMRHcKVdHMC5JjLTteuD/lCktVRzGvXZodevgWoQC9BWMC/QTuA0 d52c0i65ghvF1bbDX4YkTEh+PKgKXOI= X-Envelope-To: brauner@kernel.org X-Envelope-To: jack@suse.cz 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: linux-fsdevel@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: linux-kernel@vger.kernel.org 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: Alexander Viro , Christian Brauner , Jan Kara , Chris Mason , Josef Bacik , David Sterba , tytso@mit.edu, Andreas Dilger , Jaegeuk Kim , Chao Yu Cc: linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, youling.tang@linux.dev, Youling Tang Subject: [PATCH 1/3] f2fs: make module init/exit match their sequence Date: Thu, 11 Jul 2024 15:48:57 +0800 Message-Id: <20240711074859.366088-2-youling.tang@linux.dev> In-Reply-To: <20240711074859.366088-1-youling.tang@linux.dev> References: <20240711074859.366088-1-youling.tang@linux.dev> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT From: Youling Tang Use init_sequence 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 | 210 ++++++++++++++++++++++++------------------------ 3 files changed, 107 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 1974b6aff397..d546bd301565 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -4086,7 +4086,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 @@ -4128,7 +4128,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 1f1b3647a998..19509942b837 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4940,120 +4940,116 @@ 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; +} + +/* 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 = init_inodecache, + .exit_func = destroy_inodecache, + }, { + .init_func = f2fs_create_node_manager_caches, + .exit_func = f2fs_destroy_node_manager_caches, + }, { + .init_func = f2fs_create_segment_manager_caches, + .exit_func = f2fs_destroy_segment_manager_caches, + }, { + .init_func = f2fs_create_checkpoint_caches, + .exit_func = f2fs_destroy_checkpoint_caches, + }, { + .init_func = f2fs_create_recovery_cache, + .exit_func = f2fs_destroy_recovery_cache, + }, { + .init_func = f2fs_create_extent_cache, + .exit_func = f2fs_destroy_extent_cache, + }, { + .init_func = f2fs_create_garbage_collection_cache, + .exit_func = f2fs_destroy_garbage_collection_cache, + }, { + .init_func = f2fs_init_sysfs, + .exit_func = f2fs_exit_sysfs, + }, { + .init_func = f2fs_init_shrinker, + .exit_func = f2fs_exit_shrinker, + }, { + .init_func = register_f2fs, + .exit_func = unregister_f2fs, + }, { + .init_func = f2fs_create_root_stats, + .exit_func = f2fs_destroy_root_stats, + }, { + .init_func = f2fs_init_post_read_processing, + .exit_func = f2fs_destroy_post_read_processing, + }, { + .init_func = f2fs_init_iostat_processing, + .exit_func = f2fs_destroy_iostat_processing, + }, { + .init_func = f2fs_init_bio_entry_cache, + .exit_func = f2fs_destroy_bio_entry_cache, + }, { + .init_func = f2fs_init_bioset, + .exit_func = f2fs_destroy_bioset, + }, { + .init_func = f2fs_init_compress_mempool, + .exit_func = f2fs_destroy_compress_mempool, + }, { + .init_func = f2fs_init_compress_cache, + .exit_func = f2fs_destroy_compress_cache, + }, { + .init_func = f2fs_create_casefold_cache, + .exit_func = f2fs_destroy_casefold_cache, + } +}; + +static bool mod_init_result[ARRAY_SIZE(mod_init_seq)]; + +static __always_inline void f2fs_exit_f2fs_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 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(); + f2fs_exit_f2fs_fs(); +} + +static int __init init_f2fs_fs(void) +{ + int ret; + int i; + + for (i = 0; i < ARRAY_SIZE(mod_init_seq); i++) { + BUG_ON(mod_init_result[i]); + ret = mod_init_seq[i].init_func(); + if (ret < 0) { + f2fs_exit_f2fs_fs(); + return ret; + } + mod_init_result[i] = true; + } + return 0; } module_init(init_f2fs_fs) From patchwork Thu Jul 11 07:48:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Youling Tang X-Patchwork-Id: 1959122 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=jSvwbqw3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=aw/f=ol=vger.kernel.org=linux-ext4+bounces-3190-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WKRj01h79z1xpd for ; Thu, 11 Jul 2024 17:50:12 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4WKRj01HNzz4w2J for ; Thu, 11 Jul 2024 17:50:12 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4WKRj01DmHz4w2N; Thu, 11 Jul 2024 17:50:12 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=jSvwbqw3; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-ext4+bounces-3190-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4WKRhz58hdz4w2J for ; Thu, 11 Jul 2024 17:50:11 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DE5991C2118F for ; Thu, 11 Jul 2024 07:50:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B95B1514D0; Thu, 11 Jul 2024 07:49:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="jSvwbqw3" X-Original-To: linux-ext4@vger.kernel.org Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (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 57F1E1509A4 for ; Thu, 11 Jul 2024 07:49:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720684185; cv=none; b=UAV8fu6AtFMyPV5+PPK26ARgMr/bjsUFXqq0RVGh5Uezh6THAmUoHvr0pZPGI7ecFRceyW5G0RlA806KalJpHO4/PTkW7UaW1p7FkNYiWjg4dUkedfXoksRefw7OBlpWsZlJZ7kxqYzyaq3d3bnpluAfmHhnyTCRwjcu4Gi0Osk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720684185; c=relaxed/simple; bh=kSFRTa8cWH/vlSHnN9DUZZkdaba4iKL31E4sVSEpMEg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=euqEu26CGyevLh7OSVtiUzhLE666utTVGl2ZWeFUxpkvWd3QuXIY5ZVZDUlaApl01nLIe/N5nIz1f8eIellVX/bVc/p1CXW4ytvW9mpeI6fE5mcfi0k0dhOCDDWQiECCCZDShHrbh23MS7DQL2y167dyLNO6/FsJfp4CFCfTukE= 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=jSvwbqw3; arc=none smtp.client-ip=95.215.58.170 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 X-Envelope-To: viro@zeniv.linux.org.uk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1720684182; 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=XFljGRgWS+o+/FKeNHoSuAwsaBjm894r1O3P7vtGZus=; b=jSvwbqw3JyuWV/rQ+ZE2imPoy05s3NrdV5LAgLTjuyX+UDtp/EV2WTfYpEP+Emd5kSmXF7 7gAa6C0nAliSpduOxjQsD12PSVsToOrc5CnXNaemS/16UIWhsZIz0T2CwNZuE4mbd8j9XI HtdV9C6O9Qu2SOKnoEJC1WSdobq3lP0= X-Envelope-To: brauner@kernel.org X-Envelope-To: jack@suse.cz 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: linux-fsdevel@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: linux-kernel@vger.kernel.org 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: Alexander Viro , Christian Brauner , Jan Kara , Chris Mason , Josef Bacik , David Sterba , tytso@mit.edu, Andreas Dilger , Jaegeuk Kim , Chao Yu Cc: linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, youling.tang@linux.dev, Youling Tang Subject: [PATCH 2/3] ext4: make ext4 init/exit match their sequence Date: Thu, 11 Jul 2024 15:48:58 +0800 Message-Id: <20240711074859.366088-3-youling.tang@linux.dev> In-Reply-To: <20240711074859.366088-1-youling.tang@linux.dev> References: <20240711074859.366088-1-youling.tang@linux.dev> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT From: Youling Tang Use init_sequence to ensure that modules init and exit are in sequence and to simplify the code. Signed-off-by: Youling Tang --- fs/ext4/super.c | 175 +++++++++++++++++++++++++----------------------- 1 file changed, 93 insertions(+), 82 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index c682fb927b64..ec1e63facb10 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -7314,103 +7314,114 @@ static struct file_system_type ext4_fs_type = { }; MODULE_ALIAS_FS("ext4"); -/* Shared across all ext4 file systems */ -wait_queue_head_t ext4__ioend_wq[EXT4_WQ_HASH_SZ]; - -static int __init ext4_init_fs(void) +static int register_ext(void) { - int i, err; - - ratelimit_state_init(&ext4_mount_msg_ratelimit, 30 * HZ, 64); - ext4_li_info = NULL; + register_as_ext3(); + register_as_ext2(); + return register_filesystem(&ext4_fs_type); +} - /* Build-time check for flags consistency */ - ext4_check_flag_values(); +static void unregister_ext(void) +{ + unregister_as_ext2(); + unregister_as_ext3(); + unregister_filesystem(&ext4_fs_type); +} - for (i = 0; i < EXT4_WQ_HASH_SZ; i++) - init_waitqueue_head(&ext4__ioend_wq[i]); +/* 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); +}; - err = ext4_init_es(); - if (err) - return err; +static const struct init_sequence mod_init_seq[] = { + { + .init_func = ext4_init_es, + .exit_func = ext4_exit_es, + }, { + .init_func = ext4_init_pending, + .exit_func = ext4_exit_pending, + }, { + .init_func = ext4_init_post_read_processing, + .exit_func = ext4_exit_post_read_processing, + }, { + .init_func = ext4_init_pageio, + .exit_func = ext4_exit_pageio, + }, { + .init_func = ext4_init_system_zone, + .exit_func = ext4_exit_system_zone, + }, { + .init_func = ext4_init_sysfs, + .exit_func = ext4_exit_sysfs, + }, { + .init_func = ext4_init_mballoc, + .exit_func = ext4_exit_mballoc, + }, { + .init_func = init_inodecache, + .exit_func = destroy_inodecache, + }, { + .init_func = ext4_fc_init_dentry_cache, + .exit_func = ext4_fc_destroy_dentry_cache, + }, { + .init_func = register_ext, + .exit_func = unregister_ext, + } +}; - err = ext4_init_pending(); - if (err) - goto out7; +static bool mod_init_result[ARRAY_SIZE(mod_init_seq)]; - err = ext4_init_post_read_processing(); - if (err) - goto out6; +static __always_inline void ext4_exit_ext4_fs(void) +{ + int i; - err = ext4_init_pageio(); - if (err) - goto out5; + 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; + } +} - err = ext4_init_system_zone(); - if (err) - goto out4; +static void __exit ext4_exit_fs(void) +{ + ext4_destroy_lazyinit_thread(); + ext4_exit_ext4_fs(); +} - err = ext4_init_sysfs(); - if (err) - goto out3; +static __always_inline int ext4_init_ext4_fs(void) +{ + int ret; + int i; - err = ext4_init_mballoc(); - if (err) - goto out2; - err = init_inodecache(); - if (err) - goto out1; + 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) { + ext4_exit_ext4_fs(); + return ret; + } + mod_init_result[i] = true; + } + return 0; +} - err = ext4_fc_init_dentry_cache(); - if (err) - goto out05; +/* Shared across all ext4 file systems */ +wait_queue_head_t ext4__ioend_wq[EXT4_WQ_HASH_SZ]; - register_as_ext3(); - register_as_ext2(); - err = register_filesystem(&ext4_fs_type); - if (err) - goto out; +static int __init ext4_init_fs(void) +{ + ratelimit_state_init(&ext4_mount_msg_ratelimit, 30 * HZ, 64); + ext4_li_info = NULL; - 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(); + /* Build-time check for flags consistency */ + ext4_check_flag_values(); - return err; -} + for (int i = 0; i < EXT4_WQ_HASH_SZ; i++) + init_waitqueue_head(&ext4__ioend_wq[i]); -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(); + return ext4_init_ext4_fs(); } MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others"); From patchwork Thu Jul 11 07:48:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Youling Tang X-Patchwork-Id: 1959123 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=U0rpWiAW; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=mail.ozlabs.org; envelope-from=srs0=e6e+=ol=vger.kernel.org=linux-ext4+bounces-3191-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WKRjQ3cwdz1xpd for ; Thu, 11 Jul 2024 17:50:34 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4WKRjQ39Rtz4w2J for ; Thu, 11 Jul 2024 17:50:34 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4WKRjQ373Pz4w2N; Thu, 11 Jul 2024 17:50:34 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=U0rpWiAW; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-ext4+bounces-3191-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4WKRjQ30x7z4w2J for ; Thu, 11 Jul 2024 17:50:34 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id F3E67B227DF for ; Thu, 11 Jul 2024 07:50:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC517150992; Thu, 11 Jul 2024 07:49:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="U0rpWiAW" X-Original-To: linux-ext4@vger.kernel.org Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) (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 EAB13150997; Thu, 11 Jul 2024 07:49:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720684190; cv=none; b=RI2S8Yw34hD0zmQ8iak4HzHIwj75KO63gjiNILa065aDHUnb/qB163O26txoU2rDwmwGmM3IzUP8oucV3X0mv3LFVFjYGZmHx+L+x+M6v6/Czebk0y+GH7NpAY6+hVUfknFusQ/pLFd5obegVI2gkDiaya8NuGjIEluZsuEpeuQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720684190; c=relaxed/simple; bh=s4t6ohU0MtcRBXarNqAE1eNK8YuDB//6S6YolUZvKX4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=S1pdwiYppUL2mCjRyrtcuv2aZmSTI5wSUAlDbu2hPaxx0Ix0bgqSkXCnLJau8XAwP55jgE2JR9lrjHzB9kwdWmtVjA230N/aaZtsWgODY8Fe+NjM6A7ad4M2DK9BSttrUH2COLg3Y4U0lTs3cu8C4kOR14hgmGPH9ZKVMvY2LBo= 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=U0rpWiAW; arc=none smtp.client-ip=95.215.58.180 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 X-Envelope-To: viro@zeniv.linux.org.uk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1720684187; 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=mvI9A8h/Y5bWS/0nnv7dns2BHflaYgKGDmzquHt/oQs=; b=U0rpWiAWEUzjZS2+HWWLA903HnIPzwMLBJvJWmYhEPS0mPj8TQrwz9ld5INtXG0BqBCWnh Bm7XYNoSGhKEh3/eZHW/CSN7dDFoUMD6y6afKhy7RPuu0QADwODeT9/CRKNdkWUJ7iiBoa m17x3Jq8dEX2SUUzarB0aP2nOxGRAH0= X-Envelope-To: brauner@kernel.org X-Envelope-To: jack@suse.cz 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: linux-fsdevel@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: linux-kernel@vger.kernel.org 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: Alexander Viro , Christian Brauner , Jan Kara , Chris Mason , Josef Bacik , David Sterba , tytso@mit.edu, Andreas Dilger , Jaegeuk Kim , Chao Yu Cc: linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, youling.tang@linux.dev, Youling Tang Subject: [PATCH 3/3] fs: Add {init, exit}_sequence_fs() helper functions Date: Thu, 11 Jul 2024 15:48:59 +0800 Message-Id: <20240711074859.366088-4-youling.tang@linux.dev> In-Reply-To: <20240711074859.366088-1-youling.tang@linux.dev> References: <20240711074859.366088-1-youling.tang@linux.dev> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT From: Youling Tang In theory init_sequence_fs() and exit_sequence_fs() should match their sequence, thus normally they should look like this: init_sequence_fs() | exit_sequence_fs() -------------------------+------------------------ init_A(); | init_B(); | init_C(); | | exit_C(); | exit_B(); | exit_A(); Providing {init, exit}_sequence_fs() helps functions ensure that modules init/exit match their order, while also simplifying the code. For more details see commit 5565b8e0adcd ("btrfs: make module init/exit match their sequence"). Signed-off-by: Youling Tang --- fs/btrfs/super.c | 36 ++---------------------------------- fs/ext4/super.c | 41 ++--------------------------------------- fs/f2fs/super.c | 36 ++---------------------------------- include/linux/fs.h | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 107 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index f05cce7c8b8d..1101991a9a63 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2478,13 +2478,6 @@ 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, @@ -2551,40 +2544,15 @@ static const struct init_sequence mod_init_seq[] = { 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 void __exit exit_btrfs_fs(void) { - btrfs_exit_btrfs_fs(); + exit_sequence_fs(mod_init_seq, mod_init_result, ARRAY_SIZE(mod_init_seq)); btrfs_cleanup_fs_uuids(); } static int __init init_btrfs_fs(void) { - int ret; - int i; - - 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; + return init_sequence_fs(mod_init_seq, mod_init_result, ARRAY_SIZE(mod_init_seq)); } late_initcall(init_btrfs_fs); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index ec1e63facb10..cb5b7449c80b 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -7328,13 +7328,6 @@ static void unregister_ext(void) unregister_filesystem(&ext4_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 = ext4_init_es, @@ -7371,40 +7364,10 @@ static const struct init_sequence mod_init_seq[] = { static bool mod_init_result[ARRAY_SIZE(mod_init_seq)]; -static __always_inline void ext4_exit_ext4_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 void __exit ext4_exit_fs(void) { ext4_destroy_lazyinit_thread(); - ext4_exit_ext4_fs(); -} - -static __always_inline int ext4_init_ext4_fs(void) -{ - int ret; - int i; - - 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) { - ext4_exit_ext4_fs(); - return ret; - } - mod_init_result[i] = true; - } - return 0; + exit_sequence_fs(mod_init_seq, mod_init_result, ARRAY_SIZE(mod_init_seq)); } /* Shared across all ext4 file systems */ @@ -7421,7 +7384,7 @@ static int __init ext4_init_fs(void) for (int i = 0; i < EXT4_WQ_HASH_SZ; i++) init_waitqueue_head(&ext4__ioend_wq[i]); - return ext4_init_ext4_fs(); + return init_sequence_fs(mod_init_seq, mod_init_result, ARRAY_SIZE(mod_init_seq)); } MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others"); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 19509942b837..b4be24865ab3 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4950,13 +4950,6 @@ static void unregister_f2fs(void) unregister_filesystem(&f2fs_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 = init_inodecache, @@ -5017,39 +5010,14 @@ static const struct init_sequence mod_init_seq[] = { static bool mod_init_result[ARRAY_SIZE(mod_init_seq)]; -static __always_inline void f2fs_exit_f2fs_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 void __exit exit_f2fs_fs(void) { - f2fs_exit_f2fs_fs(); + exit_sequence_fs(mod_init_seq, mod_init_result, ARRAY_SIZE(mod_init_seq)); } static int __init init_f2fs_fs(void) { - int ret; - int i; - - for (i = 0; i < ARRAY_SIZE(mod_init_seq); i++) { - BUG_ON(mod_init_result[i]); - ret = mod_init_seq[i].init_func(); - if (ret < 0) { - f2fs_exit_f2fs_fs(); - return ret; - } - mod_init_result[i] = true; - } - return 0; + return init_sequence_fs(mod_init_seq, mod_init_result, ARRAY_SIZE(mod_init_seq)); } module_init(init_f2fs_fs) diff --git a/include/linux/fs.h b/include/linux/fs.h index 0283cf366c2a..b173194b7f14 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2598,6 +2598,44 @@ extern void iput(struct inode *); int inode_update_timestamps(struct inode *inode, int flags); int generic_update_time(struct inode *, int); +/* 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 __always_inline void exit_sequence_fs(const struct init_sequence *mod_init_seq, + bool *mod_init_result, int num) +{ + int i; + + for (i = num - 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 __always_inline int init_sequence_fs(const struct init_sequence *mod_init_seq, + bool *mod_init_result, int num) +{ + int ret, i; + + for (i = 0; i < num; i++) { + BUG_ON(mod_init_result[i]); + ret = mod_init_seq[i].init_func(); + if (ret < 0) { + exit_sequence_fs(mod_init_seq, mod_init_result, num); + return ret; + } + mod_init_result[i] = true; + } + return 0; +} + /* /sys/fs */ extern struct kobject *fs_kobj;