f2fs: support fault injection for f2fs_is_valid_blkaddr()
authorChao Yu <chao@kernel.org>
Thu, 6 Oct 2022 15:09:28 +0000 (23:09 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 2 Nov 2022 00:56:01 +0000 (17:56 -0700)
This patch supports to inject fault into f2fs_is_valid_blkaddr() to
simulate accessing inconsistent data/meta block addressses from caller.

Usage:
a) echo 262144 > /sys/fs/f2fs/<dev>/inject_type or
b) mount -o fault_type=262144 <dev> <mountpoint>

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

index 17df9a02ccff14a17be195730ff5ce71ffeb79ae..b797e8ec96ede22f2e24ea654457a69045d29cc6 100644 (file)
@@ -199,6 +199,7 @@ fault_type=%d                Support configuring fault injection type, should be
                         FAULT_SLAB_ALLOC         0x000008000
                         FAULT_DQUOT_INIT         0x000010000
                         FAULT_LOCK_OP            0x000020000
+                        FAULT_BLKADDR            0x000040000
                         ===================      ===========
 mode=%s                         Control block allocation mode which supports "adaptive"
                         and "lfs". In "lfs" mode, there should be no random
index 0c82dae082aa9e4ee3e37b758cb046fc43766110..c00694a502227c61bac7b1e5fb60fb2c8851018d 100644 (file)
@@ -171,6 +171,11 @@ static bool __is_bitmap_valid(struct f2fs_sb_info *sbi, block_t blkaddr,
 bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
                                        block_t blkaddr, int type)
 {
+       if (time_to_inject(sbi, FAULT_BLKADDR)) {
+               f2fs_show_injection_info(sbi, FAULT_BLKADDR);
+               return false;
+       }
+
        switch (type) {
        case META_NAT:
                break;
index e6355a5683b75cc1dd1941bdec48566efa612f66..f57cb49dc3830cd1780ff53b41518e448dde5594 100644 (file)
@@ -60,6 +60,7 @@ enum {
        FAULT_SLAB_ALLOC,
        FAULT_DQUOT_INIT,
        FAULT_LOCK_OP,
+       FAULT_BLKADDR,
        FAULT_MAX,
 };
 
index 3834ead046200ac428b36135f5bcf1f17d735a78..df26fbe2bf58621b3d2daf44b5590eaf6fbcbad3 100644 (file)
@@ -61,6 +61,7 @@ const char *f2fs_fault_name[FAULT_MAX] = {
        [FAULT_SLAB_ALLOC]      = "slab alloc",
        [FAULT_DQUOT_INIT]      = "dquot initialize",
        [FAULT_LOCK_OP]         = "lock_op",
+       [FAULT_BLKADDR]         = "invalid blkaddr",
 };
 
 void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,