f2fs: merge f2fs_show_injection_info() into time_to_inject()
authorYangtao Li <frank.li@vivo.com>
Tue, 20 Dec 2022 18:39:04 +0000 (02:39 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 11 Jan 2023 19:15:19 +0000 (11:15 -0800)
There is no need to additionally use f2fs_show_injection_info()
to output information. Concatenate time_to_inject() and
__time_to_inject() via a macro. In the new __time_to_inject()
function, pass in the caller function name and parent function.

In this way, we no longer need the f2fs_show_injection_info() function,
and let's remove it.

Suggested-by: Chao Yu <chao@kernel.org>
Signed-off-by: Yangtao Li <frank.li@vivo.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/checkpoint.c
fs/f2fs/data.c
fs/f2fs/dir.c
fs/f2fs/f2fs.h
fs/f2fs/file.c
fs/f2fs/gc.c
fs/f2fs/inode.c
fs/f2fs/node.c
fs/f2fs/segment.c
fs/f2fs/super.c

index 56f7d0d6a8b2f0b1c588db97fe09e1bb53a9d89b..d68b3c991888df14c0e87de5863aafbb2d3b24f7 100644 (file)
@@ -171,10 +171,8 @@ 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);
+       if (time_to_inject(sbi, FAULT_BLKADDR))
                return false;
-       }
 
        switch (type) {
        case META_NAT:
@@ -622,7 +620,6 @@ int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi)
 
        if (time_to_inject(sbi, FAULT_ORPHAN)) {
                spin_unlock(&im->ino_lock);
-               f2fs_show_injection_info(sbi, FAULT_ORPHAN);
                return -ENOSPC;
        }
 
index af906ed6d53d36db7edca84c06fc5abb0dafc9e4..c940da1c540f57d2c9f2eb95f833617626fd401c 100644 (file)
@@ -295,10 +295,8 @@ static void f2fs_read_end_io(struct bio *bio)
        iostat_update_and_unbind_ctx(bio, 0);
        ctx = bio->bi_private;
 
-       if (time_to_inject(sbi, FAULT_READ_IO)) {
-               f2fs_show_injection_info(sbi, FAULT_READ_IO);
+       if (time_to_inject(sbi, FAULT_READ_IO))
                bio->bi_status = BLK_STS_IOERR;
-       }
 
        if (bio->bi_status) {
                f2fs_finish_read_bio(bio, intask);
@@ -335,10 +333,8 @@ static void f2fs_write_end_io(struct bio *bio)
        iostat_update_and_unbind_ctx(bio, 1);
        sbi = bio->bi_private;
 
-       if (time_to_inject(sbi, FAULT_WRITE_IO)) {
-               f2fs_show_injection_info(sbi, FAULT_WRITE_IO);
+       if (time_to_inject(sbi, FAULT_WRITE_IO))
                bio->bi_status = BLK_STS_IOERR;
-       }
 
        bio_for_each_segment_all(bvec, bio, iter_all) {
                struct page *page = bvec->bv_page;
index 8e025157f35c9550885b5d9c7eb8506871f560bb..9ccdbe120425e8c5b212c66cba920acb1f737739 100644 (file)
@@ -732,10 +732,8 @@ int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname,
        }
 
 start:
-       if (time_to_inject(F2FS_I_SB(dir), FAULT_DIR_DEPTH)) {
-               f2fs_show_injection_info(F2FS_I_SB(dir), FAULT_DIR_DEPTH);
+       if (time_to_inject(F2FS_I_SB(dir), FAULT_DIR_DEPTH))
                return -ENOSPC;
-       }
 
        if (unlikely(current_depth == MAX_DIR_HASH_DEPTH))
                return -ENOSPC;
index d1fcaa973a53e287934a7fb43005709630fddf0f..53d7ca96df6376b42f16a4cd4fbd63d9ec9165cb 100644 (file)
@@ -1867,12 +1867,10 @@ struct f2fs_sb_info {
 };
 
 #ifdef CONFIG_F2FS_FAULT_INJECTION
-#define f2fs_show_injection_info(sbi, type)                                    \
-       printk_ratelimited("%sF2FS-fs (%s) : inject %s in %s of %pS\n", \
-               KERN_INFO, sbi->sb->s_id,                               \
-               f2fs_fault_name[type],                                  \
-               __func__, __builtin_return_address(0))
-static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
+#define time_to_inject(sbi, type) __time_to_inject(sbi, type, __func__,        \
+                                                                       __builtin_return_address(0))
+static inline bool __time_to_inject(struct f2fs_sb_info *sbi, int type,
+                               const char *func, const char *parent_func)
 {
        struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info;
 
@@ -1885,12 +1883,14 @@ static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
        atomic_inc(&ffi->inject_ops);
        if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) {
                atomic_set(&ffi->inject_ops, 0);
+               printk_ratelimited("%sF2FS-fs (%s) : inject %s in %s of %pS\n",
+                       KERN_INFO, sbi->sb->s_id, f2fs_fault_name[type],
+                       func, parent_func);
                return true;
        }
        return false;
 }
 #else
