]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
f2fs: rework fault injection handling to avoid a warning
authorArnd Bergmann <arnd@arndb.de>
Mon, 13 Aug 2018 21:38:06 +0000 (23:38 +0200)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 14 Aug 2018 16:49:15 +0000 (09:49 -0700)
When CONFIG_F2FS_FAULT_INJECTION is disabled, we get a warning about an
unused label:

fs/f2fs/segment.c: In function '__submit_discard_cmd':
fs/f2fs/segment.c:1059:1: error: label 'submit' defined but not used [-Werror=unused-label]

This could be fixed by adding another #ifdef around it, but the more
reliable way of doing this seems to be to remove the other #ifdefs
where that is easily possible.

By defining time_to_inject() as a trivial stub, most of the checks for
CONFIG_F2FS_FAULT_INJECTION can go away. This also leads to nicer
formatting of the code.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
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/recovery.c
fs/f2fs/segment.c

index 3ab7a00c0641f766d85b87589f8b3e270497e5c0..e8b6b89bddb865e488c4213dcbf09fa79e4d83cb 100644 (file)
@@ -555,13 +555,12 @@ int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi)
 
        spin_lock(&im->ino_lock);
 
-#ifdef CONFIG_F2FS_FAULT_INJECTION
        if (time_to_inject(sbi, FAULT_ORPHAN)) {
                spin_unlock(&im->ino_lock);
                f2fs_show_injection_info(FAULT_ORPHAN);
                return -ENOSPC;
        }
-#endif
+
        if (unlikely(im->ino_num >= sbi->max_orphans))
                err = -ENOSPC;
        else
index 45f043ee48bdb73972783ee6e62e6fd55c6685dd..43d3723dc8863fed00c376ae2e78886a6776453a 100644 (file)
@@ -126,12 +126,10 @@ static bool f2fs_bio_post_read_required(struct bio *bio)
 
 static void f2fs_read_end_io(struct bio *bio)
 {
-#ifdef CONFIG_F2FS_FAULT_INJECTION
        if (time_to_inject(F2FS_P_SB(bio_first_page_all(bio)), FAULT_IO)) {
                f2fs_show_injection_info(FAULT_IO);
                bio->bi_status = BLK_STS_IOERR;
        }
-#endif
 
        if (f2fs_bio_post_read_required(bio)) {
                struct bio_post_read_ctx *ctx = bio->bi_private;
index 7f955c4e86a45e56a870c2f014ab9eee71fef84b..ecc3a4e2be96d8a25fd6814a9d09476b30095eaa 100644 (file)
@@ -517,12 +517,11 @@ int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name,
        }
 
 start:
-#ifdef CONFIG_F2FS_FAULT_INJECTION
        if (time_to_inject(F2FS_I_SB(dir), FAULT_DIR_DEPTH)) {
                f2fs_show_injection_info(FAULT_DIR_DEPTH);
                return -ENOSPC;
        }
-#endif
+
        if (unlikely(current_depth == MAX_DIR_HASH_DEPTH))
                return -ENOSPC;
 
index 375aa9f30cfa336f80d67b82ab61564228d73cac..9a6ba4a8d338526df522268e8866bd0c5973f9bc 100644 (file)
@@ -41,7 +41,6 @@
        } while (0)
 #endif
 
-#ifdef CONFIG_F2FS_FAULT_INJECTION
 enum {
        FAULT_KMALLOC,
        FAULT_KVMALLOC,
@@ -60,6 +59,7 @@ enum {
        FAULT_MAX,
 };
 
+#ifdef CONFIG_F2FS_FAULT_INJECTION
 #define F2FS_ALL_FAULT_TYPE            ((1 << FAULT_MAX) - 1)
 
 struct f2fs_fault_info {
@@ -1324,6 +1324,12 @@ static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
        }
        return false;
 }
