aboutsummaryrefslogtreecommitdiffstats
path: root/fs/f2fs/f2fs.h
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@kernel.org>2016-04-29 18:49:56 -0400
committerJaegeuk Kim <jaegeuk@kernel.org>2016-05-07 13:32:22 -0400
commit2c63fead9e372b3b65d1883bb174df6c9820f1dd (patch)
tree885acae64bc6daf3c08ea10403b0bb36109b9a76 /fs/f2fs/f2fs.h
parent73faec4d99358b79815866dd660ae2f9f6f9110a (diff)
f2fs: inject kmalloc failure
This patch injects kmalloc failure given a fault injection rate. Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs/f2fs.h')
-rw-r--r--fs/f2fs/f2fs.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 0cf2a26388e5..cf03c57d0feb 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -37,6 +37,31 @@
37 } while (0) 37 } while (0)
38#endif 38#endif
39 39
40#ifdef CONFIG_F2FS_FAULT_INJECTION
41enum {
42 FAULT_KMALLOC,
43 FAULT_MAX,
44};
45
46extern u32 f2fs_fault_rate;
47extern atomic_t f2fs_ops;
48extern char *fault_name[FAULT_MAX];
49
50static inline bool time_to_inject(int type)
51{
52 atomic_inc(&f2fs_ops);
53 if (f2fs_fault_rate && (atomic_read(&f2fs_ops) >= f2fs_fault_rate)) {
54 atomic_set(&f2fs_ops, 0);
55 printk("%sF2FS-fs : inject %s in %pF\n",
56 KERN_INFO,
57 fault_name[type],
58 __builtin_return_address(0));
59 return true;
60 }
61 return false;
62}
63#endif
64
40/* 65/*
41 * For mount options 66 * For mount options
42 */ 67 */
@@ -1647,6 +1672,10 @@ static inline bool f2fs_may_extent_tree(struct inode *inode)
1647 1672
1648static inline void *f2fs_kmalloc(size_t size, gfp_t flags) 1673static inline void *f2fs_kmalloc(size_t size, gfp_t flags)
1649{ 1674{
1675#ifdef CONFIG_F2FS_FAULT_INJECTION
1676 if (time_to_inject(FAULT_KMALLOC))
1677 return NULL;
1678#endif
1650 return kmalloc(size, flags); 1679 return kmalloc(size, flags);
1651} 1680}
1652 1681