fstests: Add more sanity to seek_sanity_test
authorAmir Goldstein <amir73il@gmail.com>
Wed, 3 Apr 2019 05:59:25 +0000 (08:59 +0300)
committerEryu Guan <guaneryu@gmail.com>
Sat, 6 Apr 2019 11:47:53 +0000 (19:47 +0800)
seek_sanity_test checks for one of several SEEK_DATA/HOLE
behaviors and allows for the default behavior of filesystems,
where SEEK_HOLE always returns EOF.

This means that if filesystem has a regression in finding
holes, the sanity test won't catch it. And indeed this regression
happened in overlayfs on kernel v4.19 and went unnoticed.

To improve test coverage, add a flag -f to seek_sanity_test to
indicate that the default behavior is not acceptable.
Whitelist all filesystem types that are expected to detect holes
and use wrapper when invoking seek_sanity_test to add the -f flag
to those filesystems.

Overlayfs inherits expected behavior from base fs type.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Acked-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
common/rc
src/seek_sanity_test.c
tests/generic/285
tests/generic/436
tests/generic/445
tests/generic/448
tests/generic/490

index 5693ba3cad181e8c5e77c1746b81f66631c0ae0d..1fb6af4cc80c4f595d91ddb6647fd57831770520 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -2298,6 +2298,53 @@ _ext4_disable_extent_zeroout()
                echo 0 >/sys/fs/ext4/$sdev/extent_max_zeroout_kb
 }
 
                echo 0 >/sys/fs/ext4/$sdev/extent_max_zeroout_kb
 }
 
+# The default behavior of SEEK_HOLE is to always return EOF.
+# Filesystems that implement non-default behavior return the offset
+# of holes with SEEK_HOLE. There is no way to query the filesystem
+# of which behavior it is implementing.
+# We use this whitelist FSTYP, to set expectation and avoid silent
+# regression of filesystem seek hole behavior.
+#
+# Return 0 for true
+_fstyp_has_non_default_seek_data_hole()
+{
+       if [ -z $1 ]; then
+               local fstyp=$FSTYP
+       else
+               local fstyp=$1
+       fi
+
+       case "$fstyp" in
+       btrfs|ext4|xfs|ceph|cifs|f2fs|gfs2|nfs*|ocfs2|tmpfs)
+               return 0
+               ;;
+       overlay)
+               if [ ! -z $OVL_BASE_FSTYP -a $OVL_BASE_FSTYP != "overlay" ]; then
+                       _fstyp_has_non_default_seek_data_hole $OVL_BASE_FSTYP
+                       return $?
+               else
+                       # Assume that base fs has default behavior
+                       return 1
+               fi
+               ;;
+       *)
+               # by default fstyp has default SEEK_HOLE behavior;
+               # if your fs has non-default behavior, add it to whitelist above!
+               return 1
+               ;;
+       esac
+}
+
+# Run seek sanity test with predefined expectation for SEEK_DATA/HOLE behavior
+_run_seek_sanity_test()
+{
+       local testseekargs
+       if _fstyp_has_non_default_seek_data_hole; then
+               testseekargs+="-f"
+       fi
+       $here/src/seek_sanity_test $testseekargs $*
+}
+
 # Check if the file system supports seek_data/hole
 _require_seek_data_hole()
 {
 # Check if the file system supports seek_data/hole
 _require_seek_data_hole()
 {
index e9938d1b1a23a548731346506f9528f46e4da244..a6bda0b18139d85cef8671518ac7c7ef068a4f58 100644 (file)
@@ -23,6 +23,7 @@
 #endif
 
 static blksize_t alloc_size;
 #endif
 
 static blksize_t alloc_size;
+int allow_default_behavior = 1;
 int default_behavior = 0;
 int unwritten_extents = 0;
 char *base_file_path;
 int default_behavior = 0;
 int unwritten_extents = 0;
 char *base_file_path;
@@ -1119,6 +1120,12 @@ static int test_basic_support(void)
                fprintf(stderr, "File system supports the default behavior.\n");
        }
 
                fprintf(stderr, "File system supports the default behavior.\n");
        }
 
