]> www.infradead.org Git - users/hch/xfstests-dev.git/commitdiff
generic: add a partial pages zeroing out test
authorZhang Yi <yi.zhang@huawei.com>
Wed, 8 Jan 2025 08:44:07 +0000 (16:44 +0800)
committerZorro Lang <zlang@kernel.org>
Fri, 10 Jan 2025 04:44:03 +0000 (12:44 +0800)
This addresses a data corruption issue encountered during partial page
zeroing in ext4 which the block size is smaller than the page size [1].
Add a new test which is expanded upon generic/567, this test performs a
zeroing range test that spans two partial pages to cover this case, and
also generalize it to work for non-4k page sizes.

Link: https://lore.kernel.org/linux-ext4/20241220011637.1157197-2-yi.zhang@huaweicloud.com/
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
tests/generic/758 [new file with mode: 0755]
tests/generic/758.out [new file with mode: 0644]

diff --git a/tests/generic/758 b/tests/generic/758
new file mode 100755 (executable)
index 0000000..ad08b83
--- /dev/null
@@ -0,0 +1,68 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2024 Huawei.  All Rights Reserved.
+#
+# FS QA Test No. 758
+#
+# Test mapped writes against zero-range to ensure we get the data
+# correctly written. This can expose data corruption bugs on filesystems
+# where the block size is smaller than the page size.
+#
+# (generic/567 is a similar test but for punch hole.)
+#
+. ./common/preamble
+_begin_fstest auto quick rw zero
+
+# Import common functions.
+. ./common/filter
+
+_require_scratch
+_require_xfs_io_command "fzero"
+
+verifyfile=$SCRATCH_MNT/verifyfile
+testfile=$SCRATCH_MNT/testfile
+
+pagesz=$(_get_page_size)
+
+_scratch_mkfs >> $seqres.full 2>&1
+_scratch_mount
+
+_dump_files()
+{
+       echo "---- testfile ----"
+       _hexdump $testfile
+       echo "---- verifyfile --"
+       _hexdump $verifyfile
+}
+
+# Build verify file, the data in this file should be consistent with
+# that in the test file.
+$XFS_IO_PROG -f -c "pwrite -S 0x58 0 $((pagesz * 3))" \
+               -c "pwrite -S 0x59 $((pagesz / 2)) $((pagesz * 2))" \
+               $verifyfile | _filter_xfs_io >> $seqres.full
+
+# Zero out straddling two pages to check that the mapped write after the
+# range-zeroing are correctly handled.
+$XFS_IO_PROG -t -f \
+       -c "pwrite -S 0x58 0 $((pagesz * 3))" \
+       -c "mmap -rw 0 $((pagesz * 3))" \
+       -c "mwrite -S 0x5a $((pagesz / 2)) $((pagesz * 2))" \
+       -c "fzero $((pagesz / 2)) $((pagesz * 2))" \
+       -c "mwrite -S 0x59 $((pagesz / 2)) $((pagesz * 2))" \
+       -c "close"      \
+$testfile | _filter_xfs_io >> $seqres.full
+
+echo "==== Pre-Remount ==="
+if ! cmp -s $testfile $verifyfile; then
+       echo "Data does not match pre-remount."
+       _dump_files
+fi
+_scratch_cycle_mount
+echo "==== Post-Remount =="
+if ! cmp -s $testfile $verifyfile; then
+       echo "Data does not match post-remount."
+       _dump_files
+fi
+
+status=0
+exit
diff --git a/tests/generic/758.out b/tests/generic/758.out
new file mode 100644 (file)
index 0000000..d01c195
--- /dev/null
@@ -0,0 +1,3 @@
+QA output created by 758
+==== Pre-Remount ===
+==== Post-Remount ==