summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2022-12-20 16:22:02 -0800
committerZorro Lang <zlang@kernel.org>2022-12-25 21:25:45 +0800
commit56c8f841407c29808d370d06929a3f58c7afeee3 (patch)
tree03a8f9af8da0371b033a5c52a5916b02fb5d4348
parent5f291f3c9a846a14547444d9d71d0cfe5c2f9a71 (diff)
xfs/179: modify test to trigger refcount update bugs
Upon enabling fsdax + reflink for XFS, this test began to report refcount metadata corruptions after being run. Specifically, xfs_repair noticed single-block refcount records that could be combined but had not been. The root cause of this is improper MAXREFCOUNT edge case handling in xfs_refcount_merge_extents. When we're trying to find candidates for a record merge, we compute the refcount of the merged record, but without accounting for the fact that once a record hits rc_refcount == MAXREFCOUNT, it is pinned that way forever. Adjust this test to use a sub-filesize write for one of the COW writes, because this is how we force the extent merge code to run. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Zorro Lang <zlang@kernel.org>
-rwxr-xr-xtests/xfs/17932
1 files changed, 29 insertions, 3 deletions
diff --git a/tests/xfs/179 b/tests/xfs/179
index ec0cb7e5..98b01476 100755
--- a/tests/xfs/179
+++ b/tests/xfs/179
@@ -21,17 +21,29 @@ _require_scratch_nocheck
_require_cp_reflink
_require_test_program "punch-alternating"
+_fixed_by_kernel_commit b25d1984aa88 \
+ "xfs: estimate post-merge refcounts correctly"
+
echo "Format and mount"
_scratch_mkfs -d agcount=1 > $seqres.full 2>&1
_scratch_mount >> $seqres.full 2>&1
+# This test modifies the refcount btree on the data device, so we must force
+# rtinherit off so that the test files are created there.
+_xfs_force_bdev data $SCRATCH_MNT
+
testdir=$SCRATCH_MNT/test-$seq
mkdir $testdir
+# Set the file size to 10x the block size to guarantee that the COW writes will
+# touch multiple blocks and exercise the refcount extent merging code. This is
+# necessary to catch a bug in the refcount extent merging code that handles
+# MAXREFCOUNT edge cases.
blksz=65536
+filesz=$((blksz * 10))
echo "Create original files"
-_pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
+_pwrite_byte 0x61 0 $filesz $testdir/file1 >> $seqres.full
_cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
echo "Change reference count"
@@ -56,9 +68,23 @@ _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
_scratch_mount >> $seqres.full
echo "CoW a couple files"
-_pwrite_byte 0x62 0 $blksz $testdir/file3 >> $seqres.full
-_pwrite_byte 0x62 0 $blksz $testdir/file5 >> $seqres.full
+_pwrite_byte 0x62 0 $filesz $testdir/file3 >> $seqres.full
+_pwrite_byte 0x62 0 $filesz $testdir/file5 >> $seqres.full
+
+# For the last COW test, write single blocks at the start, middle, and end of
+# the shared file to exercise a refcount btree update that targets a single
+# block of the multiblock refcount record that we just modified.
+#
+# This trips a bug where XFS didn't correctly identify refcount record merge
+# candidates when any of the records are pinned at MAXREFCOUNT. The bug was
+# originally discovered by enabling fsdax + reflink, but the bug can be
+# triggered by any COW that doesn't target the entire extent.
+#
+# The bug was fixed by kernel commit b25d1984aa88 ("xfs: estimate post-merge
+# refcounts correctly")
_pwrite_byte 0x62 0 $blksz $testdir/file7 >> $seqres.full
+_pwrite_byte 0x62 $((blksz * 4)) $blksz $testdir/file7 >> $seqres.full
+_pwrite_byte 0x62 $((filesz - blksz)) $blksz $testdir/file7 >> $seqres.full
echo "Check scratch fs"
_scratch_unmount