fsstress: Add fallocate insert range operation
authorNamjae Jeon <namjae.jeon@samsung.com>
Wed, 25 Feb 2015 04:34:48 +0000 (15:34 +1100)
committerDave Chinner <david@fromorbit.com>
Wed, 25 Feb 2015 04:34:48 +0000 (15:34 +1100)
This commit adds insert operation support for fsstress, which is
meant to exercise fallocate FALLOC_FL_INSERT_RANGE support.

[dchinner: turn off this op for xfs/068, which expects an exact
outcome from the fsstress execution. ]

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Ashish Sangwan <a.sangwan@samsung.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
ltp/fsstress.c
src/global.h
tests/xfs/068

index b56fe5c6a1044cca8c249175c4ad15ad72f969b6..aa3e0c309ddbf08dc52f4db35283196a150bfaea 100644 (file)
@@ -72,6 +72,7 @@ typedef enum {
        OP_PUNCH,
        OP_ZERO,
        OP_COLLAPSE,
        OP_PUNCH,
        OP_ZERO,
        OP_COLLAPSE,
+       OP_INSERT,
        OP_READ,
        OP_READLINK,
        OP_RENAME,
        OP_READ,
        OP_READLINK,
        OP_RENAME,
@@ -170,6 +171,7 @@ void        mknod_f(int, long);
 void   punch_f(int, long);
 void   zero_f(int, long);
 void   collapse_f(int, long);
 void   punch_f(int, long);
 void   zero_f(int, long);
 void   collapse_f(int, long);
+void   insert_f(int, long);
 void   read_f(int, long);
 void   readlink_f(int, long);
 void   rename_f(int, long);
 void   read_f(int, long);
 void   readlink_f(int, long);
 void   rename_f(int, long);
@@ -209,6 +211,7 @@ opdesc_t    ops[] = {
        { OP_PUNCH, "punch", punch_f, 1, 1 },
        { OP_ZERO, "zero", zero_f, 1, 1 },
        { OP_COLLAPSE, "collapse", collapse_f, 1, 1 },
        { OP_PUNCH, "punch", punch_f, 1, 1 },
        { OP_ZERO, "zero", zero_f, 1, 1 },
        { OP_COLLAPSE, "collapse", collapse_f, 1, 1 },
+       { OP_INSERT, "insert", insert_f, 1, 1 },
        { OP_READ, "read", read_f, 1, 0 },
        { OP_READLINK, "readlink", readlink_f, 1, 0 },
        { OP_RENAME, "rename", rename_f, 2, 1 },
        { OP_READ, "read", read_f, 1, 0 },
        { OP_READLINK, "readlink", readlink_f, 1, 0 },
        { OP_RENAME, "rename", rename_f, 2, 1 },
@@ -2176,6 +2179,7 @@ struct print_flags falloc_flags [] = {
        { FALLOC_FL_NO_HIDE_STALE, "NO_HIDE_STALE"},
        { FALLOC_FL_COLLAPSE_RANGE, "COLLAPSE_RANGE"},
        { FALLOC_FL_ZERO_RANGE, "ZERO_RANGE"},
        { FALLOC_FL_NO_HIDE_STALE, "NO_HIDE_STALE"},
        { FALLOC_FL_COLLAPSE_RANGE, "COLLAPSE_RANGE"},
        { FALLOC_FL_ZERO_RANGE, "ZERO_RANGE"},
+       { FALLOC_FL_INSERT_RANGE, "INSERT_RANGE"},
        { -1, NULL}
 };
 
        { -1, NULL}
 };
 
@@ -2227,10 +2231,11 @@ do_fallocate(int opno, long r, int mode)
        off %= maxfsize;
        len = (off64_t)(random() % (1024 * 1024));
        /*
        off %= maxfsize;
        len = (off64_t)(random() % (1024 * 1024));
        /*
-        * Collapse range requires off and len to be block aligned, make it
-        * more likely to be the case.
+        * Collapse/insert range requires off and len to be block aligned,
+        * make it more likely to be the case.
         */
         */
-       if ((mode & FALLOC_FL_COLLAPSE_RANGE) && (opno % 2)) {
+       if ((mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE)) &&
+               (opno % 2)) {
                off = ((off + stb.st_blksize - 1) & ~(stb.st_blksize - 1));
                len = ((len + stb.st_blksize - 1) & ~(stb.st_blksize - 1));
        }
                off = ((off + stb.st_blksize - 1) & ~(stb.st_blksize - 1));
                len = ((len + stb.st_blksize - 1) & ~(stb.st_blksize - 1));
        }
@@ -2655,6 +2660,14 @@ collapse_f(int opno, long r)
 #endif
 }
 
 #endif
 }
 
+void
+insert_f(int opno, long r)
+{
+#ifdef HAVE_LINUX_FALLOC_H
+       do_fallocate(opno, r, FALLOC_FL_INSERT_RANGE);
+#endif
+}
+
 void
 read_f(int opno, long r)
 {
 void
 read_f(int opno, long r)
 {
index 8180f66821e3ad286149dcb155dad6dde630ec14..f63246bd5e6b8ded1953152f708c65691cef1ea4 100644 (file)
 #define FALLOC_FL_ZERO_RANGE           0x10
 #endif
 
 #define FALLOC_FL_ZERO_RANGE           0x10
 #endif
 
+#ifndef FALLOC_FL_INSERT_RANGE
+#define FALLOC_FL_INSERT_RANGE         0x20
+#endif
+
 #endif /* HAVE_LINUX_FALLOC_H */
 
 #endif /* GLOBAL_H */
 #endif /* HAVE_LINUX_FALLOC_H */
 
 #endif /* GLOBAL_H */
index 7151e28ef0d883368d3c177cf081002d82f1a46b..4dac95ebac93032d240d6c3eaee8f70a5ae424b3 100755 (executable)
@@ -43,6 +43,8 @@ trap "rm -rf $tmp.*; exit \$status" 0 1 2 3 15
 _supported_fs xfs
 _supported_os Linux
 
 _supported_fs xfs
 _supported_os Linux
 
+# need to ensure new fsstress operations don't perturb expected output
+FSSTRESS_AVOID="-f insert=0 $FSSTRESS_AVOID"
 _create_dumpdir_stress_num 4096
 _do_dump_restore
 
 _create_dumpdir_stress_num 4096
 _do_dump_restore