From nobody Mon Jun 15 02:24:38 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72835C433F5 for ; Fri, 1 Apr 2022 07:04:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343657AbiDAHGV (ORCPT ); Fri, 1 Apr 2022 03:06:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343632AbiDAHGR (ORCPT ); Fri, 1 Apr 2022 03:06:17 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A05BD65D3B for ; Fri, 1 Apr 2022 00:04:27 -0700 (PDT) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KVB3p0gZTz1HBJn; Fri, 1 Apr 2022 15:04:06 +0800 (CST) Received: from dggpeml500009.china.huawei.com (7.185.36.209) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 1 Apr 2022 15:04:25 +0800 Received: from huawei.com (10.175.127.227) by dggpeml500009.china.huawei.com (7.185.36.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 1 Apr 2022 15:04:25 +0800 From: Yufen Yu To: , CC: , , Subject: [PATCH 1/5] f2fs: extract f2fs root debugfs to init_f2fs_fs Date: Fri, 1 Apr 2022 15:19:05 +0800 Message-ID: <20220401071909.505086-2-yuyufen@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220401071909.505086-1-yuyufen@huawei.com> References: <20220401071909.505086-1-yuyufen@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500009.china.huawei.com (7.185.36.209) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Then, we don't need to depend on CONFIG_F2FS_STAT_FS to create f2fs root debugfs directory /sys/kernel/debug/f2fs. This patch is prepared for following f2fs fault injection, which will create sub directory 'fault_inject' into f2fs root debugfs. Signed-off-by: Yufen Yu --- fs/f2fs/debug.c | 19 ++----------------- fs/f2fs/f2fs.h | 4 ++-- fs/f2fs/super.c | 22 ++++++++++++++++++++-- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c index fcdf253cd211..15b3567cd208 100644 --- a/fs/f2fs/debug.c +++ b/fs/f2fs/debug.c @@ -22,9 +22,6 @@ =20 static LIST_HEAD(f2fs_stat_list); static DEFINE_RAW_SPINLOCK(f2fs_stat_lock); -#ifdef CONFIG_DEBUG_FS -static struct dentry *f2fs_debugfs_root; -#endif =20 /* * This function calculates BDF of every segments @@ -648,18 +645,6 @@ void f2fs_destroy_stats(struct f2fs_sb_info *sbi) =20 void __init f2fs_create_root_stats(void) { -#ifdef CONFIG_DEBUG_FS - f2fs_debugfs_root =3D debugfs_create_dir("f2fs", NULL); - - debugfs_create_file("status", 0444, f2fs_debugfs_root, NULL, - &stat_fops); -#endif -} - -void f2fs_destroy_root_stats(void) -{ -#ifdef CONFIG_DEBUG_FS - debugfs_remove_recursive(f2fs_debugfs_root); - f2fs_debugfs_root =3D NULL; -#endif + if (f2fs_debugfs_root) + debugfs_create_file("status", 0444, f2fs_debugfs_root, NULL, &stat_fops); } diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index cd1e65bcf0b0..be3014029a4e 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -62,6 +62,8 @@ enum { FAULT_MAX, }; =20 +extern struct dentry *f2fs_debugfs_root; + #ifdef CONFIG_F2FS_FAULT_INJECTION #define F2FS_ALL_FAULT_TYPE ((1 << FAULT_MAX) - 1) =20 @@ -3994,7 +3996,6 @@ 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); -void f2fs_destroy_root_stats(void); void f2fs_update_sit_info(struct f2fs_sb_info *sbi); #else #define stat_inc_cp_count(si) do { } while (0) @@ -4035,7 +4036,6 @@ 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 void f2fs_destroy_root_stats(void) { } static inline void f2fs_update_sit_info(struct f2fs_sb_info *sbi) {} #endif =20 diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index ea939db18f88..04e41360303c 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -27,6 +27,7 @@ #include #include #include +#include =20 #include "f2fs.h" #include "node.h" @@ -39,6 +40,7 @@ #include =20 static struct kmem_cache *f2fs_inode_cachep; +struct dentry *f2fs_debugfs_root; =20 #ifdef CONFIG_F2FS_FAULT_INJECTION =20 @@ -4575,6 +4577,21 @@ static void destroy_inodecache(void) kmem_cache_destroy(f2fs_inode_cachep); } =20 +static void f2fs_create_debugfs(void) +{ +#ifdef CONFIG_DEBUG_FS + f2fs_debugfs_root =3D debugfs_create_dir("f2fs", NULL); +#endif +} + +static void f2fs_destroy_debugfs(void) +{ +#ifdef CONFIG_DEBUG_FS + debugfs_remove_recursive(f2fs_debugfs_root); + f2fs_debugfs_root =3D NULL; +#endif +} + static int __init init_f2fs_fs(void) { int err; @@ -4615,6 +4632,7 @@ static int __init init_f2fs_fs(void) err =3D register_filesystem(&f2fs_fs_type); if (err) goto free_shrinker; + f2fs_create_debugfs(); f2fs_create_root_stats(); err =3D f2fs_init_post_read_processing(); if (err) @@ -4651,7 +4669,7 @@ static int __init init_f2fs_fs(void) free_post_read: f2fs_destroy_post_read_processing(); free_root_stats: - f2fs_destroy_root_stats(); + f2fs_destroy_debugfs(); unregister_filesystem(&f2fs_fs_type); free_shrinker: unregister_shrinker(&f2fs_shrinker_info); @@ -4684,7 +4702,7 @@ static void __exit exit_f2fs_fs(void) f2fs_destroy_bio_entry_cache(); f2fs_destroy_iostat_processing(); f2fs_destroy_post_read_processing(); - f2fs_destroy_root_stats(); + f2fs_destroy_debugfs(); unregister_filesystem(&f2fs_fs_type); unregister_shrinker(&f2fs_shrinker_info); f2fs_exit_sysfs(); --=20 2.31.1 From nobody Mon Jun 15 02:24:38 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA23BC433EF for ; Fri, 1 Apr 2022 07:04:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343663AbiDAHGX (ORCPT ); Fri, 1 Apr 2022 03:06:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236804AbiDAHGR (ORCPT ); Fri, 1 Apr 2022 03:06:17 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D12FF66CAC for ; Fri, 1 Apr 2022 00:04:27 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KVB3p3Pg2z1HBKp; Fri, 1 Apr 2022 15:04:06 +0800 (CST) Received: from dggpeml500009.china.huawei.com (7.185.36.209) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 1 Apr 2022 15:04:26 +0800 Received: from huawei.com (10.175.127.227) by dggpeml500009.china.huawei.com (7.185.36.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 1 Apr 2022 15:04:25 +0800 From: Yufen Yu To: , CC: , , Subject: [PATCH 2/5] f2fs: use common fault injection frmework Date: Fri, 1 Apr 2022 15:19:06 +0800 Message-ID: <20220401071909.505086-3-yuyufen@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220401071909.505086-1-yuyufen@huawei.com> References: <20220401071909.505086-1-yuyufen@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500009.china.huawei.com (7.185.36.209) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" For now, f2fs use mount options 'fault_injection' and 'fault_type' to enable fault injection. We set inject_type and inject_rate in sysfs to control fault injection. In fact, common fault injection framework have provided a systematic way to support error injection via debugfs, which has more richer and easier control means than the current one. For example, we can set 'interval' to specify the interval between failures, and set 'times' to specify how many times failures may happen at most. More fault injection usage can be seen in (Documentation/ fault-injection/fault-injection.rst) Signed-off-by: Yufen Yu --- fs/f2fs/Kconfig | 2 +- fs/f2fs/Makefile | 1 + fs/f2fs/f2fs.h | 26 ++++++++++++++++ fs/f2fs/fault_inject.c | 67 ++++++++++++++++++++++++++++++++++++++++++ fs/f2fs/super.c | 3 ++ 5 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 fs/f2fs/fault_inject.c diff --git a/fs/f2fs/Kconfig b/fs/f2fs/Kconfig index 03ef087537c7..d40a69077383 100644 --- a/fs/f2fs/Kconfig +++ b/fs/f2fs/Kconfig @@ -86,7 +86,7 @@ config F2FS_CHECK_FS =20 config F2FS_FAULT_INJECTION bool "F2FS fault injection facility" - depends on F2FS_FS + depends on F2FS_FS && FAULT_INJECTION && DEBUG_FS help Test F2FS to inject faults such as ENOMEM, ENOSPC, and so on. =20 diff --git a/fs/f2fs/Makefile b/fs/f2fs/Makefile index 8a7322d229e4..ff25d7095b95 100644 --- a/fs/f2fs/Makefile +++ b/fs/f2fs/Makefile @@ -10,3 +10,4 @@ f2fs-$(CONFIG_F2FS_FS_POSIX_ACL) +=3D acl.o f2fs-$(CONFIG_FS_VERITY) +=3D verity.o f2fs-$(CONFIG_F2FS_FS_COMPRESSION) +=3D compress.o f2fs-$(CONFIG_F2FS_IOSTAT) +=3D iostat.o +f2fs-$(CONFIG_F2FS_FAULT_INJECTION) +=3D fault_inject.o diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index be3014029a4e..50077b0388d1 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -27,6 +27,7 @@ =20 #include #include +#include =20 struct pagevec; =20 @@ -1592,6 +1593,14 @@ struct decompress_io_ctx { struct work_struct verity_work; /* work to verify the decompressed pages = */ }; =20 +struct f2fs_fault_inject { +#ifdef CONFIG_F2FS_FAULT_INJECTION + struct fault_attr attr; + struct dentry *parent; + unsigned int inject_type; +#endif +}; + #define NULL_CLUSTER ((unsigned int)(~0)) #define MIN_COMPRESS_LOG_SIZE 2 #define MAX_COMPRESS_LOG_SIZE 8 @@ -1846,6 +1855,8 @@ struct f2fs_sb_info { spinlock_t iostat_lat_lock; struct iostat_lat_info *iostat_io_lat; #endif + + struct f2fs_fault_inject fault_inject; }; =20 #ifdef CONFIG_F2FS_FAULT_INJECTION @@ -1879,6 +1890,21 @@ static inline bool time_to_inject(struct f2fs_sb_inf= o *sbi, int type) } #endif =20 +#ifdef CONFIG_F2FS_FAULT_INJECTION +bool f2fs_should_fail(struct f2fs_sb_info *sbi, unsigned int type); +void f2fs_fault_inject_init(struct f2fs_sb_info *sbi); +void f2fs_fault_inject_fini(struct f2fs_sb_info *sbi); +void f2fs_stop_fault_inject(struct f2fs_sb_info *sbi); +#else +static inline bool f2fs_should_fail(struct f2fs_sb_info *sbi, unsigned int= type) +{ + return false; +}; +static inline void f2fs_fault_inject_init(struct f2fs_sb_info *sbi) {}; +static inline void f2fs_fault_inject_fini(struct f2fs_sb_info *sbi) {}; +static inline void f2fs_stop_fault_inject(struct f2fs_sb_info *sbi) {}; +#endif + /* * Test if the mounted volume is a multi-device volume. * - For a single regular disk volume, sbi->s_ndevs is 0. diff --git a/fs/f2fs/fault_inject.c b/fs/f2fs/fault_inject.c new file mode 100644 index 000000000000..a62328b38ad6 --- /dev/null +++ b/fs/f2fs/fault_inject.c @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022 Huawei Technologies Co., Ltd. + * + */ +#include +#include "f2fs.h" + +static DECLARE_FAULT_ATTR(fail_default_attr); + +void f2fs_fault_inject_init(struct f2fs_sb_info *sbi) +{ + struct f2fs_fault_inject *fault_inj =3D &sbi->fault_inject; + struct dentry *dir, *parent; + struct fault_attr *attr =3D &fault_inj->attr; + const char *name =3D sbi->sb->s_id; + + if (!f2fs_debugfs_root) { + f2fs_warn(sbi, "root debugfs have not created"); + return; + } + + /* create debugfs directory and attribute */ + parent =3D debugfs_create_dir(name, f2fs_debugfs_root); + if (!parent) { + f2fs_warn(sbi, "%s: failed to create debugfs directory\n", name); + return; + } + + *attr =3D fail_default_attr; + dir =3D fault_create_debugfs_attr("fault_inject", parent, attr); + if (IS_ERR(dir)) { + f2fs_warn(sbi, "%s: failed to create debugfs attr\n", name); + debugfs_remove_recursive(parent); + return; + } + fault_inj->parent =3D parent; + + debugfs_create_x32("inject_type", 0600, dir, &fault_inj->inject_type); +} + +void f2fs_fault_inject_fini(struct f2fs_sb_info *sbi) +{ + struct f2fs_fault_inject *fault_inj =3D &sbi->fault_inject; + + debugfs_remove_recursive(fault_inj->parent); +} + +bool f2fs_should_fail(struct f2fs_sb_info *sbi, unsigned int type) +{ + struct f2fs_fault_inject *fault_inj =3D &sbi->fault_inject; + + if (!(fault_inj->inject_type & (1 << type))) + return false; + + if (!should_fail(&fault_inj->attr, 1)) + return false; + + return true; +} + +void f2fs_stop_fault_inject(struct f2fs_sb_info *sbi) +{ + struct f2fs_fault_inject *fault_inj =3D &sbi->fault_inject; + + fault_inj->inject_type =3D 0; +} diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 04e41360303c..4366469aae80 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1600,6 +1600,8 @@ static void f2fs_put_super(struct super_block *sb) */ f2fs_destroy_stats(sbi); =20 + f2fs_fault_inject_fini(sbi); + /* destroy f2fs internal modules */ f2fs_destroy_node_manager(sbi); f2fs_destroy_segment_manager(sbi); @@ -4418,6 +4420,7 @@ static int f2fs_fill_super(struct super_block *sb, vo= id *data, int silent) f2fs_update_time(sbi, CP_TIME); f2fs_update_time(sbi, REQ_TIME); clear_sbi_flag(sbi, SBI_CP_DISABLED_QUICK); + f2fs_fault_inject_init(sbi); return 0; =20 sync_free_meta: --=20 2.31.1 From nobody Mon Jun 15 02:24:38 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13BADC433EF for ; Fri, 1 Apr 2022 07:04:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343677AbiDAHG1 (ORCPT ); Fri, 1 Apr 2022 03:06:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343638AbiDAHGS (ORCPT ); Fri, 1 Apr 2022 03:06:18 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFE14692A8 for ; Fri, 1 Apr 2022 00:04:28 -0700 (PDT) Received: from dggpeml500026.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KVB1c0zj7zDq6P; Fri, 1 Apr 2022 15:02:12 +0800 (CST) Received: from dggpeml500009.china.huawei.com (7.185.36.209) by dggpeml500026.china.huawei.com (7.185.36.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 1 Apr 2022 15:04:26 +0800 Received: from huawei.com (10.175.127.227) by dggpeml500009.china.huawei.com (7.185.36.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 1 Apr 2022 15:04:26 +0800 From: Yufen Yu To: , CC: , , Subject: [PATCH 3/5] f2fs: replace function time_to_inject by f2fs_should_fail Date: Fri, 1 Apr 2022 15:19:07 +0800 Message-ID: <20220401071909.505086-4-yuyufen@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220401071909.505086-1-yuyufen@huawei.com> References: <20220401071909.505086-1-yuyufen@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500009.china.huawei.com (7.185.36.209) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace all time_to_inject by f2fs_should_fail to apply new fault inject. Signed-off-by: Yufen Yu --- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/data.c | 4 ++-- fs/f2fs/dir.c | 2 +- fs/f2fs/f2fs.h | 16 ++++++++-------- fs/f2fs/file.c | 2 +- fs/f2fs/gc.c | 2 +- fs/f2fs/inode.c | 2 +- fs/f2fs/node.c | 2 +- fs/f2fs/segment.c | 4 ++-- fs/f2fs/super.c | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index a8fc4fa511a8..820eb95b08f1 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -611,7 +611,7 @@ int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi) =20 spin_lock(&im->ino_lock); =20 - if (time_to_inject(sbi, FAULT_ORPHAN)) { + if (f2fs_should_fail(sbi, FAULT_ORPHAN)) { spin_unlock(&im->ino_lock); f2fs_show_injection_info(sbi, FAULT_ORPHAN); return -ENOSPC; diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index f8fcbe91059b..c070d64504d6 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -276,7 +276,7 @@ static void f2fs_read_end_io(struct bio *bio) iostat_update_and_unbind_ctx(bio, 0); ctx =3D bio->bi_private; =20 - if (time_to_inject(sbi, FAULT_READ_IO)) { + if (f2fs_should_fail(sbi, FAULT_READ_IO)) { f2fs_show_injection_info(sbi, FAULT_READ_IO); bio->bi_status =3D BLK_STS_IOERR; } @@ -303,7 +303,7 @@ static void f2fs_write_end_io(struct bio *bio) iostat_update_and_unbind_ctx(bio, 1); sbi =3D bio->bi_private; =20 - if (time_to_inject(sbi, FAULT_WRITE_IO)) { + if (f2fs_should_fail(sbi, FAULT_WRITE_IO)) { f2fs_show_injection_info(sbi, FAULT_WRITE_IO); bio->bi_status =3D BLK_STS_IOERR; } diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index a0e51937d92e..ab50f8f3597b 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -727,7 +727,7 @@ int f2fs_add_regular_entry(struct inode *dir, const str= uct f2fs_filename *fname, } =20 start: - if (time_to_inject(F2FS_I_SB(dir), FAULT_DIR_DEPTH)) { + if (f2fs_should_fail(F2FS_I_SB(dir), FAULT_DIR_DEPTH)) { f2fs_show_injection_info(F2FS_I_SB(dir), FAULT_DIR_DEPTH); return -ENOSPC; } diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 50077b0388d1..beb935f807d6 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2231,7 +2231,7 @@ static inline void f2fs_lock_op(struct f2fs_sb_info *= sbi) =20 static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) { - if (time_to_inject(sbi, FAULT_LOCK_OP)) { + if (f2fs_should_fail(sbi, FAULT_LOCK_OP)) { f2fs_show_injection_info(sbi, FAULT_LOCK_OP); return 0; } @@ -2321,7 +2321,7 @@ static inline int inc_valid_block_count(struct f2fs_s= b_info *sbi, if (ret) return ret; =20 - if (time_to_inject(sbi, FAULT_BLOCK)) { + if (f2fs_should_fail(sbi, FAULT_BLOCK)) { f2fs_show_injection_info(sbi, FAULT_BLOCK); release =3D *count; goto release_quota; @@ -2579,7 +2579,7 @@ static inline int inc_valid_node_count(struct f2fs_sb= _info *sbi, return err; } =20 - if (time_to_inject(sbi, FAULT_BLOCK)) { + if (f2fs_should_fail(sbi, FAULT_BLOCK)) { f2fs_show_injection_info(sbi, FAULT_BLOCK); goto enospc; } @@ -2699,7 +2699,7 @@ static inline struct page *f2fs_grab_cache_page(struc= t address_space *mapping, if (page) return page; =20 - if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { + if (f2fs_should_fail(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { f2fs_show_injection_info(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC); return NULL; @@ -2715,7 +2715,7 @@ static inline struct page *f2fs_pagecache_get_page( struct address_space *mapping, pgoff_t index, int fgp_flags, gfp_t gfp_mask) { - if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) { + if (f2fs_should_fail(F2FS_M_SB(mapping), FAULT_PAGE_GET)) { f2fs_show_injection_info(F2FS_M_SB(mapping), FAULT_PAGE_GET); return NULL; } @@ -2778,7 +2778,7 @@ static inline void *f2fs_kmem_cache_alloc(struct kmem= _cache *cachep, if (nofail) return f2fs_kmem_cache_alloc_nofail(cachep, flags); =20 - if (time_to_inject(sbi, FAULT_SLAB_ALLOC)) { + if (f2fs_should_fail(sbi, FAULT_SLAB_ALLOC)) { f2fs_show_injection_info(sbi, FAULT_SLAB_ALLOC); return NULL; } @@ -3350,7 +3350,7 @@ static inline bool is_dot_dotdot(const u8 *name, size= _t len) static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, size_t size, gfp_t flags) { - if (time_to_inject(sbi, FAULT_KMALLOC)) { + if (f2fs_should_fail(sbi, FAULT_KMALLOC)) { f2fs_show_injection_info(sbi, FAULT_KMALLOC); return NULL; } @@ -3367,7 +3367,7 @@ static inline void *f2fs_kzalloc(struct f2fs_sb_info = *sbi, static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi, size_t size, gfp_t flags) { - if (time_to_inject(sbi, FAULT_KVMALLOC)) { + if (f2fs_should_fail(sbi, FAULT_KVMALLOC)) { f2fs_show_injection_info(sbi, FAULT_KVMALLOC); return NULL; } diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index d3f39a704b8b..b73729c111bd 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -782,7 +782,7 @@ int f2fs_truncate(struct inode *inode) =20 trace_f2fs_truncate(inode); =20 - if (time_to_inject(F2FS_I_SB(inode), FAULT_TRUNCATE)) { + if (f2fs_should_fail(F2FS_I_SB(inode), FAULT_TRUNCATE)) { f2fs_show_injection_info(F2FS_I_SB(inode), FAULT_TRUNCATE); return -EIO; } diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index ea5b93b689cd..0a513c5e6b1e 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -68,7 +68,7 @@ static int gc_thread_func(void *data) continue; } =20 - if (time_to_inject(sbi, FAULT_CHECKPOINT)) { + if (f2fs_should_fail(sbi, FAULT_CHECKPOINT)) { f2fs_show_injection_info(sbi, FAULT_CHECKPOINT); f2fs_stop_checkpoint(sbi, false); } diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index 71f232dcf3c2..036e40fca681 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -786,7 +786,7 @@ void f2fs_evict_inode(struct inode *inode) if (F2FS_HAS_BLOCKS(inode)) err =3D f2fs_truncate(inode); =20 - if (time_to_inject(sbi, FAULT_EVICT_INODE)) { + if (f2fs_should_fail(sbi, FAULT_EVICT_INODE)) { f2fs_show_injection_info(sbi, FAULT_EVICT_INODE); err =3D -EIO; } diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 0b6e741e94a0..ee9ddbe5630e 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -2543,7 +2543,7 @@ bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *= nid) struct f2fs_nm_info *nm_i =3D NM_I(sbi); struct free_nid *i =3D NULL; retry: - if (time_to_inject(sbi, FAULT_ALLOC_NID)) { + if (f2fs_should_fail(sbi, FAULT_ALLOC_NID)) { f2fs_show_injection_info(sbi, FAULT_ALLOC_NID); return false; } diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 22dfeb991529..1e1436b8c125 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -493,7 +493,7 @@ int f2fs_commit_inmem_pages(struct inode *inode) */ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need) { - if (time_to_inject(sbi, FAULT_CHECKPOINT)) { + if (f2fs_should_fail(sbi, FAULT_CHECKPOINT)) { f2fs_show_injection_info(sbi, FAULT_CHECKPOINT); f2fs_stop_checkpoint(sbi, false); } @@ -1237,7 +1237,7 @@ static int __submit_discard_cmd(struct f2fs_sb_info *= sbi, =20 dc->len +=3D len; =20 - if (time_to_inject(sbi, FAULT_DISCARD)) { + if (f2fs_should_fail(sbi, FAULT_DISCARD)) { f2fs_show_injection_info(sbi, FAULT_DISCARD); err =3D -EIO; goto submit; diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 4366469aae80..e18f60165f44 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1347,7 +1347,7 @@ static struct inode *f2fs_alloc_inode(struct super_bl= ock *sb) { struct f2fs_inode_info *fi; =20 - if (time_to_inject(F2FS_SB(sb), FAULT_SLAB_ALLOC)) { + if (f2fs_should_fail(F2FS_SB(sb), FAULT_SLAB_ALLOC)) { f2fs_show_injection_info(F2FS_SB(sb), FAULT_SLAB_ALLOC); return NULL; } @@ -2551,7 +2551,7 @@ static ssize_t f2fs_quota_write(struct super_block *s= b, int type, =20 int f2fs_dquot_initialize(struct inode *inode) { - if (time_to_inject(F2FS_I_SB(inode), FAULT_DQUOT_INIT)) { + if (f2fs_should_fail(F2FS_I_SB(inode), FAULT_DQUOT_INIT)) { f2fs_show_injection_info(F2FS_I_SB(inode), FAULT_DQUOT_INIT); return -ESRCH; } --=20 2.31.1 From nobody Mon Jun 15 02:24:38 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3817C433EF for ; Fri, 1 Apr 2022 07:04:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343690AbiDAHGc (ORCPT ); Fri, 1 Apr 2022 03:06:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343637AbiDAHGS (ORCPT ); Fri, 1 Apr 2022 03:06:18 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFF3769CCB for ; Fri, 1 Apr 2022 00:04:28 -0700 (PDT) Received: from dggpeml500025.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KVB3p6VZyzdZLS; Fri, 1 Apr 2022 15:04:06 +0800 (CST) Received: from dggpeml500009.china.huawei.com (7.185.36.209) by dggpeml500025.china.huawei.com (7.185.36.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 1 Apr 2022 15:04:27 +0800 Received: from huawei.com (10.175.127.227) by dggpeml500009.china.huawei.com (7.185.36.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 1 Apr 2022 15:04:26 +0800 From: Yufen Yu To: , CC: , , Subject: [PATCH 4/5] f2fs: get rid of stale fault injection code Date: Fri, 1 Apr 2022 15:19:08 +0800 Message-ID: <20220401071909.505086-5-yuyufen@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220401071909.505086-1-yuyufen@huawei.com> References: <20220401071909.505086-1-yuyufen@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500009.china.huawei.com (7.185.36.209) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Nowly, we can use new fault injection framework. Just delete the stale fault injection code. Signed-off-by: Yufen Yu --- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/f2fs.h | 51 ++---------------------------------------- fs/f2fs/super.c | 53 -------------------------------------------- fs/f2fs/sysfs.c | 23 ------------------- 4 files changed, 3 insertions(+), 126 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 820eb95b08f1..88e419db5782 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -28,7 +28,7 @@ struct kmem_cache *f2fs_inode_entry_slab; =20 void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io) { - f2fs_build_fault_attr(sbi, 0, 0); + f2fs_stop_fault_inject(sbi); set_ckpt_flags(sbi, CP_ERROR_FLAG); if (!end_io) f2fs_flush_merged_writes(sbi); diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index beb935f807d6..61b07eb4bb7b 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -65,19 +65,6 @@ enum { =20 extern struct dentry *f2fs_debugfs_root; =20 -#ifdef CONFIG_F2FS_FAULT_INJECTION -#define F2FS_ALL_FAULT_TYPE ((1 << FAULT_MAX) - 1) - -struct f2fs_fault_info { - atomic_t inject_ops; - unsigned int inject_rate; - unsigned int inject_type; -}; - -extern const char *f2fs_fault_name[FAULT_MAX]; -#define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) -#endif - /* * For mount options */ @@ -148,9 +135,6 @@ struct f2fs_mount_info { kgid_t s_resgid; /* reserved blocks for gid */ int active_logs; /* # of active logs */ int inline_xattr_size; /* inline xattr size */ -#ifdef CONFIG_F2FS_FAULT_INJECTION - struct f2fs_fault_info fault_info; /* For fault injection */ -#endif #ifdef CONFIG_QUOTA /* Names of quota files with journalled quota */ char *s_qf_names[MAXQUOTAS]; @@ -1860,42 +1844,18 @@ struct f2fs_sb_info { }; =20 #ifdef CONFIG_F2FS_FAULT_INJECTION +extern const char *f2fs_fault_name[FAULT_MAX]; #define f2fs_show_injection_info(sbi, type) \ printk_ratelimited("%sF2FS-fs (%s) : inject %s in %s of %pS\n", \ KERN_INFO, sbi->sb->s_id, \ f2fs_fault_name[type], \ __func__, __builtin_return_address(0)) -static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) -{ - struct f2fs_fault_info *ffi =3D &F2FS_OPTION(sbi).fault_info; - - if (!ffi->inject_rate) - return false; - - if (!IS_FAULT_SET(ffi, type)) - return false; - - atomic_inc(&ffi->inject_ops); - if (atomic_read(&ffi->inject_ops) >=3D ffi->inject_rate) { - atomic_set(&ffi->inject_ops, 0); - return true; - } - return false; -} -#else -#define f2fs_show_injection_info(sbi, type) do { } while (0) -static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) -{ - return false; -} -#endif - -#ifdef CONFIG_F2FS_FAULT_INJECTION bool f2fs_should_fail(struct f2fs_sb_info *sbi, unsigned int type); void f2fs_fault_inject_init(struct f2fs_sb_info *sbi); void f2fs_fault_inject_fini(struct f2fs_sb_info *sbi); void f2fs_stop_fault_inject(struct f2fs_sb_info *sbi); #else +#define f2fs_show_injection_info(sbi, type) do { } while (0) static inline bool f2fs_should_fail(struct f2fs_sb_info *sbi, unsigned int= type) { return false; @@ -4538,13 +4498,6 @@ static inline bool f2fs_need_verity(const struct ino= de *inode, pgoff_t idx) idx < DIV_ROUND_UP(inode->i_size, PAGE_SIZE); } =20 -#ifdef CONFIG_F2FS_FAULT_INJECTION -extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int r= ate, - unsigned int type); -#else -#define f2fs_build_fault_attr(sbi, rate, type) do { } while (0) -#endif - static inline bool is_journalled_quota(struct f2fs_sb_info *sbi) { #ifdef CONFIG_QUOTA diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index e18f60165f44..859ae5068761 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -64,22 +64,6 @@ const char *f2fs_fault_name[FAULT_MAX] =3D { [FAULT_LOCK_OP] =3D "lock_op", }; =20 -void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, - unsigned int type) -{ - struct f2fs_fault_info *ffi =3D &F2FS_OPTION(sbi).fault_info; - - if (rate) { - atomic_set(&ffi->inject_ops, 0); - ffi->inject_rate =3D rate; - } - - if (type) - ffi->inject_type =3D type; - - if (!rate && !type) - memset(ffi, 0, sizeof(struct f2fs_fault_info)); -} #endif =20 /* f2fs-wide shrinker description */ @@ -122,8 +106,6 @@ enum { Opt_resuid, Opt_mode, Opt_io_size_bits, - Opt_fault_injection, - Opt_fault_type, Opt_lazytime, Opt_nolazytime, Opt_quota, @@ -198,8 +180,6 @@ static match_table_t f2fs_tokens =3D { {Opt_resuid, "resuid=3D%u"}, {Opt_mode, "mode=3D%s"}, {Opt_io_size_bits, "io_bits=3D%u"}, - {Opt_fault_injection, "fault_injection=3D%u"}, - {Opt_fault_type, "fault_type=3D%u"}, {Opt_lazytime, "lazytime"}, {Opt_nolazytime, "nolazytime"}, {Opt_quota, "quota"}, @@ -874,29 +854,6 @@ static int parse_options(struct super_block *sb, char = *options, bool is_remount) } F2FS_OPTION(sbi).write_io_size_bits =3D arg; break; -#ifdef CONFIG_F2FS_FAULT_INJECTION - case Opt_fault_injection: - if (args->from && match_int(args, &arg)) - return -EINVAL; - f2fs_build_fault_attr(sbi, arg, F2FS_ALL_FAULT_TYPE); - set_opt(sbi, FAULT_INJECTION); - break; - - case Opt_fault_type: - if (args->from && match_int(args, &arg)) - return -EINVAL; - f2fs_build_fault_attr(sbi, 0, arg); - set_opt(sbi, FAULT_INJECTION); - break; -#else - case Opt_fault_injection: - f2fs_info(sbi, "fault_injection options not supported"); - break; - - case Opt_fault_type: - f2fs_info(sbi, "fault_type options not supported"); - break; -#endif case Opt_lazytime: sb->s_flags |=3D SB_LAZYTIME; break; @@ -1963,14 +1920,6 @@ static int f2fs_show_options(struct seq_file *seq, s= truct dentry *root) if (F2FS_IO_SIZE_BITS(sbi)) seq_printf(seq, ",io_bits=3D%u", F2FS_OPTION(sbi).write_io_size_bits); -#ifdef CONFIG_F2FS_FAULT_INJECTION - if (test_opt(sbi, FAULT_INJECTION)) { - seq_printf(seq, ",fault_injection=3D%u", - F2FS_OPTION(sbi).fault_info.inject_rate); - seq_printf(seq, ",fault_type=3D%u", - F2FS_OPTION(sbi).fault_info.inject_type); - } -#endif #ifdef CONFIG_QUOTA if (test_opt(sbi, QUOTA)) seq_puts(seq, ",quota"); @@ -2076,8 +2025,6 @@ static void default_options(struct f2fs_sb_info *sbi) #ifdef CONFIG_F2FS_FS_POSIX_ACL set_opt(sbi, POSIX_ACL); #endif - - f2fs_build_fault_attr(sbi, 0, 0); } =20 #ifdef CONFIG_QUOTA diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index 4c50aedd5144..85af2e97d565 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -31,10 +31,6 @@ enum { F2FS_SBI, /* struct f2fs_sb_info */ #ifdef CONFIG_F2FS_STAT_FS STAT_INFO, /* struct f2fs_stat_info */ -#endif -#ifdef CONFIG_F2FS_FAULT_INJECTION - FAULT_INFO_RATE, /* struct f2fs_fault_info */ - FAULT_INFO_TYPE, /* struct f2fs_fault_info */ #endif RESERVED_BLOCKS, /* struct f2fs_sb_info */ CPRC_INFO, /* struct ckpt_req_control */ @@ -76,11 +72,6 @@ static unsigned char *__struct_ptr(struct f2fs_sb_info *= sbi, int struct_type) return (unsigned char *)NM_I(sbi); else if (struct_type =3D=3D F2FS_SBI || struct_type =3D=3D RESERVED_BLOCK= S) return (unsigned char *)sbi; -#ifdef CONFIG_F2FS_FAULT_INJECTION - else if (struct_type =3D=3D FAULT_INFO_RATE || - struct_type =3D=3D FAULT_INFO_TYPE) - return (unsigned char *)&F2FS_OPTION(sbi).fault_info; -#endif #ifdef CONFIG_F2FS_STAT_FS else if (struct_type =3D=3D STAT_INFO) return (unsigned char *)F2FS_STAT(sbi); @@ -429,12 +420,6 @@ static ssize_t __sbi_store(struct f2fs_attr *a, ret =3D kstrtoul(skip_spaces(buf), 0, &t); if (ret < 0) return ret; -#ifdef CONFIG_F2FS_FAULT_INJECTION - if (a->struct_type =3D=3D FAULT_INFO_TYPE && t >=3D (1 << FAULT_MAX)) - return -EINVAL; - if (a->struct_type =3D=3D FAULT_INFO_RATE && t >=3D UINT_MAX) - return -EINVAL; -#endif if (a->struct_type =3D=3D RESERVED_BLOCKS) { spin_lock(&sbi->stat_lock); if (t > (unsigned long)(sbi->user_block_count - @@ -773,10 +758,6 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readd= ir_ra); F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_io_bytes, max_io_bytes); F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_thres= hold); F2FS_RW_ATTR(F2FS_SBI, f2fs_super_block, extension_list, extension_list); -#ifdef CONFIG_F2FS_FAULT_INJECTION -F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate); -F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type); -#endif F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, data_io_flag, data_io_flag); F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, node_io_flag, node_io_flag); F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent_high_remaining, gc_urgent_h= igh_remaining); @@ -892,10 +873,6 @@ static struct attribute *f2fs_attrs[] =3D { ATTR_LIST(max_io_bytes), ATTR_LIST(gc_pin_file_thresh), ATTR_LIST(extension_list), -#ifdef CONFIG_F2FS_FAULT_INJECTION - ATTR_LIST(inject_rate), - ATTR_LIST(inject_type), -#endif ATTR_LIST(data_io_flag), ATTR_LIST(node_io_flag), ATTR_LIST(gc_urgent_high_remaining), --=20 2.31.1 From nobody Mon Jun 15 02:24:38 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 665E6C433EF for ; Fri, 1 Apr 2022 07:04:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343708AbiDAHGh (ORCPT ); Fri, 1 Apr 2022 03:06:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343644AbiDAHGS (ORCPT ); Fri, 1 Apr 2022 03:06:18 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 273266A06D for ; Fri, 1 Apr 2022 00:04:29 -0700 (PDT) Received: from dggpeml500020.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4KV9zV1g9QzBrvk; Fri, 1 Apr 2022 15:00:22 +0800 (CST) Received: from dggpeml500009.china.huawei.com (7.185.36.209) by dggpeml500020.china.huawei.com (7.185.36.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 1 Apr 2022 15:04:27 +0800 Received: from huawei.com (10.175.127.227) by dggpeml500009.china.huawei.com (7.185.36.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 1 Apr 2022 15:04:27 +0800 From: Yufen Yu To: , CC: , , Subject: [PATCH 5/5] f2fs: update doc for f2fs fault injection Date: Fri, 1 Apr 2022 15:19:09 +0800 Message-ID: <20220401071909.505086-6-yuyufen@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220401071909.505086-1-yuyufen@huawei.com> References: <20220401071909.505086-1-yuyufen@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500009.china.huawei.com (7.185.36.209) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Just update doc for fault injection. Signed-off-by: Yufen Yu --- Documentation/filesystems/f2fs.rst | 118 ++++++++++++++++++++++------- 1 file changed, 90 insertions(+), 28 deletions(-) diff --git a/Documentation/filesystems/f2fs.rst b/Documentation/filesystems= /f2fs.rst index 4a2426f0485a..e8dfe1541613 100644 --- a/Documentation/filesystems/f2fs.rst +++ b/Documentation/filesystems/f2fs.rst @@ -172,34 +172,6 @@ reserve_root=3D%d Support configuring reserved space= which is used for gid, unit: 4KB, the default limit is 0.2% of user blocks. resuid=3D%d The user ID which may use the reserved blocks. resgid=3D%d The group ID which may use the reserved blocks. -fault_injection=3D%d Enable fault injection in all supported types with - specified injection rate. -fault_type=3D%d Support configuring fault injection type, should be - enabled with fault_injection option, fault type value - is shown below, it supports single or combined type. - - =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D - Type_Name Type_Value - =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D - FAULT_KMALLOC 0x000000001 - FAULT_KVMALLOC 0x000000002 - FAULT_PAGE_ALLOC 0x000000004 - FAULT_PAGE_GET 0x000000008 - FAULT_ALLOC_BIO 0x000000010 (obsolete) - FAULT_ALLOC_NID 0x000000020 - FAULT_ORPHAN 0x000000040 - FAULT_BLOCK 0x000000080 - FAULT_DIR_DEPTH 0x000000100 - FAULT_EVICT_INODE 0x000000200 - FAULT_TRUNCATE 0x000000400 - FAULT_READ_IO 0x000000800 - FAULT_CHECKPOINT 0x000001000 - FAULT_DISCARD 0x000002000 - FAULT_WRITE_IO 0x000004000 - FAULT_SLAB_ALLOC 0x000008000 - FAULT_DQUOT_INIT 0x000010000 - FAULT_LOCK_OP 0x000020000 - =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D mode=3D%s Control block allocation mode which supports "adaptive" and "lfs". In "lfs" mode, there should be no random writes towards main area. @@ -367,6 +339,96 @@ The files in each per-device directory are shown in ta= ble below. Files in /sys/fs/f2fs/ (see also Documentation/ABI/testing/sysfs-fs-f2fs) =20 +Fault Injection +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +/sys/kernel/debug/f2fs//fault_inject contains fault_inject contro= l. + +Support configuring fault injection type by writing value to +/sys/kernel/debug/f2fs//fault_inject/inject_type. +The values are shown below. They support single or combined type. + + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D + Type_Name Type_Value + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D + FAULT_KMALLOC 0x000000001 + FAULT_KVMALLOC 0x000000002 + FAULT_PAGE_ALLOC 0x000000004 + FAULT_PAGE_GET 0x000000008 + FAULT_ALLOC_BIO 0x000000010 (obsolete) + FAULT_ALLOC_NID 0x000000020 + FAULT_ORPHAN 0x000000040 + FAULT_BLOCK 0x000000080 + FAULT_DIR_DEPTH 0x000000100 + FAULT_EVICT_INODE 0x000000200 + FAULT_TRUNCATE 0x000000400 + FAULT_READ_IO 0x000000800 + FAULT_CHECKPOINT 0x000001000 + FAULT_DISCARD 0x000002000 + FAULT_WRITE_IO 0x000004000 + FAULT_SLAB_ALLOC 0x000008000 + FAULT_DQUOT_INIT 0x000010000 + FAULT_LOCK_OP 0x000020000 + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D + +Example: Inject write io fail +--------------------------------------------------- + +:: + + mount /dev/sda /mnt + echo 0x000000800 > /sys/kernel/debug/f2fs/sda/fault_inject/inject_type + echo 1 > /sys/kernel/debug/f2fs/sda/fault_inject/times + echo 100 > /sys/kernel/debug/f2fs/sda/fault_inject/probability + cp /mnt/file . + +Expected Result:: + + cat: /mnt/file: Input/output error + +Message from dmesg:: + + FAULT_INJECTION: forcing a failure. + name fault_inject, interval 1, probability 100, space 0, times 1 + CPU: 30 PID: 0 Comm: swapper/30 Not tainted 5.17.0-rc8 #6 + Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ?-20190727= _073836-build + Call Trace: + + ? dump_stack_lvl+0x73/0x9f + ? dump_stack+0x13/0x1b + ? should_fail.cold+0x4a/0x57 + ? f2fs_should_fail+0x3e/0x60 + ? f2fs_read_end_io+0x94/0x230 + ? bio_endio+0x15d/0x2d0 + ? blk_update_request+0x188/0x5b0 + ? kfree+0x138/0x4a0 + ? scsi_end_request+0x2f/0x230 + ? scsi_io_completion+0x86/0x9a0 + ? scsi_dec_host_busy+0xc6/0xe0 + ? scsi_finish_command+0xf0/0x160 + ? scsi_complete+0x9f/0x160 + ? blk_complete_reqs+0x5a/0x70 + ? blk_done_softirq+0x34/0x40 + ? __do_softirq+0x14f/0x4ef + ? irq_exit_rcu+0x1a7/0x210 + ? common_interrupt+0xa4/0xc0 + + + ? asm_common_interrupt+0x1e/0x40 + ? default_idle+0x38/0x50 + ? arch_cpu_idle+0x13/0x20 + ? default_idle_call+0x82/0x270 + ? do_idle+0x37c/0x4a0 + ? swake_up_locked+0x38/0x80 + ? _raw_spin_unlock_irqrestore+0x4b/0x90 + ? cpu_startup_entry+0x31/0x40 + ? start_secondary+0x222/0x280 + ? secondary_startup_64_no_verify+0xc3/0xcb + + F2FS-fs (sda) : inject read IO error in f2fs_read_end_io of bio_endio+= 0x15d/0x2d0 + +Files in /sys/kernel/debug/f2fs//fault_inject +(see also Documentation/fault-injection/fault-injection.rst) + Usage =3D=3D=3D=3D=3D =20 --=20 2.31.1