+#else
+#define f2fs_show_injection_info(type) do { } while (0)
+static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
+{
+       return false;
+}
 #endif
 
 /* For write statistics. Suppose sector size is 512 bytes,
@@ -1676,13 +1682,12 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
        if (ret)
                return ret;
 
-#ifdef CONFIG_F2FS_FAULT_INJECTION
        if (time_to_inject(sbi, FAULT_BLOCK)) {
                f2fs_show_injection_info(FAULT_BLOCK);
                release = *count;
                goto enospc;
        }
-#endif
+
        /*
         * let's increase this in prior to actual block count change in order
         * for f2fs_sync_file to avoid data races when deciding checkpoint.
@@ -1891,12 +1896,10 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,
                        return ret;
        }
 
-#ifdef CONFIG_F2FS_FAULT_INJECTION
        if (time_to_inject(sbi, FAULT_BLOCK)) {
                f2fs_show_injection_info(FAULT_BLOCK);
                goto enospc;
        }
-#endif
 
        spin_lock(&sbi->stat_lock);
 
@@ -1981,22 +1984,23 @@ static inline s64 valid_inode_count(struct f2fs_sb_info *sbi)
 static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
                                                pgoff_t index, bool for_write)
 {
-#ifdef CONFIG_F2FS_FAULT_INJECTION
        struct page *page;
 
-       if (!for_write)
-               page = find_get_page_flags(mapping, index,
-                                               FGP_LOCK | FGP_ACCESSED);
-       else
-               page = find_lock_page(mapping, index);
-       if (page)
-               return page;
+       if (IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)) {
+               if (!for_write)
+                       page = find_get_page_flags(mapping, index,
+                                                       FGP_LOCK | FGP_ACCESSED);
+               else
+                       page = find_lock_page(mapping, index);
+               if (page)
+                       return page;
 
-       if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) {
-               f2fs_show_injection_info(FAULT_PAGE_ALLOC);
-               return NULL;
+               if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) {
+                       f2fs_show_injection_info(FAULT_PAGE_ALLOC);
+                       return NULL;
+               }
        }
-#endif
+
        if (!for_write)
                return grab_cache_page(mapping, index);
        return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS);
@@ -2006,12 +2010,11 @@ static inline struct page *f2fs_pagecache_get_page(
                                struct address_space *mapping, pgoff_t index,
                                int fgp_flags, gfp_t gfp_mask)
 {
-#ifdef CONFIG_F2FS_FAULT_INJECTION
        if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) {
                f2fs_show_injection_info(FAULT_PAGE_GET);
                return NULL;
        }
-#endif
+
        return pagecache_get_page(mapping, index, fgp_flags, gfp_mask);
 }
 
@@ -2076,12 +2079,11 @@ static inline struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi,
                        bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages);
                return bio;
        }
-#ifdef CONFIG_F2FS_FAULT_INJECTION
        if (time_to_inject(sbi, FAULT_ALLOC_BIO)) {
                f2fs_show_injection_info(FAULT_ALLOC_BIO);
                return NULL;
        }
-#endif
+
        return bio_alloc(GFP_KERNEL, npages);
 }
 
@@ -2616,12 +2618,11 @@ static inline bool f2fs_may_extent_tree(struct inode *inode)
 static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi,
                                        size_t size, gfp_t flags)
 {
-#ifdef CONFIG_F2FS_FAULT_INJECTION
        if (time_to_inject(sbi, FAULT_KMALLOC)) {
                f2fs_show_injection_info(FAULT_KMALLOC);
                return NULL;
        }
-#endif
+
        return kmalloc(size, flags);
 }
 
@@ -2634,12 +2635,11 @@ 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)
 {
-#ifdef CONFIG_F2FS_FAULT_INJECTION
        if (time_to_inject(sbi, FAULT_KVMALLOC)) {
                f2fs_show_injection_info(FAULT_KVMALLOC);
                return NULL;
        }
-#endif
+
        return kvmalloc(size, flags);
 }
 
index 8c4694b9af27ebc3ae500ab6437771393c31c75d..1f76cc3fc46b076dbb343c7f6828e603584f004e 100644 (file)
@@ -668,12 +668,11 @@ int f2fs_truncate(struct inode *inode)
 
        trace_f2fs_truncate(inode);
 
-#ifdef CONFIG_F2FS_FAULT_INJECTION
        if (time_to_inject(F2FS_I_SB(inode), FAULT_TRUNCATE)) {
                f2fs_show_injection_info(FAULT_TRUNCATE);
                return -EIO;
        }
-#endif
+
        /* we should check inline_data size */
        if (!f2fs_may_inline_data(inode)) {
                err = f2fs_convert_inline_inode(inode);
index e352fbd33848ef4c2ab5db017d0d9d657819e9ed..76a22b3773bc0d95e991f402196114d8178aedb1 100644 (file)
@@ -53,12 +53,10 @@ static int gc_thread_func(void *data)
                        continue;
                }
 
