seek_sanity_test: Repair check for unwritten extent support
authorAndreas Gruenbacher <agruenba@redhat.com>
Wed, 7 Aug 2019 11:25:14 +0000 (13:25 +0200)
committerEryu Guan <guaneryu@gmail.com>
Sun, 11 Aug 2019 14:27:12 +0000 (22:27 +0800)
In test_basic_support, commit f3c1bca7fb25 ("generic: Test that
SEEK_HOLE can find a punched hole") cleverly punched a hole in the test
file in the middle of the check for unwritten extent support, making
sure we would never detect when unwritten extent support is missing.
Fix that.

While at it, explicitly check for SEEK_DATA support as well:  so far, we
were assuming that SEEK_HOLE support implies SEEK_DATA support, but it
won't hurt to actually check.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
src/seek_sanity_test.c

index 30e996e2e6a7af63884450757915c8ed24674d4b..cb036f7bda87859e204f30b465726b770848287e 100644 (file)
@@ -1156,7 +1156,16 @@ static int test_basic_support(void)
        if (ret)
                goto out;
 
-       /* Is SEEK_DATA and SEEK_HOLE supported in the kernel? */
+       /* Is SEEK_DATA supported in the kernel? */
+       pos = lseek(fd, 0, SEEK_DATA);
+       if (pos == -1) {
+               fprintf(stderr, "Kernel does not support llseek(2) extension "
+                       "SEEK_DATA. Aborting.\n");
+               ret = -1;
+               goto out;
+       }
+
+       /* Is SEEK_HOLE supported in the kernel? */
        pos = lseek(fd, 0, SEEK_HOLE);
        if (pos == -1) {
                fprintf(stderr, "Kernel does not support llseek(2) extension "
@@ -1176,29 +1185,31 @@ static int test_basic_support(void)
                goto out;
        }
 
+       /* Is unwritten extent supported? */
        ftruncate(fd, 0);
        if (fallocate(fd, 0, 0, alloc_size * 2) == -1) {
-               if (errno == EOPNOTSUPP)
+               if (errno == EOPNOTSUPP) {
                        fprintf(stderr, "File system does not support fallocate.\n");
-               else {
+               else {
                        fprintf(stderr, "ERROR %d: Failed to preallocate "
                                "space to %ld bytes. Aborting.\n", errno, (long) alloc_size);
                        ret = -1;
                }
                goto out;
-       } else if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
-                            0, alloc_size) == -1) {
-               fprintf(stderr, "File system does not support punch hole.\n");
-       } else {
-               punch_hole = 1;
        }
 
        pos = lseek(fd, 0, SEEK_DATA);
-       if (pos == 0) {
+       if (pos == 0)
                fprintf(stderr, "File system does not support unwritten extents.\n");
-               goto out;
-       }
-       unwritten_extents = 1;
+       else
+               unwritten_extents = 1;
+
+       /* Is punch hole supported? */
+       if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
+                     0, alloc_size) == -1)
+               fprintf(stderr, "File system does not support punch hole.\n");
+       else
+               punch_hole = 1;
 
        printf("\n");