-#define f2fs_show_injection_info(sbi, type) do { } while (0)
 static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
 {
        return false;
@@ -2223,10 +2223,8 @@ static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
 
 static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi)
 {
-       if (time_to_inject(sbi, FAULT_LOCK_OP)) {
-               f2fs_show_injection_info(sbi, FAULT_LOCK_OP);
+       if (time_to_inject(sbi, FAULT_LOCK_OP))
                return 0;
-       }
        return f2fs_down_read_trylock(&sbi->cp_rwsem);
 }
 
@@ -2314,7 +2312,6 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
                return ret;
 
        if (time_to_inject(sbi, FAULT_BLOCK)) {
-               f2fs_show_injection_info(sbi, FAULT_BLOCK);
                release = *count;
                goto release_quota;
        }
@@ -2594,10 +2591,8 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,
                        return err;
        }
 
-       if (time_to_inject(sbi, FAULT_BLOCK)) {
-               f2fs_show_injection_info(sbi, FAULT_BLOCK);
+       if (time_to_inject(sbi, FAULT_BLOCK))
                goto enospc;
-       }
 
        spin_lock(&sbi->stat_lock);
 
@@ -2721,11 +2716,8 @@ static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
                if (page)
                        return page;
 
-               if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) {
-                       f2fs_show_injection_info(F2FS_M_SB(mapping),
-                                                       FAULT_PAGE_ALLOC);
+               if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC))
                        return NULL;
-               }
        }
 
        if (!for_write)
@@ -2742,10 +2734,8 @@ static inline struct page *f2fs_pagecache_get_page(
                                struct address_space *mapping, pgoff_t index,
                                int fgp_flags, gfp_t gfp_mask)
 {
-       if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) {
-               f2fs_show_injection_info(F2FS_M_SB(mapping), FAULT_PAGE_GET);
+       if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET))
                return NULL;
-       }
 
        return pagecache_get_page(mapping, index, fgp_flags, gfp_mask);
 }
@@ -2795,10 +2785,8 @@ static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
        if (nofail)
                return f2fs_kmem_cache_alloc_nofail(cachep, flags);
 
-       if (time_to_inject(sbi, FAULT_SLAB_ALLOC)) {
-               f2fs_show_injection_info(sbi, FAULT_SLAB_ALLOC);
+       if (time_to_inject(sbi, FAULT_SLAB_ALLOC))
                return NULL;
-       }
 
        return kmem_cache_alloc(cachep, flags);
 }
@@ -3372,10 +3360,8 @@ static inline bool is_dot_dotdot(const u8 *name, size_t len)
 static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi,
                                        size_t size, gfp_t flags)
 {
-       if (time_to_inject(sbi, FAULT_KMALLOC)) {
-               f2fs_show_injection_info(sbi, FAULT_KMALLOC);
+       if (time_to_inject(sbi, FAULT_KMALLOC))
                return NULL;
-       }
 
        return kmalloc(size, flags);
 }
@@ -3389,10 +3375,8 @@ static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi,
 static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi,
                                        size_t size, gfp_t flags)
 {
-       if (time_to_inject(sbi, FAULT_KVMALLOC)) {
-               f2fs_show_injection_info(sbi, FAULT_KVMALLOC);
+       if (time_to_inject(sbi, FAULT_KVMALLOC))
                return NULL;
-       }
 
        return kvmalloc(size, flags);
 }
index 58b4200f7fdf054569f5bc0a28da46eb88da8158..f5c1b78149540c5cfa295238e0d32a6e847027d0 100644 (file)
@@ -782,10 +782,8 @@ int f2fs_truncate(struct inode *inode)
 
        trace_f2fs_truncate(inode);
 
-       if (time_to_inject(F2FS_I_SB(inode), FAULT_TRUNCATE)) {
-               f2fs_show_injection_info(F2FS_I_SB(inode), FAULT_TRUNCATE);
+       if (time_to_inject(F2FS_I_SB(inode), FAULT_TRUNCATE))
                return -EIO;
-       }
 
        err = f2fs_dquot_initialize(inode);
        if (err)
