f2fs: support FAULT_TIMEOUT
authorChao Yu <chao@kernel.org>
Fri, 25 Apr 2025 09:50:55 +0000 (17:50 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 6 May 2025 15:46:55 +0000 (15:46 +0000)
Support to inject a timeout fault into function, currently it only
support to inject timeout to commit_atomic_write flow to reproduce
inconsistent bug, like the bug fixed by commit f098aeba04c9 ("f2fs:
fix to avoid atomicity corruption of atomic file").

By default, the new type fault will inject 1000ms timeout, and the
timeout process can be interrupted by SIGKILL.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Documentation/ABI/testing/sysfs-fs-f2fs
Documentation/filesystems/f2fs.rst
fs/f2fs/f2fs.h
fs/f2fs/segment.c
fs/f2fs/super.c

index 8ff7e769a2f90bc6e590c6a93ecf8d8c3073c281..feafb36fd92151c8debce388419f949081e1cf79 100644 (file)
@@ -735,6 +735,7 @@ Description:        Support configuring fault injection type, should be
                FAULT_BLKADDR_CONSISTENCE        0x000080000
                FAULT_NO_SEGMENT                 0x000100000
                FAULT_INCONSISTENT_FOOTER        0x000200000
+               FAULT_TIMEOUT                    0x000400000 (1000ms)
                ===========================      ===========
 
 What:          /sys/fs/f2fs/<disk>/discard_io_aware_gran
index e15c4275862a721c44953b4908ef70e7239f4e46..157743ab107d5fb7cc2125f4bcfc54cc82983898 100644 (file)
@@ -207,6 +207,7 @@ fault_type=%d                Support configuring fault injection type, should be
                         FAULT_BLKADDR_CONSISTENCE        0x000080000
                         FAULT_NO_SEGMENT                 0x000100000
                         FAULT_INCONSISTENT_FOOTER        0x000200000
+                        FAULT_TIMEOUT                    0x000400000 (1000ms)
                         ===========================      ===========
 mode=%s                         Control block allocation mode which supports "adaptive"
                         and "lfs". In "lfs" mode, there should be no random
index b3982a8bfecd70e552eb5decfafa24517c3c922e..9432fd15766ad7ae4566d750f7f961ed4645b580 100644 (file)
@@ -63,6 +63,7 @@ enum {
        FAULT_BLKADDR_CONSISTENCE,
        FAULT_NO_SEGMENT,
        FAULT_INCONSISTENT_FOOTER,
+       FAULT_TIMEOUT,
        FAULT_MAX,
 };
 
@@ -613,6 +614,9 @@ enum {
 /* congestion wait timeout value, default: 20ms */
 #define        DEFAULT_IO_TIMEOUT      (msecs_to_jiffies(20))
 
+/* timeout value injected, default: 1000ms */
+#define DEFAULT_FAULT_TIMEOUT  (msecs_to_jiffies(1000))
+
 /* maximum retry quota flush count */
 #define DEFAULT_RETRY_QUOTA_FLUSH_COUNT                8
 
@@ -4815,6 +4819,19 @@ static inline void f2fs_io_schedule_timeout(long timeout)
        io_schedule_timeout(timeout);
 }
 
+static inline void f2fs_io_schedule_timeout_killable(long timeout)
+{
+       while (timeout) {
+               if (fatal_signal_pending(current))
+                       return;
+               set_current_state(TASK_UNINTERRUPTIBLE);
+               io_schedule_timeout(DEFAULT_IO_TIMEOUT);
+               if (timeout <= DEFAULT_IO_TIMEOUT)
+                       return;
+               timeout -= DEFAULT_IO_TIMEOUT;
+       }
+}
+
 static inline void f2fs_handle_page_eio(struct f2fs_sb_info *sbi,
                                struct folio *folio, enum page_type type)
 {
index ffb4619c1edfe39f4fd2828426769f473340f2c0..671bc5a8fd4a5b5aa2986b9e08f9a16c8aa5eda3 100644 (file)
@@ -371,6 +371,9 @@ next:
        }
 
 out:
+       if (time_to_inject(sbi, FAULT_TIMEOUT))
+               f2fs_io_schedule_timeout_killable(DEFAULT_FAULT_TIMEOUT);
+
        if (ret) {
                sbi->revoked_atomic_block += fi->atomic_write_cnt;
        } else {
index 8abfbee13204537c9689575bb64cf9181e9f0e91..e25d74774f24ef9df6d7c8417598062ee315357b 100644 (file)
@@ -65,6 +65,7 @@ const char *f2fs_fault_name[FAULT_MAX] = {
        [FAULT_BLKADDR_CONSISTENCE]     = "inconsistent blkaddr",
        [FAULT_NO_SEGMENT]              = "no free segment",
        [FAULT_INCONSISTENT_FOOTER]     = "inconsistent footer",
+       [FAULT_TIMEOUT]                 = "timeout",
 };
 
 int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned long rate,