Whamcloud - gitweb
LU-14324 tests: Fix fsx fallocate detection 02/41202/5
authorOleg Drokin <green@whamcloud.com>
Mon, 11 Jan 2021 23:57:40 +0000 (18:57 -0500)
committerOleg Drokin <green@whamcloud.com>
Tue, 12 Jan 2021 15:04:45 +0000 (15:04 +0000)
Avoid kernel playing fake tricks on us by optimizing away small
increases in file size by fallocate, so to ensure the truth make
large fallocate call instead.
Additionally always truncate to zero after all call, as even a
failed call can result in increased file size.

Test-Parameters: trivial testlist=sanity env=ONLY=150
Test-Parameters: testlist=sanityn env=ONLY=16,COUNT=10000
Test-Parameters: testlist=sanity-dom env=ONLY=fsx,sanityn,SANITYN_ONLY=16
Test-Parameters: fstype=zfs testlist=sanity env=ONLY=150
Test-Parameters: fstype=zfs testlist=sanityn env=ONLY=16,COUNT=10000
Test-Parameters: fstype=zfs testlist=sanity-dom env=ONLY=fsx,sanityn,SANITYN_ONLY=16
Change-Id: I8cddb7d0d30bdf89bf13d18ae36a5f950adc392d
Fixes: 03247bda765c ("LU-14286 osd-ldiskfs: fallocate() should zero new blocks")
Signed-off-by: Oleg Drokin <green@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/41202
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/tests/fsx.c

index 2f765c0..66e1de5 100644 (file)
@@ -1526,7 +1526,8 @@ test_fallocate(int mode)
        int fd = get_fd();
 
        if (!lite) {
-               if (fallocate(fd, mode, 0, 1) && errno == EOPNOTSUPP) {
+               /* Must go more than a page away so let's go 4M to be sure */
+               if (fallocate(fd, mode, 0, 4096*1024) && errno == EOPNOTSUPP) {
                        if (!quiet)
                                warn("%s: filesystem does not support fallocate mode 0x%x, disabling!",
                                     __func__, mode);
@@ -1534,8 +1535,10 @@ test_fallocate(int mode)
                        ret = 1;
                }
 
-               /* Call truncate only when fallocate succeeds */
-               if (ret == 1 && ftruncate(fd, 0) == -1)
+               /* Always call ftruncate since file size might be adjusted
+                * by fallocate even on error
+                */
+               if (ftruncate(fd, 0) == -1)
                        warn("ftruncate to 0 size failed");
        }
        return ret;