aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2018-08-13 17:38:06 -0400
committerJaegeuk Kim <jaegeuk@kernel.org>2018-08-14 12:49:15 -0400
commit7fa750a163089cf96866de402314d853a96cb342 (patch)
treec47c85285e4213a7c88fbdffd3fc27fcc16a913b
parentd494500a70434223bc35f862fab0679b13bea23d (diff)
f2fs: rework fault injection handling to avoid a warning
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>
-rw-r--r--fs/f2fs/checkpoint.c3
-rw-r--r--fs/f2fs/data.c2
-rw-r--r--fs/f2fs/dir.c3
-rw-r--r--fs/f2fs/f2fs.h50
-rw-r--r--fs/f2fs/file.c3
-rw-r--r--fs/f2fs/gc.c2
-rw-r--r--fs/f2fs/inode.c3
-rw-r--r--fs/f2fs/node.c3
-rw-r--r--fs/f2fs/recovery.c5
-rw-r--r--fs/f2fs/segment.c4
10 files changed, 32 insertions, 46 deletions
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 3ab7a00c0641..e8b6b89bddb8 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -555,13 +555,12 @@ int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi)
555 555
556 spin_lock(&im->ino_lock); 556 spin_lock(&im->ino_lock);
557 557
558#ifdef CONFIG_F2FS_FAULT_INJECTION
559 if (time_to_inject(sbi, FAULT_ORPHAN)) { 558 if (time_to_inject(sbi, FAULT_ORPHAN)) {
560 spin_unlock(&im->ino_lock); 559 spin_unlock(&im->ino_lock);
561 f2fs_show_injection_info(FAULT_ORPHAN); 560 f2fs_show_injection_info(FAULT_ORPHAN);
562 return -ENOSPC; 561 return -ENOSPC;
563 } 562 }
564#endif 563
565 if (unlikely(im->ino_num >= sbi->max_orphans)) 564 if (unlikely(im->ino_num >= sbi->max_orphans))
566 err = -ENOSPC; 565 err = -ENOSPC;
567 else 566 else
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 45f043ee48bd..43d3723dc886 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -126,12 +126,10 @@ static bool f2fs_bio_post_read_required(struct bio *bio)
126 126
127static void f2fs_read_end_io(struct bio *bio) 127static void f2fs_read_end_io(struct bio *bio)
128{ 128{
129#ifdef CONFIG_F2FS_FAULT_INJECTION
130 if (time_to_inject(F2FS_P_SB(bio_first_page_all(bio)), FAULT_IO)) { 129 if (time_to_inject(F2FS_P_SB(bio_first_page_all(bio)), FAULT_IO)) {
131 f2fs_show_injection_info(FAULT_IO); 130 f2fs_show_injection_info(FAULT_IO);
132 bio->bi_status = BLK_STS_IOERR; 131 bio->bi_status = BLK_STS_IOERR;
133 } 132 }
134#endif
135 133
136 if (f2fs_bio_post_read_required(bio)) { 134 if (f2fs_bio_post_read_required(bio)) {
137 struct bio_post_read_ctx *ctx = bio->bi_private; 135 struct bio_post_read_ctx *ctx = bio->bi_private;
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 7f955c4e86a4..ecc3a4e2be96 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -517,12 +517,11 @@ int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name,
517 } 517 }
518 518
519start: 519start:
520#ifdef CONFIG_F2FS_FAULT_INJECTION
521 if (time_to_inject(F2FS_I_SB(dir), FAULT_DIR_DEPTH)) { 520 if (time_to_inject(F2FS_I_SB(dir), FAULT_DIR_DEPTH)) {
522 f2fs_show_injection_info(FAULT_DIR_DEPTH); 521 f2fs_show_injection_info(FAULT_DIR_DEPTH);
523 return -ENOSPC; 522 return -ENOSPC;
524 } 523 }
525#endif 524
526 if (unlikely(current_depth == MAX_DIR_HASH_DEPTH)) 525 if (unlikely(current_depth == MAX_DIR_HASH_DEPTH))
527 return -ENOSPC; 526 return -ENOSPC;
528 527
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 375aa9f30cfa..9a6ba4a8d338 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -41,7 +41,6 @@
41 } while (0) 41 } while (0)
42#endif 42#endif
43 43
44#ifdef CONFIG_F2FS_FAULT_INJECTION
45enum { 44enum {
46 FAULT_KMALLOC, 45 FAULT_KMALLOC,
47 FAULT_KVMALLOC, 46 FAULT_KVMALLOC,
@@ -60,6 +59,7 @@ enum {
60 FAULT_MAX, 59 FAULT_MAX,
61}; 60};
62 61
62#ifdef CONFIG_F2FS_FAULT_INJECTION
63#define F2FS_ALL_FAULT_TYPE ((1 << FAULT_MAX) - 1) 63#define F2FS_ALL_FAULT_TYPE ((1 << FAULT_MAX) - 1)
64 64
65struct f2fs_fault_info { 65struct f2fs_fault_info {
@@ -1324,6 +1324,12 @@ static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
1324 } 1324 }
1325 return false; 1325 return false;
1326} 1326}
1327#else
1328#define f2fs_show_injection_info(type) do { } while (0)
1329static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
1330{
1331 return false;
1332}
1327#endif 1333#endif
1328 1334
1329/* For write statistics. Suppose sector size is 512 bytes, 1335/* 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,
1676 if (ret) 1682 if (ret)
1677 return ret; 1683 return ret;
1678 1684
1679#ifdef CONFIG_F2FS_FAULT_INJECTION
1680 if (time_to_inject(sbi, FAULT_BLOCK)) { 1685 if (time_to_inject(sbi, FAULT_BLOCK)) {
1681 f2fs_show_injection_info(FAULT_BLOCK); 1686 f2fs_show_injection_info(FAULT_BLOCK);
1682 release = *count; 1687 release = *count;
1683 goto enospc; 1688 goto enospc;
1684 } 1689 }
1685#endif 1690
1686 /* 1691 /*
1687 * let's increase this in prior to actual block count change in order 1692 * let's increase this in prior to actual block count change in order
1688 * for f2fs_sync_file to avoid data races when deciding checkpoint. 1693 * 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,
1891 return ret; 1896 return ret;
1892 } 1897 }
1893 1898
1894#ifdef CONFIG_F2FS_FAULT_INJECTION
1895 if (time_to_inject(sbi, FAULT_BLOCK)) { 1899 if (time_to_inject(sbi, FAULT_BLOCK)) {
1896 f2fs_show_injection_info(FAULT_BLOCK); 1900 f2fs_show_injection_info(FAULT_BLOCK);
1897 goto enospc; 1901 goto enospc;
1898 } 1902 }
1899#endif
1900 1903
1901 spin_lock(&sbi->stat_lock); 1904 spin_lock(&sbi->stat_lock);
1902 1905
@@ -1981,22 +1984,23 @@ static inline s64 valid_inode_count(struct f2fs_sb_info *sbi)
1981static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1984static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
1982 pgoff_t index, bool for_write) 1985 pgoff_t index, bool for_write)
1983{ 1986{
1984#ifdef CONFIG_F2FS_FAULT_INJECTION
1985 struct page *page; 1987 struct page *page;
1986 1988
1987 if (!for_write) 1989 if (IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)) {
1988 page = find_get_page_flags(mapping, index, 1990 if (!for_write)
1989 FGP_LOCK | FGP_ACCESSED); 1991 page = find_get_page_flags(mapping, index,
1990 else 1992 FGP_LOCK | FGP_ACCESSED);
1991 page = find_lock_page(mapping, index); 1993 else
1992 if (page) 1994 page = find_lock_page(mapping, index);
1993 return page; 1995 if (page)
1996 return page;
1994 1997
1995 if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 1998 if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) {
1996 f2fs_show_injection_info(FAULT_PAGE_ALLOC); 1999 f2fs_show_injection_info(FAULT_PAGE_ALLOC);
1997 return NULL; 2000 return NULL;
2001 }
1998 } 2002 }
1999#endif 2003
2000 if (!for_write) 2004 if (!for_write)
2001 return grab_cache_page(mapping, index); 2005 return grab_cache_page(mapping, index);
2002 return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 2006 return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS);
@@ -2006,12 +2010,11 @@ static inline struct page *f2fs_pagecache_get_page(
2006 struct address_space *mapping, pgoff_t index, 2010 struct address_space *mapping, pgoff_t index,
2007 int fgp_flags, gfp_t gfp_mask) 2011 int fgp_flags, gfp_t gfp_mask)
2008{ 2012{
2009#ifdef CONFIG_F2FS_FAULT_INJECTION
2010 if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) { 2013 if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) {
2011 f2fs_show_injection_info(FAULT_PAGE_GET); 2014 f2fs_show_injection_info(FAULT_PAGE_GET);
2012 return NULL; 2015 return NULL;
2013 } 2016 }
2014#endif 2017
2015 return pagecache_get_page(mapping, index, fgp_flags, gfp_mask); 2018 return pagecache_get_page(mapping, index, fgp_flags, gfp_mask);
2016} 2019}
2017 2020
@@ -2076,12 +2079,11 @@ static inline struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi,
2076 bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 2079 bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages);
2077 return bio; 2080 return bio;
2078 } 2081 }
2079#ifdef CONFIG_F2FS_FAULT_INJECTION
2080 if (time_to_inject(sbi, FAULT_ALLOC_BIO)) { 2082 if (time_to_inject(sbi, FAULT_ALLOC_BIO)) {
2081 f2fs_show_injection_info(FAULT_ALLOC_BIO); 2083 f2fs_show_injection_info(FAULT_ALLOC_BIO);
2082 return NULL; 2084 return NULL;
2083 } 2085 }
2084#endif 2086
2085 return bio_alloc(GFP_KERNEL, npages); 2087 return bio_alloc(GFP_KERNEL, npages);
2086} 2088}
2087 2089
@@ -2616,12 +2618,11 @@ static inline bool f2fs_may_extent_tree(struct inode *inode)
2616static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 2618static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi,
2617 size_t size, gfp_t flags) 2619 size_t size, gfp_t flags)
2618{ 2620{
2619#ifdef CONFIG_F2FS_FAULT_INJECTION
2620 if (time_to_inject(sbi, FAULT_KMALLOC)) { 2621 if (time_to_inject(sbi, FAULT_KMALLOC)) {
2621 f2fs_show_injection_info(FAULT_KMALLOC); 2622 f2fs_show_injection_info(FAULT_KMALLOC);
2622 return NULL; 2623 return NULL;
2623 } 2624 }
2624#endif 2625
2625 return kmalloc(size, flags); 2626 return kmalloc(size, flags);
2626} 2627}
2627 2628
@@ -2634,12 +2635,11 @@ static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi,
2634static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi, 2635static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi,
2635 size_t size, gfp_t flags) 2636 size_t size, gfp_t flags)
2636{ 2637{
2637#ifdef CONFIG_F2FS_FAULT_INJECTION
2638 if (time_to_inject(sbi, FAULT_KVMALLOC)) { 2638 if (time_to_inject(sbi, FAULT_KVMALLOC)) {
2639 f2fs_show_injection_info(FAULT_KVMALLOC); 2639 f2fs_show_injection_info(FAULT_KVMALLOC);
2640 return NULL; 2640 return NULL;
2641 } 2641 }
2642#endif 2642
2643 return kvmalloc(size, flags); 2643 return kvmalloc(size, flags);
2644} 2644}
2645 2645
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 8c4694b9af27..1f76cc3fc46b 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -668,12 +668,11 @@ int f2fs_truncate(struct inode *inode)
668 668
669 trace_f2fs_truncate(inode); 669 trace_f2fs_truncate(inode);
670 670
671#ifdef CONFIG_F2FS_FAULT_INJECTION
672 if (time_to_inject(F2FS_I_SB(inode), FAULT_TRUNCATE)) { 671 if (time_to_inject(F2FS_I_SB(inode), FAULT_TRUNCATE)) {
673 f2fs_show_injection_info(FAULT_TRUNCATE); 672 f2fs_show_injection_info(FAULT_TRUNCATE);
674 return -EIO; 673 return -EIO;
675 } 674 }
676#endif 675
677 /* we should check inline_data size */ 676 /* we should check inline_data size */
678 if (!f2fs_may_inline_data(inode)) { 677 if (!f2fs_may_inline_data(inode)) {
679 err = f2fs_convert_inline_inode(inode); 678 err = f2fs_convert_inline_inode(inode);
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index e352fbd33848..76a22b3773bc 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -53,12 +53,10 @@ static int gc_thread_func(void *data)
53 continue; 53 continue;
54 } 54 }
55 55
56#ifdef CONFIG_F2FS_FAULT_INJECTION
57 if (time_to_inject(sbi, FAULT_CHECKPOINT)) { 56 if (time_to_inject(sbi, FAULT_CHECKPOINT)) {
58 f2fs_show_injection_info(FAULT_CHECKPOINT); 57 f2fs_show_injection_info(FAULT_CHECKPOINT);
59 f2fs_stop_checkpoint(sbi, false); 58 f2fs_stop_checkpoint(sbi, false);
60 } 59 }
61#endif
62 60
63 if (!sb_start_write_trylock(sbi->sb)) 61 if (!sb_start_write_trylock(sbi->sb))
64 continue; 62 continue;
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index fc2c98b9e255..6908896a1950 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -659,12 +659,11 @@ retry:
659 if (F2FS_HAS_BLOCKS(inode)) 659 if (F2FS_HAS_BLOCKS(inode))
660 err = f2fs_truncate(inode); 660 err = f2fs_truncate(inode);
661 661
662#ifdef CONFIG_F2FS_FAULT_INJECTION
663 if (time_to_inject(sbi, FAULT_EVICT_INODE)) { 662 if (time_to_inject(sbi, FAULT_EVICT_INODE)) {
664 f2fs_show_injection_info(FAULT_EVICT_INODE); 663 f2fs_show_injection_info(FAULT_EVICT_INODE);
665 err = -EIO; 664 err = -EIO;
666 } 665 }
667#endif 666
668 if (!err) { 667 if (!err) {
669 f2fs_lock_op(sbi); 668 f2fs_lock_op(sbi);
670 err = f2fs_remove_inode_page(inode); 669 err = f2fs_remove_inode_page(inode);
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 472dd643b074..dd2e45a661aa 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -2323,12 +2323,11 @@ bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid)
2323 struct f2fs_nm_info *nm_i = NM_I(sbi); 2323 struct f2fs_nm_info *nm_i = NM_I(sbi);
2324 struct free_nid *i = NULL; 2324 struct free_nid *i = NULL;
2325retry: 2325retry:
2326#ifdef CONFIG_F2FS_FAULT_INJECTION
2327 if (time_to_inject(sbi, FAULT_ALLOC_NID)) { 2326 if (time_to_inject(sbi, FAULT_ALLOC_NID)) {
2328 f2fs_show_injection_info(FAULT_ALLOC_NID); 2327 f2fs_show_injection_info(FAULT_ALLOC_NID);
2329 return false; 2328 return false;
2330 } 2329 }
2331#endif 2330
2332 spin_lock(&nm_i->nid_list_lock); 2331 spin_lock(&nm_i->nid_list_lock);
2333 2332
2334 if (unlikely(nm_i->available_nids == 0)) { 2333 if (unlikely(nm_i->available_nids == 0)) {
diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c
index 64e5a59a270a..95511ed11a22 100644
--- a/fs/f2fs/recovery.c
+++ b/fs/f2fs/recovery.c
@@ -518,10 +518,9 @@ retry_dn:
518 518
519 if (src == NULL_ADDR) { 519 if (src == NULL_ADDR) {
520 err = f2fs_reserve_new_block(&dn); 520 err = f2fs_reserve_new_block(&dn);
521#ifdef CONFIG_F2FS_FAULT_INJECTION 521 while (err &&
522 while (err) 522 IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION))
523 err = f2fs_reserve_new_block(&dn); 523 err = f2fs_reserve_new_block(&dn);
524#endif
525 /* We should not get -ENOSPC */ 524 /* We should not get -ENOSPC */
526 f2fs_bug_on(sbi, err); 525 f2fs_bug_on(sbi, err);
527 if (err) 526 if (err)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 63fc647f9ac2..b136e39e1e9e 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -470,12 +470,10 @@ int f2fs_commit_inmem_pages(struct inode *inode)
470 */ 470 */
471void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need) 471void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need)
472{ 472{
473#ifdef CONFIG_F2FS_FAULT_INJECTION
474 if (time_to_inject(sbi, FAULT_CHECKPOINT)) { 473 if (time_to_inject(sbi, FAULT_CHECKPOINT)) {
475 f2fs_show_injection_info(FAULT_CHECKPOINT); 474 f2fs_show_injection_info(FAULT_CHECKPOINT);
476 f2fs_stop_checkpoint(sbi, false); 475 f2fs_stop_checkpoint(sbi, false);
477 } 476 }
478#endif
479 477
480 /* balance_fs_bg is able to be pending */ 478 /* balance_fs_bg is able to be pending */
481 if (need && excess_cached_nats(sbi)) 479 if (need && excess_cached_nats(sbi))
@@ -1041,13 +1039,11 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
1041 1039
1042 dc->len += len; 1040 dc->len += len;
1043 1041
1044#ifdef CONFIG_F2FS_FAULT_INJECTION
1045 if (time_to_inject(sbi, FAULT_DISCARD)) { 1042 if (time_to_inject(sbi, FAULT_DISCARD)) {
1046 f2fs_show_injection_info(FAULT_DISCARD); 1043 f2fs_show_injection_info(FAULT_DISCARD);
1047 err = -EIO; 1044 err = -EIO;
1048 goto submit; 1045 goto submit;
1049 } 1046 }
1050#endif
1051 err = __blkdev_issue_discard(bdev, 1047 err = __blkdev_issue_discard(bdev,
1052 SECTOR_FROM_BLOCK(start), 1048 SECTOR_FROM_BLOCK(start),
1053 SECTOR_FROM_BLOCK(len), 1049 SECTOR_FROM_BLOCK(len),