generic: add test for zero range over a file range with many small extents
authorFilipe Manana <fdmanana@suse.com>
Tue, 8 Sep 2020 10:32:02 +0000 (11:32 +0100)
committerEryu Guan <guaneryu@gmail.com>
Sun, 13 Sep 2020 16:19:01 +0000 (00:19 +0800)
Test a fallocate() zero range operation against a large file range for which
there are many small extents allocated. Verify the operation does not fail
and the respective range return zeroes on subsequent reads.

This test is motivated by a bug found on btrfs. The patch that fixes the
bug on btrfs has the following subject:

 "btrfs: fix metadata reservation for fallocate that leads to transaction aborts"

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/generic/610 [new file with mode: 0755]
tests/generic/610.out [new file with mode: 0644]
tests/generic/group

diff --git a/tests/generic/610 b/tests/generic/610
new file mode 100755 (executable)
index 0000000..0b9e732
--- /dev/null
@@ -0,0 +1,61 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
+#
+# FS QA Test No. 610
+#
+# Test a fallocate() zero range operation against a large file range for which
+# there are many small extents allocated. Verify the operation does not fail
+# and the respective range return zeroes on subsequent reads.
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+tmp=/tmp/$$
+status=1       # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_scratch
+_require_xfs_io_command "fzero"
+_require_xfs_io_command "fpunch"
+_require_test_program "punch-alternating"
+
+rm -f $seqres.full
+
+_scratch_mkfs >>$seqres.full 2>&1
+_scratch_mount
+
+# Create a file with many small extents. To speed up file creation, do
+# buffered writes and then punch a hole on every other block.
+$XFS_IO_PROG -f -c "pwrite -S 0xab -b 10M 0 100M" \
+       $SCRATCH_MNT/foobar >>$seqres.full
+$here/src/punch-alternating $SCRATCH_MNT/foobar >>$seqres.full
+
+# For btrfs, trigger a transaction commit to force metadata COW for the
+# following fallocate zero range operation.
+sync
+
+$XFS_IO_PROG -c "fzero 0 100M" $SCRATCH_MNT/foobar
+
+# Check the file content after umounting and mounting again the fs, to verify
+# everything was persisted.
+_scratch_cycle_mount
+
+echo "File content after zero range operation:"
+od -A d -t x1 $SCRATCH_MNT/foobar
+
+status=0
+exit
diff --git a/tests/generic/610.out b/tests/generic/610.out
new file mode 100644 (file)
index 0000000..96f8d13
--- /dev/null
@@ -0,0 +1,5 @@
+QA output created by 610
+File content after zero range operation:
+0000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+*
+104857600
index 2c704266f614339ef05a02e66302633d9cf97182..8eba6c9826df01860967e8ea7c5f59cda0b2f27f 100644 (file)
 607 auto attr quick dax
 608 auto attr quick dax
 609 auto quick rw
 607 auto attr quick dax
 608 auto attr quick dax
 609 auto quick rw
+610 auto quick prealloc zero