+       if (default_behavior && !allow_default_behavior) {
+               fprintf(stderr, "Default behavior is not allowed. Aborting.\n");
+               ret = -1;
+               goto out;
+       }
+
        ftruncate(fd, 0);
        if (fallocate(fd, 0, 0, alloc_size) == -1) {
                if (errno == EOPNOTSUPP)
        ftruncate(fd, 0);
        if (fallocate(fd, 0, 0, alloc_size) == -1) {
                if (errno == EOPNOTSUPP)
@@ -1148,7 +1155,7 @@ out:
 
 void usage(char *cmd)
 {
 
 void usage(char *cmd)
 {
-       fprintf(stdout, "Usage: %s [-t] [-s <starttest>] [-e <endtest>] base_file_path\n", cmd);
+       fprintf(stdout, "Usage: %s [-tf] [-s <starttest>] [-e <endtest>] base_file_path\n", cmd);
        exit(1);
 }
 
        exit(1);
 }
 
@@ -1169,11 +1176,14 @@ int main(int argc, char **argv)
        teststart = 1;
        testend = 12;
 
        teststart = 1;
        testend = 12;
 
-       while ((opt = getopt(argc, argv, "ts:e:")) != -1) {
+       while ((opt = getopt(argc, argv, "tfs:e:")) != -1) {
                switch (opt) {
                case 't':
                        check_support++;
                        break;
                switch (opt) {
                case 't':
                        check_support++;
                        break;
+               case 'f':
+                       allow_default_behavior = 0;
+                       break;
                case 's':
                        teststart = strtol(optarg, NULL, 10);
                        if (teststart <= 0 || teststart > numtests) {
                case 's':
                        teststart = strtol(optarg, NULL, 10);
                        if (teststart <= 0 || teststart > numtests) {
index b53b3accbc35adad5db0df6331bd4787dbfb3484..20e89e5b335fb2cf673cd87f609fb17108437d8f 100755 (executable)
@@ -37,7 +37,7 @@ _cleanup()
        eval "rm -f $BASE_TEST_FILE.*"
 }
 
        eval "rm -f $BASE_TEST_FILE.*"
 }
 
-$here/src/seek_sanity_test $BASE_TEST_FILE > $seqres.full 2>&1 ||
+_run_seek_sanity_test $BASE_TEST_FILE > $seqres.full 2>&1 ||
        _fail "seek sanity check failed!"
 
 # success, all done
        _fail "seek sanity check failed!"
 
 # success, all done
index a3ef70e54c87329b73fa17edee9fa737b8f50627..ada60b2e7afdaa73c4e9cb30435312df58ba3d9c 100755 (executable)
@@ -36,7 +36,7 @@ _cleanup()
        rm -f $tmp.* $BASE_TEST_FILE.*
 }
 
        rm -f $tmp.* $BASE_TEST_FILE.*
 }
 
-$here/src/seek_sanity_test -s 13 -e 16 $BASE_TEST_FILE > $seqres.full 2>&1 ||
+_run_seek_sanity_test -s 13 -e 16 $BASE_TEST_FILE > $seqres.full 2>&1 ||
        _fail "seek sanity check failed!"
 
 # success, all done
        _fail "seek sanity check failed!"
 
 # success, all done
index 694913aeb03b08c2eff82334bc7a68abe1bd696b..248f321b86013de08ef9c4ab97c0e38135e7e86a 100755 (executable)
@@ -36,7 +36,7 @@ _cleanup()
        rm -f $tmp.* $BASE_TEST_FILE.*
 }
 
        rm -f $tmp.* $BASE_TEST_FILE.*
 }
 
-$here/src/seek_sanity_test -s 17 -e 17 $BASE_TEST_FILE > $seqres.full 2>&1 ||
+_run_seek_sanity_test -s 17 -e 17 $BASE_TEST_FILE > $seqres.full 2>&1 ||
        _fail "seek sanity check failed!"
 
 # success, all done
        _fail "seek sanity check failed!"
 
 # success, all done
index d3ec5528ccfdd870b4ae848b0da55ca79cb6deeb..dada499b766fd0c36ef7120c50776dc2ca7edc19 100755 (executable)
@@ -34,7 +34,7 @@ BASE_TEST_FILE=$TEST_DIR/seek_sanity_testfile_$seq
 
 _require_test_program "seek_sanity_test"
 
 
 _require_test_program "seek_sanity_test"
 
-$here/src/seek_sanity_test -s 18 -e 18 $BASE_TEST_FILE > $seqres.full 2>&1 ||
+_run_seek_sanity_test -s 18 -e 18 $BASE_TEST_FILE > $seqres.full 2>&1 ||
        _fail "seek sanity check failed!"
 
 _check_dmesg
        _fail "seek sanity check failed!"
 
 _check_dmesg
index 330c2b60952b0f53d04e36d53eb80dba4395255c..07b08939dde211188e121a8340ace336e4d57c3c 100755 (executable)
@@ -39,7 +39,7 @@ _cleanup()
        rm -f $base_test_file*
 }
 
        rm -f $base_test_file*
 }
 
-$here/src/seek_sanity_test -s 19 -e 20 $base_test_file > $seqres.full 2>&1 ||
+_run_seek_sanity_test -s 19 -e 20 $base_test_file > $seqres.full 2>&1 ||
        _fail "seek sanity check failed!"
 
 # success, all done
        _fail "seek sanity check failed!"
 
 # success, all done