index 7444c392eab161159ae9b97dff2bf1ec30e93c70..e59c006c10f77f9825024ab8500ead889deadb9b 100644 (file)
@@ -72,11 +72,9 @@ static int gc_thread_func(void *data)
                        continue;
                }
 
-               if (time_to_inject(sbi, FAULT_CHECKPOINT)) {
-                       f2fs_show_injection_info(sbi, FAULT_CHECKPOINT);
+               if (time_to_inject(sbi, FAULT_CHECKPOINT))
                        f2fs_stop_checkpoint(sbi, false,
                                        STOP_CP_REASON_FAULT_INJECT);
-               }
 
                if (!sb_start_write_trylock(sbi->sb)) {
                        stat_other_skip_bggc_count(sbi);
index ff6cf66ed46b22778bd03d8f370bbc5782cf99b4..01b9e6f85f6bed9d16a30c565611d660668020f5 100644 (file)
@@ -809,10 +809,8 @@ retry:
        if (F2FS_HAS_BLOCKS(inode))
                err = f2fs_truncate(inode);
 
-       if (time_to_inject(sbi, FAULT_EVICT_INODE)) {
-               f2fs_show_injection_info(sbi, FAULT_EVICT_INODE);
+       if (time_to_inject(sbi, FAULT_EVICT_INODE))
                err = -EIO;
-       }
 
        if (!err) {
                f2fs_lock_op(sbi);
index 558b318f73167bc131c5a2deb50829097ea4e09b..fbd1d25fecc22e1935ec3e9884fc8fb0bf7b1735 100644 (file)
@@ -2541,10 +2541,8 @@ bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid)
        struct f2fs_nm_info *nm_i = NM_I(sbi);
        struct free_nid *i = NULL;
 retry:
-       if (time_to_inject(sbi, FAULT_ALLOC_NID)) {
-               f2fs_show_injection_info(sbi, FAULT_ALLOC_NID);
+       if (time_to_inject(sbi, FAULT_ALLOC_NID))
                return false;
-       }
 
        spin_lock(&nm_i->nid_list_lock);
 
index e2f95f46d2989d5bc9b2c4fa4e87d04a701a9361..ba8331434703cb7db58ff3d8b4e9ad1d23e88b67 100644 (file)
@@ -384,10 +384,8 @@ int f2fs_commit_atomic_write(struct inode *inode)
  */
 void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need)
 {
-       if (time_to_inject(sbi, FAULT_CHECKPOINT)) {
-               f2fs_show_injection_info(sbi, FAULT_CHECKPOINT);
+       if (time_to_inject(sbi, FAULT_CHECKPOINT))
                f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_FAULT_INJECT);
-       }
 
        /* balance_fs_bg is able to be pending */
        if (need && excess_cached_nats(sbi))
@@ -1140,7 +1138,6 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
                dc->len += len;
 
                if (time_to_inject(sbi, FAULT_DISCARD)) {
-                       f2fs_show_injection_info(sbi, FAULT_DISCARD);
                        err = -EIO;
                } else {
                        err = __blkdev_issue_discard(bdev,
index 1d057a4c664249e353eed97c2b6da5440d009fcd..5fc83771042d3840c7ac4d4a0150d9292436df78 100644 (file)
@@ -1371,10 +1371,8 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)
 {
        struct f2fs_inode_info *fi;
 
-       if (time_to_inject(F2FS_SB(sb), FAULT_SLAB_ALLOC)) {
-               f2fs_show_injection_info(F2FS_SB(sb), FAULT_SLAB_ALLOC);
+       if (time_to_inject(F2FS_SB(sb), FAULT_SLAB_ALLOC))
                return NULL;
-       }
 
        fi = alloc_inode_sb(sb, f2fs_inode_cachep, GFP_F2FS_ZERO);
        if (!fi)
@@ -2594,10 +2592,8 @@ retry:
 
 int f2fs_dquot_initialize(struct inode *inode)
 {
-       if (time_to_inject(F2FS_I_SB(inode), FAULT_DQUOT_INIT)) {
-               f2fs_show_injection_info(F2FS_I_SB(inode), FAULT_DQUOT_INIT);
+       if (time_to_inject(F2FS_I_SB(inode), FAULT_DQUOT_INIT))
                return -ESRCH;
-       }
 
        return dquot_initialize(inode);
 }