f2fs: introduce FAULT_NO_SEGMENT
authorChao Yu <chao@kernel.org>
Thu, 22 Feb 2024 12:18:51 +0000 (20:18 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Thu, 29 Feb 2024 16:34:34 +0000 (08:34 -0800)
Use it to simulate no free segment case during block allocation.

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 22d070c0de406d8b34673c32ff57c24f06cc083e..1a4d83953379ec902c828af8f359003ff08955f0 100644 (file)
@@ -724,6 +724,7 @@ Description:        Support configuring fault injection type, should be
                FAULT_LOCK_OP                    0x000020000
                FAULT_BLKADDR_VALIDITY           0x000040000
                FAULT_BLKADDR_CONSISTENCE        0x000080000
+               FAULT_NO_SEGMENT                 0x000100000
                ===========================      ===========
 
 What:          /sys/fs/f2fs/<disk>/discard_io_aware_gran
index 8930d9ea8c4e2a8160e1f7cb1acd9161ca634af1..efc3493fd6f84b92b986da63c44e8629bd042f02 100644 (file)
@@ -205,6 +205,7 @@ fault_type=%d                Support configuring fault injection type, should be
                         FAULT_LOCK_OP                    0x000020000
                         FAULT_BLKADDR_VALIDITY           0x000040000
                         FAULT_BLKADDR_CONSISTENCE        0x000080000
+                        FAULT_NO_SEGMENT                 0x000100000
                         ===========================      ===========
 mode=%s                         Control block allocation mode which supports "adaptive"
                         and "lfs". In "lfs" mode, there should be no random
index 4ce48dbae55b8334f0756add1a2e55e24a8af91c..f1ec1a53afece502fa71c198a798aad2e0e4e935 100644 (file)
@@ -62,6 +62,7 @@ enum {
        FAULT_LOCK_OP,
        FAULT_BLKADDR_VALIDITY,
        FAULT_BLKADDR_CONSISTENCE,
+       FAULT_NO_SEGMENT,
        FAULT_MAX,
 };
 
index a5339dd7a9322fbe48a1fbdea3ea75404dc3f4e9..dab9544f871aa1d0050576043a07cdadfa78dd21 100644 (file)
@@ -2656,6 +2656,11 @@ static int get_new_segment(struct f2fs_sb_info *sbi,
 
        spin_lock(&free_i->segmap_lock);
 
+       if (time_to_inject(sbi, FAULT_NO_SEGMENT)) {
+               ret = -ENOSPC;
+               goto out_unlock;
+       }
+
        if (!new_sec && ((*newseg + 1) % SEGS_PER_SEC(sbi))) {
                segno = find_next_zero_bit(free_i->free_segmap,
                        GET_SEG_FROM_SEC(sbi, hint + 1), *newseg + 1);
index 329f317e6f095f5f52fe1d421de9d18c6e25677d..6190aace3d8c5c3457b396bd8894e0c284c5328b 100644 (file)
@@ -63,6 +63,7 @@ const char *f2fs_fault_name[FAULT_MAX] = {
        [FAULT_LOCK_OP]                 = "lock_op",
        [FAULT_BLKADDR_VALIDITY]        = "invalid blkaddr",
        [FAULT_BLKADDR_CONSISTENCE]     = "inconsistent blkaddr",
+       [FAULT_NO_SEGMENT]              = "no free segment",
 };
 
 void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,