aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Foster <bfoster@redhat.com>2021-12-17 12:18:26 -0500
committerEryu Guan <guaneryu@gmail.com>2021-12-19 23:18:16 +0800
commit0d04edb16471eac30e28f00bffd493e0eaf032eb (patch)
treec5b709d5133cf68e758e4ac75d089365a8c09e86
parent90d132ee44b76350e4aebd36b7598d425b25c996 (diff)
downloadxfstests-dev-0d04edb16471eac30e28f00bffd493e0eaf032eb.tar.gz
xfs: test COW writeback failure when overlapping non-shared blocks
Test that COW writeback that overlaps non-shared delalloc blocks does not leave around stale delalloc blocks on I/O failure. This triggers assert failures and free space accounting corruption on XFS. Fixed by upstream kernel commit 5ca5916b6bc9 ("xfs: punch out data fork delalloc blocks on COW writeback failure"). Signed-off-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Eryu Guan <guaneryu@gmail.com>
-rwxr-xr-xtests/xfs/54267
-rw-r--r--tests/xfs/542.out2
2 files changed, 69 insertions, 0 deletions
diff --git a/tests/xfs/542 b/tests/xfs/542
new file mode 100755
index 0000000000..5c45eed7cd
--- /dev/null
+++ b/tests/xfs/542
@@ -0,0 +1,67 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2021 Red Hat, Inc. All Rights Reserved.
+#
+# FS QA Test 542
+#
+# Test that COW writeback that overlaps non-shared delalloc blocks does not
+# leave around stale delalloc blocks on I/O failure. This triggers assert
+# failures and free space accounting corruption on XFS. Fixed by upstream kernel
+# commit 5ca5916b6bc9 ("xfs: punch out data fork delalloc blocks on COW
+# writeback failure").
+#
+. ./common/preamble
+_begin_fstest auto quick clone
+
+_cleanup()
+{
+ _cleanup_flakey
+ cd /
+ rm -r -f $tmp.*
+}
+
+# Import common functions.
+. ./common/reflink
+. ./common/dmflakey
+
+# real QA test starts here
+_supported_fs xfs
+_require_scratch_reflink
+_require_cp_reflink
+_require_xfs_io_command "cowextsize"
+_require_flakey_with_error_writes
+
+_scratch_mkfs >> $seqres.full
+_init_flakey
+_mount_flakey
+
+blksz=$(_get_file_block_size $SCRATCH_MNT)
+
+# Set the COW extent size hint to guarantee COW fork preallocation occurs over a
+# bordering block offset.
+$XFS_IO_PROG -c "cowextsize $((blksz * 2))" $SCRATCH_MNT >> $seqres.full
+
+# create two files that share a single block
+$XFS_IO_PROG -fc "pwrite $blksz $blksz" $SCRATCH_MNT/file1 >> $seqres.full
+$XFS_IO_PROG -fc "reflink $SCRATCH_MNT/file1" \
+ -c fsync $SCRATCH_MNT/file2 >> $seqres.full
+
+# Perform a buffered write across the shared and non-shared blocks. On XFS, this
+# creates a COW fork extent that covers the shared block as well as the just
+# created non-shared delalloc block. Fail the writeback to verify that all
+# delayed allocation is cleaned up properly.
+_load_flakey_table $FLAKEY_ERROR_WRITES
+len=$((blksz * 2))
+$XFS_IO_PROG -c "pwrite 0 $len" \
+ -c "sync_range -w 0 $len" \
+ -c "sync_range -a 0 $len" $SCRATCH_MNT/file2 >> $seqres.full
+_load_flakey_table $FLAKEY_ALLOW_WRITES
+
+# Try a post-fail reflink and then unmount. Both of these are known to produce
+# errors and/or assert failures on XFS if we trip over a stale delalloc block.
+_cp_reflink $SCRATCH_MNT/file2 $SCRATCH_MNT/file3
+_unmount_flakey
+
+# success, all done
+status=0
+exit
diff --git a/tests/xfs/542.out b/tests/xfs/542.out
new file mode 100644
index 0000000000..0a0fbd524b
--- /dev/null
+++ b/tests/xfs/542.out
@@ -0,0 +1,2 @@
+QA output created by 542
+sync_file_range: Input/output error