-#ifdef CONFIG_F2FS_FAULT_INJECTION
                if (time_to_inject(sbi, FAULT_CHECKPOINT)) {
                        f2fs_show_injection_info(FAULT_CHECKPOINT);
                        f2fs_stop_checkpoint(sbi, false);
                }
-#endif
 
                if (!sb_start_write_trylock(sbi->sb))
                        continue;
index fc2c98b9e255b43551b4af98032cb9db106c88fe..6908896a19502c6f00dd504d43e64f6def722a0f 100644 (file)
@@ -659,12 +659,11 @@ retry:
        if (F2FS_HAS_BLOCKS(inode))
                err = f2fs_truncate(inode);
 
-#ifdef CONFIG_F2FS_FAULT_INJECTION
        if (time_to_inject(sbi, FAULT_EVICT_INODE)) {
                f2fs_show_injection_info(FAULT_EVICT_INODE);
                err = -EIO;
        }
-#endif
+
        if (!err) {
                f2fs_lock_op(sbi);
                err = f2fs_remove_inode_page(inode);
index 472dd643b0743a774c25b6d29b631b2f6e748179..dd2e45a661aacdb123b63c92f84e717f17fa59c1 100644 (file)
@@ -2323,12 +2323,11 @@ 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:
-#ifdef CONFIG_F2FS_FAULT_INJECTION
        if (time_to_inject(sbi, FAULT_ALLOC_NID)) {
                f2fs_show_injection_info(FAULT_ALLOC_NID);
                return false;
        }
-#endif
+
        spin_lock(&nm_i->nid_list_lock);
 
        if (unlikely(nm_i->available_nids == 0)) {
index 64e5a59a270a3f46c5a400d2b6a6e1f6894142dd..95511ed11a22650018ba2ffc9593dbf7c0d063db 100644 (file)
@@ -518,10 +518,9 @@ retry_dn:
 
                        if (src == NULL_ADDR) {
                                err = f2fs_reserve_new_block(&dn);
-#ifdef CONFIG_F2FS_FAULT_INJECTION
-                               while (err)
+                               while (err &&
+                                      IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION))
                                        err = f2fs_reserve_new_block(&dn);
-#endif
                                /* We should not get -ENOSPC */
                                f2fs_bug_on(sbi, err);
                                if (err)
index 63fc647f9ac2a3edbaee907e73585c8efe62985a..b136e39e1e9ec868448fab474ddb8e14d909feef 100644 (file)
@@ -470,12 +470,10 @@ int f2fs_commit_inmem_pages(struct inode *inode)
  */
 void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need)
 {
-#ifdef CONFIG_F2FS_FAULT_INJECTION
        if (time_to_inject(sbi, FAULT_CHECKPOINT)) {
                f2fs_show_injection_info(FAULT_CHECKPOINT);
                f2fs_stop_checkpoint(sbi, false);
        }
-#endif
 
        /* balance_fs_bg is able to be pending */
        if (need && excess_cached_nats(sbi))
@@ -1041,13 +1039,11 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
 
                dc->len += len;
 
-#ifdef CONFIG_F2FS_FAULT_INJECTION
                if (time_to_inject(sbi, FAULT_DISCARD)) {
                        f2fs_show_injection_info(FAULT_DISCARD);
                        err = -EIO;
                        goto submit;
                }
-#endif
                err = __blkdev_issue_discard(bdev,
                                        SECTOR_FROM_BLOCK(start),
                                        SECTOR_FROM_BLOCK(len),