]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
f2fs: inject kmalloc failure
authorJaegeuk Kim <jaegeuk@kernel.org>
Fri, 29 Apr 2016 22:49:56 +0000 (15:49 -0700)
committerJaegeuk Kim <jaegeuk@kernel.org>
Sat, 7 May 2016 17:32:22 +0000 (10:32 -0700)
This patch injects kmalloc failure given a fault injection rate.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/f2fs.h
fs/f2fs/super.c

index 0cf2a26388e557841be3608dc8f5e9f00ca7b867..cf03c57d0febb34cb937b5185c1d36c5e3b7c60b 100644 (file)
        } while (0)
 #endif
 
+#ifdef CONFIG_F2FS_FAULT_INJECTION
+enum {
+       FAULT_KMALLOC,
+       FAULT_MAX,
+};
+
+extern u32 f2fs_fault_rate;
+extern atomic_t f2fs_ops;
+extern char *fault_name[FAULT_MAX];
+
+static inline bool time_to_inject(int type)
+{
+       atomic_inc(&f2fs_ops);
+       if (f2fs_fault_rate && (atomic_read(&f2fs_ops) >= f2fs_fault_rate)) {
+               atomic_set(&f2fs_ops, 0);
+               printk("%sF2FS-fs : inject %s in %pF\n",
+                               KERN_INFO,
+                               fault_name[type],
+                               __builtin_return_address(0));
+               return true;
+       }
+       return false;
+}
+#endif
+
 /*
  * For mount options
  */
@@ -1647,6 +1672,10 @@ static inline bool f2fs_may_extent_tree(struct inode *inode)
 
 static inline void *f2fs_kmalloc(size_t size, gfp_t flags)
 {
+#ifdef CONFIG_F2FS_FAULT_INJECTION
+       if (time_to_inject(FAULT_KMALLOC))
+               return NULL;
+#endif
        return kmalloc(size, flags);
 }
 
index 22348791700faeff5d6840fa1dc94ae165f35fa3..9a56f544da3eaeea08f15f891e0315e2bcead18c 100644 (file)
@@ -41,6 +41,11 @@ static struct kset *f2fs_kset;
 
 #ifdef CONFIG_F2FS_FAULT_INJECTION
 u32 f2fs_fault_rate = 0;
+atomic_t f2fs_ops;
+
+char *fault_name[FAULT_MAX] = {
+       [FAULT_KMALLOC]         = "kmalloc",
+};
 #endif
 
 /* f2fs-wide shrinker description */
@@ -447,6 +452,7 @@ static int parse_options(struct super_block *sb, char *options)
                                return -EINVAL;
 #ifdef CONFIG_F2FS_FAULT_INJECTION
                        f2fs_fault_rate = arg;
+                       atomic_set(&f2fs_ops, 0);
 #else
                        f2fs_msg(sb, KERN_INFO,
                                "FAULT_INJECTION was not selected");