From: Andreas Gruenbacher Date: Wed, 7 Aug 2019 11:25:14 +0000 (+0200) Subject: seek_sanity_test: Repair check for unwritten extent support X-Git-Tag: v2022.05.01~1065 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=8adf5e71df15c92943b581211d3886dfae437a25;p=users%2Fhch%2Fxfstests-dev.git seek_sanity_test: Repair check for unwritten extent support 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 Reviewed-by: Eryu Guan Signed-off-by: Eryu Guan --- diff --git a/src/seek_sanity_test.c b/src/seek_sanity_test.c index 30e996e2e..cb036f7bd 100644 --- a/src/seek_sanity_test.c +++ b/src/seek_sanity_test.c @@ -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");