Skip to contentSkip to conversation

f2fs: Add trace_f2fs_fault_report

PATCH Superseded liujinbao1 2 participants 4 messages Apr 2 – Apr 14 1 message not in the archive

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

liujinbao1

author
#0 lore raw

PATCH 1/1 f2fs: Add trace_f2fs_fault_report

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.

---
 fs/f2fs/checkpoint.c        | 10 ++++++++++
 fs/f2fs/f2fs.h              | 20 +++++++++++++++++++-
 include/trace/events/f2fs.h | 22 ++++++++++++++++++++++
 3 files changed, 51 insertions(+), 1 deletion(-)
fs/f2fs/checkpoint.c +10 -0
index 6dd39b7de11a..698540c0f619 100644
@@ -24,6 +24,8 @@
 #include "iostat.h"
 #include <trace/events/f2fs.h>
 
+EXPORT_TRACEPOINT_SYMBOL_GPL(f2fs_fault_report);
+
 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);
+}
+
 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);
fs/f2fs/f2fs.h +19 -1
index bb34e864d0ef..ac2fa4b6bd37 100644
@@ -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);
+
 	if (ofs == sbi->page_eio_ofs[type]) {
 		if (sbi->page_eio_cnt[type]++ == MAX_RETRY_PAGE_EIO)
 			set_ckpt_flags(sbi, CP_ERROR_FLAG);
include/trace/events/f2fs.h +22 -0
index 9364e6775562..039c695c45a8 100644
@@ -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",
+		__entry->err_code, __get_str(func), __entry->data)
+);
+
 #endif /* _TRACE_F2FS_H */
 
  /* This part must be outside protection */
Signature · 8 lines
2.43.0



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

ping

Quoted 117 lines · 在 2026/4/2 19:45, liujinbao1 写道:

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.

---
  fs/f2fs/checkpoint.c        | 10 ++++++++++
  fs/f2fs/f2fs.h              | 20 +++++++++++++++++++-
  include/trace/events/f2fs.h | 22 ++++++++++++++++++++++
  3 files changed, 51 insertions(+), 1 deletion(-)
fs/f2fs/checkpoint.c +10 -0
index 6dd39b7de11a..698540c0f619 100644
@@ -24,6 +24,8 @@
  #include "iostat.h"
  #include <trace/events/f2fs.h>
 
+EXPORT_TRACEPOINT_SYMBOL_GPL(f2fs_fault_report);
+
  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);
+}
+
  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);
fs/f2fs/f2fs.h +19 -1
index bb34e864d0ef..ac2fa4b6bd37 100644
@@ -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);
+
  	if (ofs == sbi->page_eio_ofs[type]) {
  		if (sbi->page_eio_cnt[type]++ == MAX_RETRY_PAGE_EIO)
  			set_ckpt_flags(sbi, CP_ERROR_FLAG);
include/trace/events/f2fs.h +15 -0
index 9364e6775562..039c695c45a8 100644
@@ -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);

include/trace/events/f2fs.h DEFINE_EVENT(f2fs_priority_update, f2fs_priority_restore, · line 2609

Quoted 10 lines
include/trace/events/f2fs.h +7 -0
+		__entry->data = data;
+	),
+
+	TP_printk("err_code=%u func=%s data=%u",
+		__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

#2 lore raw
In reply to liujinbao1
Quoted 19 lines · 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.

---
  fs/f2fs/checkpoint.c        | 10 ++++++++++
  fs/f2fs/f2fs.h              | 20 +++++++++++++++++++-
  include/trace/events/f2fs.h | 22 ++++++++++++++++++++++
  3 files changed, 51 insertions(+), 1 deletion(-)
fs/f2fs/checkpoint.c +0 -0
index 6dd39b7de11a..698540c0f619 100644

fs/f2fs/checkpoint.c line 27

Quoted 4 lines
fs/f2fs/checkpoint.c +1 -0
@@ -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.

fs/f2fs/checkpoint.c static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) · line 240

