f2fs: support fault_type mount option
authorChao Yu <yuchao0@huawei.com>
Wed, 8 Aug 2018 09:36:41 +0000 (17:36 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Mon, 13 Aug 2018 17:48:17 +0000 (10:48 -0700)
Previously, once fault injection is on, by default, all kind of faults
will be injected to f2fs, if we want to trigger single or specified
combined type during the test, we need to configure sysfs entry, it will
be a little inconvenient to integrate sysfs configuring into testsuit,
such as xfstest.

So this patch introduces a new mount option 'fault_type' to assist old
option 'fault_injection', with these two mount options, we can specify
any fault rate/type at mount-time.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Documentation/filesystems/f2fs.txt
fs/f2fs/checkpoint.c
fs/f2fs/f2fs.h
fs/f2fs/super.c

index 69f8de99573974749263a33d75904ad5d37971de..e5edd29687b50a74f8946ca215f639bb71b434fa 100644 (file)
@@ -157,6 +157,24 @@ data_flush             Enable data flushing before checkpoint in order to
                        persist data of regular and symlink.
 fault_injection=%d     Enable fault injection in all supported types with
                        specified injection rate.
+fault_type=%d          Support configuring fault injection type, should be
+                       enabled with fault_injection option, fault type value
+                       is shown below, it supports single or combined type.
+                       Type_Name               Type_Value
+                       FAULT_KMALLOC           0x000000001
+                       FAULT_KVMALLOC          0x000000002
+                       FAULT_PAGE_ALLOC                0x000000004
+                       FAULT_PAGE_GET          0x000000008
+                       FAULT_ALLOC_BIO         0x000000010
+                       FAULT_ALLOC_NID         0x000000020
+                       FAULT_ORPHAN            0x000000040
+                       FAULT_BLOCK             0x000000080
+                       FAULT_DIR_DEPTH         0x000000100
+                       FAULT_EVICT_INODE       0x000000200
+                       FAULT_TRUNCATE          0x000000400
+                       FAULT_IO                        0x000000800
+                       FAULT_CHECKPOINT                0x000001000
+                       FAULT_DISCARD           0x000002000
 mode=%s                Control block allocation mode which supports "adaptive"
                        and "lfs". In "lfs" mode, there should be no random
                        writes towards main area.
index 31561026ac9acf3be23fe7c9d82c9dd560be3857..3ab7a00c0641f766d85b87589f8b3e270497e5c0 100644 (file)
@@ -28,7 +28,7 @@ struct kmem_cache *f2fs_inode_entry_slab;
 
 void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io)
 {
-       f2fs_build_fault_attr(sbi, 0);
+       f2fs_build_fault_attr(sbi, 0, 0);
        set_ckpt_flags(sbi, CP_ERROR_FLAG);
        if (!end_io)
                f2fs_flush_merged_writes(sbi);
index 95244e75dfc4538d90c1c160fe0095a62453da40..375aa9f30cfa336f80d67b82ab61564228d73cac 100644 (file)
@@ -60,6 +60,8 @@ enum {
        FAULT_MAX,
 };
 
+#define F2FS_ALL_FAULT_TYPE            ((1 << FAULT_MAX) - 1)
+
 struct f2fs_fault_info {
        atomic_t inject_ops;
        unsigned int inject_rate;
@@ -3435,9 +3437,10 @@ static inline bool f2fs_force_buffered_io(struct inode *inode, int rw)
 }
 
 #ifdef CONFIG_F2FS_FAULT_INJECTION
-extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate);
+extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,
+                                                       unsigned int type);
 #else
-#define f2fs_build_fault_attr(sbi, rate)               do { } while (0)
+#define f2fs_build_fault_attr(sbi, rate, type)         do { } while (0)
 #endif
 
 #endif
index 30bd9138f39df062fea24ab0073e0dfd5ebedb0d..be41dbd7b261d20aac957af79ce01c92692418f7 100644 (file)
@@ -58,17 +58,21 @@ char *f2fs_fault_name[FAULT_MAX] = {
        [FAULT_DISCARD]         = "discard error",
 };
 
-void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate)
+void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,
+                                                       unsigned int type)
 {
        struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info;
 
        if (rate) {
                atomic_set(&ffi->inject_ops, 0);
                ffi->inject_rate = rate;
-               ffi->inject_type = (1 << FAULT_MAX) - 1;
-       } else {
-               memset(ffi, 0, sizeof(struct f2fs_fault_info));
        }
+
+       if (type)
+               ffi->inject_type = type;
+
+       if (!rate && !type)
+               memset(ffi, 0, sizeof(struct f2fs_fault_info));
 }
 #endif
 
@@ -113,6 +117,7 @@ enum {
        Opt_mode,
        Opt_io_size_bits,
        Opt_fault_injection,
+       Opt_fault_type,
        Opt_lazytime,
        Opt_nolazytime,
        Opt_quota,
@@ -170,6 +175,7 @@ static match_table_t f2fs_tokens = {
        {Opt_mode, "mode=%s"},
        {Opt_io_size_bits, "io_bits=%u"},
        {Opt_fault_injection, "fault_injection=%u"},
+       {Opt_fault_type, "fault_type=%u"},
        {Opt_lazytime, "lazytime"},
        {Opt_nolazytime, "nolazytime"},
        {Opt_quota, "quota"},
@@ -600,7 +606,18 @@ static int parse_options(struct super_block *sb, char *options)
                        if (args->from && match_int(args, &arg))
                                return -EINVAL;
 #ifdef CONFIG_F2FS_FAULT_INJECTION
-                       f2fs_build_fault_attr(sbi, arg);
+                       f2fs_build_fault_attr(sbi, arg, F2FS_ALL_FAULT_TYPE);
+                       set_opt(sbi, FAULT_INJECTION);
+#else
+                       f2fs_msg(sb, KERN_INFO,
+                               "FAULT_INJECTION was not selected");
+#endif
+                       break;
+               case Opt_fault_type:
+                       if (args->from && match_int(args, &arg))
+                               return -EINVAL;
+#ifdef CONFIG_F2FS_FAULT_INJECTION
+                       f2fs_build_fault_attr(sbi, 0, arg);
                        set_opt(sbi, FAULT_INJECTION);
 #else
                        f2fs_msg(sb, KERN_INFO,
@@ -1321,9 +1338,12 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
        if (F2FS_IO_SIZE_BITS(sbi))
                seq_printf(seq, ",io_size=%uKB", F2FS_IO_SIZE_KB(sbi));
 #ifdef CONFIG_F2FS_FAULT_INJECTION
-       if (test_opt(sbi, FAULT_INJECTION))
+       if (test_opt(sbi, FAULT_INJECTION)) {
                seq_printf(seq, ",fault_injection=%u",
                                F2FS_OPTION(sbi).fault_info.inject_rate);
+               seq_printf(seq, ",fault_type=%u",
+                               F2FS_OPTION(sbi).fault_info.inject_type);
+       }
 #endif
 #ifdef CONFIG_QUOTA
        if (test_opt(sbi, QUOTA))
@@ -1393,7 +1413,7 @@ static void default_options(struct f2fs_sb_info *sbi)
        set_opt(sbi, POSIX_ACL);
 #endif
 
-       f2fs_build_fault_attr(sbi, 0);
+       f2fs_build_fault_attr(sbi, 0, 0);
 }
 
 #ifdef CONFIG_QUOTA