From 8adf5e71df15c92943b581211d3886dfae437a25 Mon Sep 17 00:00:00 2001 From: Andreas Gruenbacher Date: Wed, 7 Aug 2019 13:25:14 +0200 Subject: [PATCH] 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 --- src/seek_sanity_test.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/seek_sanity_test.c b/src/seek_sanity_test.c index 30e996e2..cb036f7b 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"); -- 2.39.5