On 4/14/2026 10:53 AM, liujinbao1 wrote:

在 2026/4/13 17:54, Chao Yu 写道:
On 4/2/2026 7:45 PM, liujinbao1 wrote:
From: liujinbao1 <[email protected]>

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: liujinbao1 <[email protected]>
---
  fs/f2fs/checkpoint.c        | 10 ++++++++++
  fs/f2fs/f2fs.h              | 20 +++++++++++++++++++-
  include/trace/events/f2fs.h | 22 ++++++++++++++++++++++
  3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 6dd39b7de11a..698540c0f619 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -24,6 +24,8 @@
  #include "iostat.h"
  #include <trace/events/f2fs.h>
  +EXPORT_TRACEPOINT_SYMBOL_GPL(f2fs_fault_report);

I don't think we need to export this in upstream.

ok
+
  static inline void get_lock_elapsed_time(struct f2fs_time_stat *ts)
  {
      ts->total_time = ktime_get();
@@ -232,9 +234,17 @@ static inline void f2fs_unlock_all(struct f2fs_sb_info 
*sbi)
  static struct kmem_cache *ino_entry_slab;
  struct kmem_cache *f2fs_inode_entry_slab;
  +void f2fs_fault_report(unsigned int err_code, const char *func, unsigned int 
data)
+{
+    trace_f2fs_fault_report(err_code, func, data);
+}

What do you think just calling trace_f2fs_fault_report() directly?

It doesn't quite work, because trace_f2fs_fault_report needs to be used in 
f2fs.h,

Alright,

Thanks,


and it's not possible to include <trace/events/f2fs.h> in f2fs.h.

+
  void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io,
                          unsigned char reason)
  {
+    if (reason != STOP_CP_REASON_SHUTDOWN)
+        f2fs_fault_report(REPORT_FAULT_STOP_CP, __func__, reason);
+
      f2fs_build_fault_attr(sbi, 0, 0, FAULT_ALL);
      if (!end_io)
          f2fs_flush_merged_writes(sbi);
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index bb34e864d0ef..ac2fa4b6bd37 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -97,6 +97,15 @@ extern const char *f2fs_fault_name[FAULT_MAX];
  #define DEFAULT_FAILURE_RETRY_COUNT        1
  #endif
  +enum {
+    REPORT_FAULT_NEED_FSCK,
+    REPORT_FAULT_PAGE_EIO,
+    REPORT_FAULT_STOP_CP,
+    REPORT_FAULT_MAX,
+};
+
+void f2fs_fault_report(unsigned int err_code, const char *func, unsigned int 
data);
+
  /*
   * For mount options
   */
@@ -2275,11 +2284,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(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);
@@ -5064,6 +5080,8 @@ static inline void f2fs_handle_page_eio(struct 
f2fs_sb_info *sbi,
      if (unlikely(f2fs_cp_error(sbi)))
          return;
  +    f2fs_fault_report(REPORT_FAULT_PAGE_EIO, __func__, type);

We have changed to call f2fs_stop_checkpoint() directly in 
f2fs_handle_page_eio(),
so it's redundant here?

Yes
+
      if (ofs == sbi->page_eio_ofs[type]) {
          if (sbi->page_eio_cnt[type]++ == MAX_RETRY_PAGE_EIO)
              set_ckpt_flags(sbi, CP_ERROR_FLAG);
diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h
index 9364e6775562..039c695c45a8 100644
--- a/include/trace/events/f2fs.h
+++ b/include/trace/events/f2fs.h
@@ -2582,6 +2582,28 @@ 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(unsigned int err_code, const char *func, unsigned int data),
+
+    TP_ARGS(err_code, func, data),
+
+    TP_STRUCT__entry(
+        __field(unsigned int, err_code)
+        __string(func, func)
+        __field(unsigned int, data)
+    ),
+
+    TP_fast_assign(
+        __entry->err_code = err_code;
+        __assign_str(func, func);
+        __entry->data = data;
+    ),
+
+    TP_printk("err_code=%u func=%s data=%u",

Do we need dev information?
Yes, we need.

Thanks,

+        __entry->err_code, __get_str(func), __entry->data)
+);
+
  #endif /* _TRACE_F2FS_H */
     /* This part must be outside protection */




_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to