src/fiemap-tester: fix getting blocksize on overlayfs
authorAmir Goldstein <amir73il@gmail.com>
Thu, 11 Oct 2018 14:41:06 +0000 (17:41 +0300)
committerEryu Guan <guaneryu@gmail.com>
Sun, 14 Oct 2018 15:53:55 +0000 (23:53 +0800)
There was a regression in v4.19-rc1 that caused FIGETBSZ ioctl
to return 0 on an overlayfs file.

That regression went unnoticed because the xfstests that run
fiemap-tester program terminated in success status after not doing
much instead of failing.

Check for invalid value of block size returned by FIGETBSZ ioctl,
so these tests can detect the regression.

Fallback to statfs(2) for getting the filesystem blocksize if
FIGETBSZ ioctl fails (i.e. on overlayfs).

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
src/fiemap-tester.c

index 97ac5ad08d7a7550350fc283e55c7e6a39e48135..3db24daa792b0e7a6338adbc6626b3a4351c2552 100644 (file)
@@ -14,6 +14,7 @@
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/statfs.h>
 #include <sys/vfs.h>
 #include <linux/fs.h>
 #include <linux/types.h>
@@ -556,7 +557,19 @@ main(int argc, char **argv)
        }
 
        if (ioctl(fd, FIGETBSZ, &blocksize) < 0) {
-               perror("Can't get filesystem block size");
+               struct statfs buf;
+
+               if (fstatfs(fd, &buf) == 0) {
+                       blocksize = buf.f_bsize;
+               } else {
+                       perror("Can't get filesystem block size");
+                       close(fd);
+                       exit(1);
+               }
+       }
+
+       if (blocksize <= 0) {
+               printf("Illegal filesystem block size\n");
                close(fd);
                exit(1);
        }