]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
f2fs: Add trace_f2fs_fault_report
authorliujinbao1 <liujinbao1@xiaomi.com>
Wed, 6 May 2026 09:57:31 +0000 (17:57 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Mon, 22 Jun 2026 19:52:34 +0000 (19:52 +0000)
Add trace_f2fs_fault_report to trigger reporting upon f2fs_bug_on,
need_fsck, stop_checkpoint, and handle_eio. Since f2fs_bug_on and
need_fsck can be triggered in hundreds of scenarios, define set_sbi_flag
as a macro to help capture the effective fault function and line number.

Signed-off-by: shengyong1 <shengyong1@xiaomi.com>
Signed-off-by: liujinbao1 <liujinbao1@xiaomi.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/f2fs.h
fs/f2fs/super.c
include/trace/events/f2fs.h

index 6d2048cffa6680d903c330e8e892d9e9eb740454..b83ff4bd96ec62805834df17ff9e96b81cd6fbe6 100644 (file)
@@ -96,6 +96,15 @@ extern const char *f2fs_fault_name[FAULT_MAX];
 #define DEFAULT_FAILURE_RETRY_COUNT            1
 #endif
 
+enum {
+       REPORT_FAULT_NEED_FSCK,
+       REPORT_FAULT_STOP_CP,
+       REPORT_FAULT_MAX,
+};
+
+void f2fs_fault_report(struct super_block *sb, unsigned int err_code,
+                       const char *func, unsigned int data);
+
 /*
  * For mount options
  */
@@ -2279,11 +2288,18 @@ static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
        return test_bit(type, &sbi->s_flag);
 }
 
-static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
+static inline void __set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
 {
        set_bit(type, &sbi->s_flag);
 }
 
+#define set_sbi_flag(sbi, type)                                \
+do {                                                   \
+       __set_sbi_flag(sbi, type);                      \
+       if ((type) == SBI_NEED_FSCK)                    \
+               f2fs_fault_report(sbi->sb, REPORT_FAULT_NEED_FSCK, __func__, __LINE__); \
+} while (0)
+
 static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
 {
        clear_bit(type, &sbi->s_flag);
index aab4345f3ee7c148c99de657a39d2f965f2cd064..f4ab39b24a304f04c7c89cee611f7b7db607ad09 100644 (file)
@@ -4750,9 +4750,18 @@ static void f2fs_handle_critical_error(struct f2fs_sb_info *sbi,
         */
 }
 
+void f2fs_fault_report(struct super_block *sb, unsigned int err_code,
+                       const char *func, unsigned int data)
+{
+       trace_f2fs_fault_report(sb, err_code, func, data);
+}
+
 void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io,
                                                unsigned char reason)
 {
+       if (reason != STOP_CP_REASON_SHUTDOWN)
+               f2fs_fault_report(sbi->sb, REPORT_FAULT_STOP_CP, __func__, reason);
+
        f2fs_build_fault_attr(sbi, 0, 0, FAULT_ALL);
        if (!end_io)
                f2fs_flush_merged_writes(sbi);
index b5188d2671d7374c35f451fac87044c08c88a48d..270c1a2c24c44a78d57f463252f4e0db81be8c34 100644 (file)
@@ -2595,6 +2595,34 @@ DEFINE_EVENT(f2fs_priority_update, f2fs_priority_restore,
        TP_ARGS(sbi, lock_name, is_write, p, orig_prio, new_prio)
 );
 
+TRACE_EVENT(f2fs_fault_report,
+
+       TP_PROTO(struct super_block *sb, unsigned int err_code,
+               const char *func, unsigned int data),
+
+       TP_ARGS(sb, err_code, func, data),
+
+       TP_STRUCT__entry(
+               __field(dev_t, dev)
+               __field(unsigned int, err_code)
+               __string(func, func)
+               __field(unsigned int, data)
+       ),
+
+       TP_fast_assign(
+               __entry->dev            = sb->s_dev;
+               __entry->err_code       = err_code;
+               __assign_str(func);
+               __entry->data           = data;
+       ),
+
+       TP_printk("dev = (%d,%d), err_code = %u, func = %s, data = %u",
+               show_dev(__entry->dev),
+               __entry->err_code,
+               __get_str(func),
+               __entry->data)
+);
+
 #endif /* _TRACE_F2FS_H */
 
  /* This part must be outside protection */