Quoted 12 lines
fs/f2fs/checkpoint.c +5 -0
+
  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?

Quoted 51 lines
fs/f2fs/checkpoint.c +4 -0
+
  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);
fs/f2fs/f2fs.h +17 -1
index bb34e864d0ef..ac2fa4b6bd37 100644
@@ -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);

fs/f2fs/f2fs.h static inline void f2fs_handle_page_eio(struct f2fs_sb_info *sbi, · line 5083

Quoted 4 lines
fs/f2fs/f2fs.h +1 -0
@@ -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?

Quoted 21 lines
fs/f2fs/f2fs.h +1 -0
+
  	if (ofs == sbi->page_eio_ofs[type]) {
  		if (sbi->page_eio_cnt[type]++ == MAX_RETRY_PAGE_EIO)
  			set_ckpt_flags(sbi, CP_ERROR_FLAG);
include/trace/events/f2fs.h +9 -0
index 9364e6775562..039c695c45a8 100644
@@ -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)

include/trace/events/f2fs.h DEFINE_EVENT(f2fs_priority_update, f2fs_priority_restore, · line 2603

Quoted 10 lines
include/trace/events/f2fs.h +10 -0
+		__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?

Thanks,

include/trace/events/f2fs.h DEFINE_EVENT(f2fs_priority_update, f2fs_priority_restore, · line 2609

Quoted 6 lines
include/trace/events/f2fs.h +3 -0
+		__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

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 43 lines · On 4/14/2026 10:53 AM, liujinbao1 wrote:
Quoted 15 lines · Chao Yu
Quoted 14 lines · 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.

---
  fs/f2fs/checkpoint.c        | 10 ++++++++++ fs/f2fs/f2fs.h              | 20 +++++++++++++++++++- include/trace/events/f2fs.h | 22 ++++++++++++++++++++++

  3 files changed, 51 insertions(+), 1 deletion(-)
Quoted 11 lines

fs/f2fs/checkpoint.c line 26

Quoted 8 lines
fs/f2fs/checkpoint.c +0 -0
index 6dd39b7de11a..698540c0f619 100644
@@ -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

Quoted 5 lines
Quoted 5 lines
fs/f2fs/checkpoint.c +1 -0
+
   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)
Quoted 9 lines

fs/f2fs/checkpoint.c static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) · line 240

Quoted 6 lines
fs/f2fs/checkpoint.c +3 -0
   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?

Quoted 1 line

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

Alright,

Thanks,

Quoted 91 lines

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

Quoted 46 lines
Quoted 46 lines
fs/f2fs/checkpoint.c +4 -0
+
   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);
fs/f2fs/f2fs.h +15 -0
index bb34e864d0ef..ac2fa4b6bd37 100644
@@ -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)
   {
Quoted 9 lines

fs/f2fs/f2fs.h static inline void f2fs_handle_page_eio(struct f2fs_sb_info *sbi, · line 5082

Quoted 5 lines
fs/f2fs/f2fs.h +0 -0
       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

Quoted 24 lines
Quoted 24 lines
fs/f2fs/f2fs.h +1 -0
+
       if (ofs == sbi->page_eio_ofs[type]) {
           if (sbi->page_eio_cnt[type]++ == MAX_RETRY_PAGE_EIO)
               set_ckpt_flags(sbi, CP_ERROR_FLAG);
include/trace/events/f2fs.h +12 -0
index 9364e6775562..039c695c45a8 100644
@@ -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(
Quoted 8 lines

include/trace/events/f2fs.h DEFINE_EVENT(f2fs_priority_update, f2fs_priority_restore, · line 2603

Quoted 6 lines
include/trace/events/f2fs.h +6 -0
+        __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?

Quoted 10 lines

Yes, we need.

Quoted 9 lines

Thanks,

Quoted 5 lines
include/trace/events/f2fs.h +3 -0
+        __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