[PATCH 6/7] generic/331,xfs/240: support files that skip delayed allocation

Darrick J. Wong
2025-02-19T01:08:36Z

From: Darrick J. Wong <djwong@kernel.org>

The goal of this test is to ensure that log recovery finishes a copy on
write operation in the event of temporary media errors. It's important
that the test observe some sort of IO error once we switch the scratch
device to fail all IOs, but regrettably the test encoded the specific
behavior of XFS and btrfs when the test was written -- the aio write
to the page cache doesn't have to touch the disk and succeeds, and the
fdatasync flushes things to disk and hits the IO error.

However, this is not how things work on the XFS realtime device. There
is no delalloc on realtime when the rt extent size > 1 fsblock (or on
any file with extent size hints), so the aio write allocates an
unwritten extent to stage the write. The allocation fails due to EIO,
so it's the write call that fails. Therefore, all we need to do is to
detect an IO error at any point between the write and the fdatasync call
to be satisfied that the test does what we want to do.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
tests/generic/331 | 13 +++++++++++--
tests/generic/331.out | 2 +-
tests/xfs/240 | 12 ++++++++++--
tests/xfs/240.out | 2 +-
4 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/tests/generic/331 b/tests/generic/331
index 704bb1283ecb85..a079ba297c201b 100755
--- a/tests/generic/331
+++ b/tests/generic/331
@@ -58,10 +58,19 @@ echo "CoW and unmount"
$XFS_IO_PROG -f -c "pwrite -S 0x63 $bufsize 1" $testdir/file2 >> $seqres.full
$XFS_IO_PROG -f -c "pwrite -S 0x63 -b $bufsize 0 $filesize" $TEST_DIR/moo >> $seqres.full
_scratch_sync
+
+# If the filesystem supports delalloc, then the fdatasync will report an IO
+# error. If the write goes directly to disk, then aiocp will return nonzero.
+unset write_failed
_dmerror_load_error_table
-$AIO_TEST -b $bufsize $TEST_DIR/moo $testdir/file2 >> $seqres.full 2>&1
+$AIO_TEST -b $bufsize $TEST_DIR/moo $testdir/file2 >> $seqres.full 2>&1 || \
+ write_failed=1
$XFS_IO_PROG -c "fdatasync" $testdir/file2 |& \
- _filter_flakey_EIO "fdatasync: Input/output error"
+ _filter_flakey_EIO "fdatasync: Input/output error" | \
+ grep -q 'Input.output error' && \
+ write_failed=1
+test -n $write_failed && echo "write failed"
+
_dmerror_load_working_table
_dmerror_unmount
_dmerror_mount
diff --git a/tests/generic/331.out b/tests/generic/331.out
index adbf841d00c9d1..d8ccea704b8532 100644
--- a/tests/generic/331.out
+++ b/tests/generic/331.out
@@ -5,7 +5,7 @@ Compare files
1886e67cf8783e89ce6ddc5bb09a3944 SCRATCH_MNT/test-331/file1
1886e67cf8783e89ce6ddc5bb09a3944 SCRATCH_MNT/test-331/file2
CoW and unmount
-fdatasync: Input/output error
+write failed
Compare files
1886e67cf8783e89ce6ddc5bb09a3944 SCRATCH_MNT/test-331/file1
d94b0ab13385aba594411c174b1cc13c SCRATCH_MNT/test-331/file2
diff --git a/tests/xfs/240 b/tests/xfs/240
index 8916828a8c1958..6b26620f883378 100755
--- a/tests/xfs/240
+++ b/tests/xfs/240
@@ -64,9 +64,17 @@ $XFS_IO_PROG -f -c "pwrite -S 0x63 $bufsize 1" $testdir/file2 >> $seqres.full
$XFS_IO_PROG -f -c "pwrite -S 0x63 -b $bufsize 0 $filesize" $TEST_DIR/moo >> $seqres.full
_scratch_sync
_dmerror_load_error_table
-$AIO_TEST -b $bufsize $TEST_DIR/moo $testdir/file2 >> $seqres.full 2>&1
+# If the filesystem supports delalloc, then the fdatasync will report an IO
+# error. If the write goes directly to disk, then aiocp will return nonzero.
+unset write_failed
+$AIO_TEST -b $bufsize $TEST_DIR/moo $testdir/file2 >> $seqres.full 2>&1 || \
+ write_failed=1
$XFS_IO_PROG -c "fdatasync" $testdir/file2 |& \
- _filter_flakey_EIO "fdatasync: Input/output error"
+ _filter_flakey_EIO "fdatasync: Input/output error" | \
+ grep -q 'Input.output error' && \
+ write_failed=1
+test -n $write_failed && echo "write failed"
+
_dmerror_load_working_table
_dmerror_unmount
_dmerror_mount
diff --git a/tests/xfs/240.out b/tests/xfs/240.out
index 1a22e8a389ffda..00bb116e5c1613 100644
--- a/tests/xfs/240.out
+++ b/tests/xfs/240.out
@@ -5,7 +5,7 @@ Compare files
1886e67cf8783e89ce6ddc5bb09a3944 SCRATCH_MNT/test-240/file1
1886e67cf8783e89ce6ddc5bb09a3944 SCRATCH_MNT/test-240/file2
CoW and unmount
-fdatasync: Input/output error
+write failed
Compare files
1886e67cf8783e89ce6ddc5bb09a3944 SCRATCH_MNT/test-240/file1
d94b0ab13385aba594411c174b1cc13c SCRATCH_MNT/test-240/file2