fstests: btrfs: verify subpage reflinking of a compressed inline extent
PATCH 1/1 fstests: btrfs: verify subpage reflinking of a compressed inline extent
[BUG]
Although subpage btrfs can not yet create a compressed inline file extent (we support compressed file extent, but not inlined due to other limits), subpage btrfs should still read the compressed inline content correctly.
Two routines are involved for such read:
- Regular page read
- Reflinking an compressed inlined extent to non-zero file offset This would decompress the extent and fill the page cache.
The latter part turns out to be buggy from the introduction of compression.
The interface is not handling subpage correctly, and can lead to -EIO when doing reflinks if the target offset is not page aligned but only sector aligned.
The fixes have arrived in v6.8-rc1.
[CAUSE]
The root cause is the bad page offset handling in various decompression path.
[TEST CASE]
Since subpage btrfs can not create inline extent due to other limits, we have to break the no-binary requirement.
This time we would create an xz compressed image, which contains a 4K sector sized btrfs, and it contains a file with one compressed inline extent.
The test case would:
- Use that binary dump to fill SCRATCH_DEV
- Verify we can read the file correctly
- Verify we can reflink the compressed inline extent correctly
- Verify the content of the reflinked file is correct
This has been tested on an aarch64 system with 64K page size. For common x86_64, the test case would just be skipped.
The biggest concern here is, whether a binary image dump is allowed for fstests, especially the scenario (subpage btrfs) doesn't have the way to create inlined extents, but we still want to verify the read behavior.
--- tests/btrfs/311 | 73 +++++++++++++++++++++++++++++++++++++++++ tests/btrfs/311.img.xz | Bin 0 -> 22368 bytes tests/btrfs/311.out | 3 ++ 3 files changed, 76 insertions(+) create mode 100755 tests/btrfs/311 create mode 100644 tests/btrfs/311.img.xz create mode 100644 tests/btrfs/311.out
tests/btrfs/311 new file +73 -0
@@ -0,0 +1,73 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2024 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 311 +# +# Make sure subpage btrfs can reflink a compressed inline extent to +# an non-page aligned but sector aligned file offset +# +. ./common/preamble +_begin_fstest auto quick clone compress + +. ./common/filter + +_require_command "$XZ_PROG" xz +_supported_fs btrfs +_require_scratch + +_fixed_by_kernel_commit 2c25716dcc25 \ + "btrfs: zlib: fix and simplify the inline extent decompression" + +# This test requires subpage (sectorsize < PAGE_SIZE) btrfs, and a compressed +# inline file extent, which is not yet possible to create under subpage btrfs. +# +# So here we have to use binary dump of a 4k sector sized btrfs here. +pagesize=$(_get_page_size) +if [ "$pagesize" -le "4096" ]; then + _notrun "This test case requires page size > 4096, got $pagesize" +fi + +testcase="$0" +if [ ! -f $testcase.img.xz ]; then + _fail "No binary image found" +fi + +# Extra the binary dump to $SCRATCH_DEV +$XZ_PROG --decompress --stdout $testcase.img.xz > $tmp.img +dd if=$tmp.img of=$SCRATCH_DEV bs=1M status=none +rm -f -- $tmp.img + +_scratch_mount + +# The correct md5 for the 4K file filled with "0xcd" +md5sum_inline="5fed275e7617a806f94c173746a2a723" + +# The correct md5 for the 64K file with 60K hole then a 4K filled with "0xcd". +md5sum_reflink="2fd82541f4790ea9730cd8b6c0f2fd9a" + +# Even subpage can not create compressed inline extents, read should happen without +# any problem. +result=$(_md5_checksum "$SCRATCH_MNT/inline") +echo "initial read, md5sum=${result}" >> $seqres.full +if [ "$result" != "$md5sum_inline" ]; then + _fail "initial read got incorrect content" +fi + +# Now we reflink the compressed inline extent to an non-zero offset, +# this would require us to decompress the content, and create a regular extent. +# +# For unpatched kernel, this would lead to an -EIO error. +$XFS_IO_PROG -f -c "reflink $SCRATCH_MNT/inline 0 60k 4k" $SCRATCH_MNT/reflink | _filter_xfs_io + +# Make sure the reflinked file (which contains the decompressed contents) is correct. +result=$(_md5_checksum "$SCRATCH_MNT/reflink") +if [ "$result" != "$md5sum_reflink" ]; then + _fail "reflinked file has incorrect content" +fi + +_scratch_unmount + +# success, all done +status=0 +exit
tests/btrfs/311.img.xz new file binary +0 -0
tests/btrfs/311.out new file +3 -0
@@ -0,0 +1,3 @@ +QA output created by 311 +linked 4096/4096 bytes at offset 61440 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
Signature · 1 line
2.43.0