All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: Zhiguo Niu <niuzhiguo84@gmail.com>
Cc: chao@kernel.org, jaegeuk@kernel.org,
	linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH 1/2] f2fs: add a proc entry show inject stats
Date: Thu, 20 Mar 2025 10:00:41 +0800	[thread overview]
Message-ID: <df129d6e-d598-4bc3-b147-c305f949e5eb@kernel.org> (raw)
In-Reply-To: <CAHJ8P3LPtYsOH9yQzk4ozXT_=ufzSBe+FtzymH4TaNdavcF6jw@mail.gmail.com>

On 3/20/25 09:16, Zhiguo Niu wrote:
> Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
> 于2025年3月19日周三 23:38写道:
>>
>> This patch adds a proc entry named inject_stats to show total injected
>> count for each fault type.
>>
>> cat /proc/fs/f2fs/<dev>/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 <chao@kernel.org>
>> ---
>>  fs/f2fs/f2fs.h  |  3 +++
>>  fs/f2fs/super.c |  1 +
>>  fs/f2fs/sysfs.c | 18 ++++++++++++++++++
>>  3 files changed, 22 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..e87e89d2c023 100644
>> --- a/fs/f2fs/sysfs.c
>> +++ b/fs/f2fs/sysfs.c
>> @@ -1679,6 +1679,22 @@ static int __maybe_unused disk_map_seq_show(struct seq_file *seq,
>>         return 0;
>>  }
>>
>> +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;
>> +}
>> +
> Hi Chao,
> Here should we need to use #ifdef CONFIG_F2FS_FAULT_INJECTION to avoid
> build error when
> CONFIG_F2FS_FAULT_INJECTION is not enabled?

Zhiguo,

Yeah, you're right, let me fix this. Thank you!

Thanks,

> thanks!
>>  int __init f2fs_init_sysfs(void)
>>  {
>>         int ret;
>> @@ -1770,6 +1786,8 @@ 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);
>> +       proc_create_single_data("inject_stats", 0444, sbi->s_proc,
>> +                               inject_stats_seq_show, sb);
>>         return 0;
>>  put_feature_list_kobj:
>>         kobject_put(&sbi->s_feature_list_kobj);
>> --
>> 2.48.1
>>
>>
>>
>> _______________________________________________
>> Linux-f2fs-devel mailing list
>> Linux-f2fs-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


      reply	other threads:[~2025-03-20  2:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-19 12:00 [f2fs-dev] [PATCH 1/2] f2fs: add a proc entry show inject stats Chao Yu via Linux-f2fs-devel
2025-03-19 12:00 ` Chao Yu
2025-03-19 12:00 ` [PATCH 2/2] f2fs: fix to update injection attrs according to fault_option Chao Yu
2025-03-20  1:16 ` [f2fs-dev] [PATCH 1/2] f2fs: add a proc entry show inject stats Zhiguo Niu
2025-03-20  2:00   ` Chao Yu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=df129d6e-d598-4bc3-b147-c305f949e5eb@kernel.org \
    --to=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=niuzhiguo84@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.