From patchwork Thu Mar 20 02:22:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 14023339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3076EC35FFC for ; Thu, 20 Mar 2025 02:23:11 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1tv5Ys-0006H6-3i; Thu, 20 Mar 2025 02:23:10 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tv5Yo-0006Gy-Vo for linux-f2fs-devel@lists.sourceforge.net; Thu, 20 Mar 2025 02:23:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=f6H4Jedbbn/7Mk64z/C8NQiQ6n2WCvY14Q8pE2Ff4rw=; b=BwgJbun4T/ZuQgpzXoM2zEl84z KOkWqkeLNhIyLiy3KOkwYoYTMQtkLiQ4AC2plJ1tb5V8gWcInm3WVL8uQV6MjmGjsR60aAZcnuOpk rwb7PYx42px1PKg6nnXEXwTAWBSzZ0DWBimDuaddOfZ6FeM7s/WLV4yx75vwDb2dOfro=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=f6H4Jedbbn/7Mk64z/C8NQiQ6n2WCvY14Q8pE2Ff4rw=; b=l ajW1Njf7UCNY6YuaNPMZt6HPvPnwobFBGQdKNJatGR3ThQZ5QwGlYpyrdrOViLzC/hTNlrioyuPe6 o59K2SA9uTW9Fdk6l/zqAOBUbygqMQaNF+rv3xfExFTMAp6o/WXGAhpyJAyBbpSqSuSC/dkFOSUAs VJ0xxe6tF/0axth4=; Received: from tor.source.kernel.org ([172.105.4.254]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1tv5Ye-0007LX-4q for linux-f2fs-devel@lists.sourceforge.net; Thu, 20 Mar 2025 02:23:06 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id F2A5768324 for ; Thu, 20 Mar 2025 02:22:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0316C4CEE4; Thu, 20 Mar 2025 02:22:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742437365; bh=W7q6/PTwJrqZQUKTE/L2eAuHe1DXB/d42aG5MQ4jxcA=; h=From:To:Cc:Subject:Date:From; b=SCk442lmYPaXAGDnk5j7Z3iS8kIKBgaGbOHm5Qqd3iKft7cefuA2aemDt2LhRE6L5 RPk9Ulu4TfOESGU9MlfQG3eJaCvIJadkpZ6qw6Pn0ycmdcFul8THx3d4ySQKdodBuy e0QeN5I6cYzacySyNpk8lJM3WP+MoWQOL06ssfQY4Q9tlSIgyd9kmFpwFi5rVkRstP IsUziD6c/kQQdZoWGlIcRc9hOf0D8/W3EXaAMh3Vl/XabFjqaXdYOA2gZUNMLvb+wM agp09fdxMq+Wr+uh2S5rQzQB/6r/BLtq9RsM10IpuW5YWJ7miaOiQ8yLzBX3UHvr5I jjhKaVBQZi+KQ== To: jaegeuk@kernel.org Date: Thu, 20 Mar 2025 10:22:29 +0800 Message-ID: <20250320022230.1938110-1-chao@kernel.org> X-Mailer: git-send-email 2.49.0.395.g12beb8f557-goog MIME-Version: 1.0 X-Headers-End: 1tv5Ye-0007LX-4q Subject: [f2fs-dev] [PATCH v2 1/2] f2fs: add a proc entry show inject stats X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Chao Yu via Linux-f2fs-devel From: Chao Yu Reply-To: Chao Yu Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This patch adds a proc entry named inject_stats to show total injected count for each fault type. cat /proc/fs/f2fs//inject_stats fault_type injected_count kmalloc 0 kvmalloc 0 page alloc 0 page get 0 alloc bio(obsolete) 0 alloc nid 0 orphan 0 no more block 0 too big dir depth 0 evict_inode fail 0 truncate fail 0 read IO error 0 checkpoint error 0 discard error 0 write IO error 0 slab alloc 0 dquot initialize 0 lock_op 0 invalid blkaddr 0 inconsistent blkaddr 0 no free segment 0 inconsistent footer 0 Signed-off-by: Chao Yu Reviewed-by: Zhiguo Niu --- v2: - add missing CONFIG_F2FS_FAULT_INJECTION fs/f2fs/f2fs.h | 3 +++ fs/f2fs/super.c | 1 + fs/f2fs/sysfs.c | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index f1576dc6ec67..986ee5b9326d 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -73,6 +73,8 @@ struct f2fs_fault_info { atomic_t inject_ops; int inject_rate; unsigned int inject_type; + /* Used to account total count of injection for each type */ + unsigned int inject_count[FAULT_MAX]; }; extern const char *f2fs_fault_name[FAULT_MAX]; @@ -1902,6 +1904,7 @@ static inline bool __time_to_inject(struct f2fs_sb_info *sbi, int type, atomic_inc(&ffi->inject_ops); if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { atomic_set(&ffi->inject_ops, 0); + ffi->inject_count[type]++; f2fs_info_ratelimited(sbi, "inject %s in %s of %pS", f2fs_fault_name[type], func, parent_func); return true; diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index f087b2b71c89..dfe0604ab558 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -47,6 +47,7 @@ const char *f2fs_fault_name[FAULT_MAX] = { [FAULT_KVMALLOC] = "kvmalloc", [FAULT_PAGE_ALLOC] = "page alloc", [FAULT_PAGE_GET] = "page get", + [FAULT_ALLOC_BIO] = "alloc bio(obsolete)", [FAULT_ALLOC_NID] = "alloc nid", [FAULT_ORPHAN] = "orphan", [FAULT_BLOCK] = "no more block", diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index c69161366467..46fa94db08a8 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -1679,6 +1679,24 @@ static int __maybe_unused disk_map_seq_show(struct seq_file *seq, return 0; } +#ifdef CONFIG_F2FS_FAULT_INJECTION +static int __maybe_unused inject_stats_seq_show(struct seq_file *seq, + void *offset) +{ + struct super_block *sb = seq->private; + struct f2fs_sb_info *sbi = F2FS_SB(sb); + struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; + int i; + + seq_puts(seq, "fault_type injected_count\n"); + + for (i = 0; i < FAULT_MAX; i++) + seq_printf(seq, "%-24s%-10u\n", f2fs_fault_name[i], + ffi->inject_count[i]); + return 0; +} +#endif + int __init f2fs_init_sysfs(void) { int ret; @@ -1770,6 +1788,10 @@ int f2fs_register_sysfs(struct f2fs_sb_info *sbi) discard_plist_seq_show, sb); proc_create_single_data("disk_map", 0444, sbi->s_proc, disk_map_seq_show, sb); +#ifdef CONFIG_F2FS_FAULT_INJECTION + proc_create_single_data("inject_stats", 0444, sbi->s_proc, + inject_stats_seq_show, sb); +#endif return 0; put_feature_list_kobj: kobject_put(&sbi->s_feature_list_kobj); From patchwork Thu Mar 20 02:22:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 14023355 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4CDD3C35FFC for ; Thu, 20 Mar 2025 02:39:10 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1tv5oM-00085F-EU; Thu, 20 Mar 2025 02:39:09 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tv5oK-000857-NV for linux-f2fs-devel@lists.sourceforge.net; Thu, 20 Mar 2025 02:39:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Aab7cQaaqPedLyeOwaeMNPGRH4++V2h8zn8+pMkTxmI=; b=MyLKZCdxO4Y3INgVynfZfNpKFP MxhAMCEoPa3OU5cv+C4khnUsz638htiq60r8ob0Ji1nq1m1bFT9mKza7nSquCWRWxdEgI+dQJzJ/7 SI7bTsXr5rsqN0WXwERy780W/eGgB5LGbM897C8yuPoSvgupzZ7TrppqRWP9Vd0heCyw=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Aab7cQaaqPedLyeOwaeMNPGRH4++V2h8zn8+pMkTxmI=; b=hNXkgk+BT+aOHhBYlrorHTt+4B M3nlbx6dAdxv6CwJO/T1o0lgnESyHYBzSQLRPDxXcmtUG8R9KlrqWOJm8di6kxsJFXZs9R37WCQ1B G59P0RYHczDFv4e0jszCfC3p0WqMy2UecH2H192W1VAWjKpgkSUKV/aspoqUZFcCF9ww=; Received: from sea.source.kernel.org ([172.234.252.31]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1tv5oE-0000XL-8z for linux-f2fs-devel@lists.sourceforge.net; Thu, 20 Mar 2025 02:39:08 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 6C0F843751 for ; Thu, 20 Mar 2025 02:22:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A00BDC4CEE8; Thu, 20 Mar 2025 02:22:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742437366; bh=7+Yts5LeHOxEOmhtkUAzJyFa7c2XWV7zaUXjWc0iIys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=keVJ3O1xNqwhqCBcZqW6EL+MgA/8ihCfTSSHVEXzvWr4LqmEC2FukSJtwyAshe4Sp CSAQRRPpSn3kQXiw68iAjeGkaArinWIXG/r8dJs4cYoJ2AYiJkzjWknynLmcz3RiEL 4Mv2LAjtbM6jS6mkaND29O6a0gB+O09od9YVd8yvrl7AfaiYh1CJnfIOT0Ct0vYYFa rnaDimRlj4aZNPNDPkg9KYomRiz60G/3K5gqTZFGPSYlWwdj3eQft84NQ1ST6lOZ5z Y66tJArcOhBH7ATz0hq4UDq1BO8MaBcqrW8LdgeHU9r83uKWzHJW26PGf4yIBPku/Z HrbSy4+6dfiXg== To: jaegeuk@kernel.org Date: Thu, 20 Mar 2025 10:22:30 +0800 Message-ID: <20250320022230.1938110-2-chao@kernel.org> X-Mailer: git-send-email 2.49.0.395.g12beb8f557-goog In-Reply-To: <20250320022230.1938110-1-chao@kernel.org> References: <20250320022230.1938110-1-chao@kernel.org> MIME-Version: 1.0 X-Headers-End: 1tv5oE-0000XL-8z Subject: [f2fs-dev] [PATCH v2 2/2] f2fs: fix to update injection attrs according to fault_option X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Chao Yu via Linux-f2fs-devel From: Chao Yu Reply-To: Chao Yu Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net When we update inject type via sysfs, it shows wrong rate value as below, there is a same problem when we update inject rate, fix it. Before: F2FS-fs (vdd): build fault injection attr: rate: 0, type: 0xffff F2FS-fs (vdd): build fault injection attr: rate: 1, type: 0x0 After: F2FS-fs (vdd): build fault injection type: 0x1 F2FS-fs (vdd): build fault injection rate: 1 Meanwhile, let's avoid turning on all fault types when we enable fault injection via fault_injection mount option, it will lead to shutdown filesystem or fail the mount() easily. mount -o fault_injection=4 /dev/vdd /mnt/f2fs F2FS-fs (vdd): build fault injection attr: rate: 4, type: 0x7fffff F2FS-fs (vdd): inject kmalloc in f2fs_kmalloc of f2fs_fill_super+0xbdf/0x27c0 Signed-off-by: Chao Yu --- v2 - no changes fs/f2fs/checkpoint.c | 2 +- fs/f2fs/f2fs.h | 14 ++++++++++---- fs/f2fs/super.c | 26 +++++++++++++------------- fs/f2fs/sysfs.c | 4 ++-- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index cf77987d0698..85b7141f0d89 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -29,7 +29,7 @@ struct kmem_cache *f2fs_inode_entry_slab; void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io, unsigned char reason) { - f2fs_build_fault_attr(sbi, 0, 0); + f2fs_build_fault_attr(sbi, 0, 0, FAULT_ALL); if (!end_io) f2fs_flush_merged_writes(sbi); f2fs_handle_critical_error(sbi, reason); diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 986ee5b9326d..ca884e39a5ff 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -66,9 +66,14 @@ enum { FAULT_MAX, }; -#ifdef CONFIG_F2FS_FAULT_INJECTION -#define F2FS_ALL_FAULT_TYPE (GENMASK(FAULT_MAX - 1, 0)) +/* indicate which option to update */ +enum fault_option { + FAULT_RATE = 1, /* only update fault rate */ + FAULT_TYPE = 2, /* only update fault type */ + FAULT_ALL = 4, /* reset all fault injection options/stats */ +}; +#ifdef CONFIG_F2FS_FAULT_INJECTION struct f2fs_fault_info { atomic_t inject_ops; int inject_rate; @@ -4765,10 +4770,11 @@ static inline bool f2fs_need_verity(const struct inode *inode, pgoff_t idx) #ifdef CONFIG_F2FS_FAULT_INJECTION extern int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned long rate, - unsigned long type); + unsigned long type, enum fault_option fo); #else static inline int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, - unsigned long rate, unsigned long type) + unsigned long rate, unsigned long type, + enum fault_option fo) { return 0; } diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index dfe0604ab558..011925ee54f8 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -68,29 +68,30 @@ const char *f2fs_fault_name[FAULT_MAX] = { }; int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned long rate, - unsigned long type) + unsigned long type, enum fault_option fo) { struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; - if (rate) { + if (fo & FAULT_ALL) { + memset(ffi, 0, sizeof(struct f2fs_fault_info)); + return 0; + } + + if (fo & FAULT_RATE) { if (rate > INT_MAX) return -EINVAL; atomic_set(&ffi->inject_ops, 0); ffi->inject_rate = (int)rate; + f2fs_info(sbi, "build fault injection rate: %lu", rate); } - if (type) { + if (fo & FAULT_TYPE) { if (type >= BIT(FAULT_MAX)) return -EINVAL; ffi->inject_type = (unsigned int)type; + f2fs_info(sbi, "build fault injection type: 0x%lx", type); } - if (!rate && !type) - memset(ffi, 0, sizeof(struct f2fs_fault_info)); - else - f2fs_info(sbi, - "build fault injection attr: rate: %lu, type: 0x%lx", - rate, type); return 0; } #endif @@ -897,8 +898,7 @@ static int parse_options(struct f2fs_sb_info *sbi, char *options, bool is_remoun case Opt_fault_injection: if (args->from && match_int(args, &arg)) return -EINVAL; - if (f2fs_build_fault_attr(sbi, arg, - F2FS_ALL_FAULT_TYPE)) + if (f2fs_build_fault_attr(sbi, arg, 0, FAULT_RATE)) return -EINVAL; set_opt(sbi, FAULT_INJECTION); break; @@ -906,7 +906,7 @@ static int parse_options(struct f2fs_sb_info *sbi, char *options, bool is_remoun case Opt_fault_type: if (args->from && match_int(args, &arg)) return -EINVAL; - if (f2fs_build_fault_attr(sbi, 0, arg)) + if (f2fs_build_fault_attr(sbi, 0, arg, FAULT_TYPE)) return -EINVAL; set_opt(sbi, FAULT_INJECTION); break; @@ -2209,7 +2209,7 @@ static void default_options(struct f2fs_sb_info *sbi, bool remount) set_opt(sbi, POSIX_ACL); #endif - f2fs_build_fault_attr(sbi, 0, 0); + f2fs_build_fault_attr(sbi, 0, 0, FAULT_ALL); } #ifdef CONFIG_QUOTA diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index 46fa94db08a8..3a3485622691 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -494,12 +494,12 @@ static ssize_t __sbi_store(struct f2fs_attr *a, return ret; #ifdef CONFIG_F2FS_FAULT_INJECTION if (a->struct_type == FAULT_INFO_TYPE) { - if (f2fs_build_fault_attr(sbi, 0, t)) + if (f2fs_build_fault_attr(sbi, 0, t, FAULT_TYPE)) return -EINVAL; return count; } if (a->struct_type == FAULT_INFO_RATE) { - if (f2fs_build_fault_attr(sbi, t, 0)) + if (f2fs_build_fault_attr(sbi, t, 0, FAULT_RATE)) return -EINVAL; return count; }