Commit c49dda7254 for qemu.org

commit c49dda7254d43d9e1d4da59c55f02055ba7c4c1b
Author: Eric Blake <eblake@redhat.com>
Date:   Fri May 23 11:27:23 2025 -0500

    iotests: Filter out ZFS in several tests

    Fiona reported that ZFS makes sparse file testing awkward, since:
    - it has asynchronous allocation (not even 'fsync $file' makes du see
      the desired size; it takes the slower 'fsync -f $file' which is not
      appropriate for the tests)
    - for tests of fully allocated files, ZFS with compression enabled
      still reports smaller disk usage

    Add a new _require_disk_usage that quickly probes whether an attempt
    to create a sparse 5M file shows as less than 1M usage, while the same
    file with -o preallocation=full shows as more than 4M usage without
    sync, which should filter out ZFS behavior.  Then use it in various
    affected tests.

    This does not add the new filter on all tests that Fiona is seeing ZFS
    failures on, but only those where I could quickly spot that there is
    at least one place where the test depends on the output of 'du -b' or
    'stat -c %b'.

    Reported-by: Fiona Ebner <f.ebner@proxmox.com>
    Signed-off-by: Eric Blake <eblake@redhat.com>
    Message-ID: <20250523163041.2548675-8-eblake@redhat.com>
    Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
    Tested-by: Fiona Ebner <f.ebner@proxmox.com>

diff --git a/tests/qemu-iotests/106 b/tests/qemu-iotests/106
index ae0fc46691..55548439aa 100755
--- a/tests/qemu-iotests/106
+++ b/tests/qemu-iotests/106
@@ -40,6 +40,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 _supported_fmt raw
 _supported_proto file fuse
 _supported_os Linux
+_require_disk_usage

 # in kB
 CREATION_SIZE=128
diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175
index f74f053b71..bbbf550a5a 100755
--- a/tests/qemu-iotests/175
+++ b/tests/qemu-iotests/175
@@ -77,6 +77,7 @@ _supported_os Linux

 _default_cache_mode none
 _supported_cache_modes none directsync
+_require_disk_usage

 size=$((1 * 1024 * 1024))

diff --git a/tests/qemu-iotests/221 b/tests/qemu-iotests/221
index c463fd4b11..eba00b80ad 100755
--- a/tests/qemu-iotests/221
+++ b/tests/qemu-iotests/221
@@ -41,6 +41,7 @@ _supported_os Linux

 _default_cache_mode writeback
 _supported_cache_modes writeback writethrough unsafe
+_require_disk_usage

 echo
 echo "=== Check mapping of unaligned raw image ==="
diff --git a/tests/qemu-iotests/253 b/tests/qemu-iotests/253
index 35039d20a8..6da85e6a11 100755
--- a/tests/qemu-iotests/253
+++ b/tests/qemu-iotests/253
@@ -41,6 +41,7 @@ _supported_os Linux

 _default_cache_mode none
 _supported_cache_modes none directsync
+_require_disk_usage

 echo
 echo "=== Check mapping of unaligned raw image ==="
diff --git a/tests/qemu-iotests/308 b/tests/qemu-iotests/308
index 437a9014da..6eced3aefb 100755
--- a/tests/qemu-iotests/308
+++ b/tests/qemu-iotests/308
@@ -51,6 +51,7 @@ _unsupported_fmt vpc

 _supported_proto file # We create the FUSE export manually
 _supported_os Linux # We need /dev/urandom
+_require_disk_usage

 # $1: Export ID
 # $2: Options (beyond the node-name and ID)
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
index 237f746af8..e977cb4eb6 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -996,6 +996,36 @@ _require_large_file()
     rm "$FILENAME"
 }

+# Check whether disk_usage can be reliably used.
+_require_disk_usage()
+{
+    local unusable=false
+    # ZFS triggers known failures on this front; it does not immediately
+    # allocate files, and then aggressively compresses writes even when full
+    # allocation was requested.
+    if [ -z "$TEST_IMG_FILE" ]; then
+        FILENAME="$TEST_IMG"
+    else
+        FILENAME="$TEST_IMG_FILE"
+    fi
+    if [ -e "FILENAME" ]; then
+        echo "unwilling to overwrite existing file"
+        exit 1
+    fi
+    $QEMU_IMG create -f raw "$FILENAME" 5M > /dev/null
+    if [ $(disk_usage "$FILENAME") -gt $((1024*1024)) ]; then
+        unusable=true
+    fi
+    $QEMU_IMG create -f raw -o preallocation=full "$FILENAME" 5M > /dev/null
+    if [ $(disk_usage "$FILENAME") -lt $((4*1024*1024)) ]; then
+        unusable=true
+    fi
+    rm -f "$FILENAME"
+    if $unusable; then
+        _notrun "file system on $TEST_DIR does not handle sparse files nicely"
+    fi
+}
+
 # Check that a set of devices is available in the QEMU binary
 #
 _require_devices()
diff --git a/tests/qemu-iotests/tests/mirror-sparse b/tests/qemu-iotests/tests/mirror-sparse
index 11418c0871..cfcaa600ab 100755
--- a/tests/qemu-iotests/tests/mirror-sparse
+++ b/tests/qemu-iotests/tests/mirror-sparse
@@ -40,6 +40,7 @@ cd ..
 _supported_fmt qcow2 raw  # Format of the source. dst is always raw file
 _supported_proto file
 _supported_os Linux
+_require_disk_usage

 echo
 echo "=== Initial image setup ==="
diff --git a/tests/qemu-iotests/tests/write-zeroes-unmap b/tests/qemu-iotests/tests/write-zeroes-unmap
index 7cfeeaf839..f90fb8e8d2 100755
--- a/tests/qemu-iotests/tests/write-zeroes-unmap
+++ b/tests/qemu-iotests/tests/write-zeroes-unmap
@@ -32,6 +32,7 @@ cd ..
 _supported_fmt raw
 _supported_proto file
 _supported_os Linux
+_require_disk_usage

 create_test_image() {
     _make_test_img -f $IMGFMT 1m