diff mbox series

fstests: btrfs: verify subpage reflinking of a compressed inline extent

Message ID 20240123050543.30741-1-wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series fstests: btrfs: verify subpage reflinking of a compressed inline extent | expand

Commit Message

Qu Wenruo Jan. 23, 2024, 5:05 a.m. UTC
[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.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 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
diff mbox series

Patch

diff --git a/tests/btrfs/311 b/tests/btrfs/311
new file mode 100755
index 00000000..b8c9463b
--- /dev/null
+++ b/tests/btrfs/311
@@ -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
diff --git a/tests/btrfs/311.img.xz b/tests/btrfs/311.img.xz
new file mode 100644
index 0000000000000000000000000000000000000000..ccb8fc1b8da5868f374df1c01ea480715a60b262
GIT binary patch
literal 22368
zcmeHPbx>9P);@<$0S||e5;(LpiimVe9Xh0?OH!qek|M2?beACT(k%^#R=Pt<Bm|{7
z_x-**bLabR&8wsHa_8=U_w1S9%-U-`&$FJre(PM&Q&%4Z!dM-vkVOO0gQ-Cv5b>aH
z9|{$WQDg`LJv>LDvZ_&XqViA|Ayc)Q7}nLSAnfDq720R-xjXLM1uK^M_JoEib7v7w
z`sFT%F_LI3=uvdIhb}!ns(R%|VB0e1reJQ6Svu8e!v2u5SEbFF8NNGTVhWG`+Q}Lt
z`}It@kE4J7X?fY%%;)I4;^gyB<SYYH;_Pgad{V=<1?Exd6I>H&FQCkO?(FcqI?q}2
zh!ou8uWfG0^2E(BzvNWcH!nW5ZE>=9drF;flG@9~`qxMdO*CyfKDY6C<mlKTdtr7(
zSxK!K3Kf9|o;rLzNCQ(?@q18-ePWTuWM(CbKf|f%?V+sO;h$rVFbi<C?tY!v=OEyX
z?R1Qrl_tx}rH_rCy!IhOwmHJb`3zP9BctVhCe<Ip=yZhmGF_+O5KsBJYp7T7>8@qu
zOj$W3b_X&1wEbOmu`jN_&C)Urq9cG1Yqpy{d)Tc!*w<Os8HW+<0MQXprA=!p@#ejj
zRvpgk=#-krXuQRW3>=P42=!%;{=(vZNZEpwpqy|%@pd$dsGUjU=xg*XUd)`*?T7E2
zl;sG9qe%*jO=#){%2+52^nx}l)peUT9=*|9`FI}_=eTRC`0P}j!!0x7;0jtZws5d}
z_eY;$A@t86W8FZs76|_bL>yOo64fWfz*3>D1O|MZdalWv-IP0X2gh9Jg*c~`Kf0-x
zl7|2{yzb@^hM(Z1^5kg}s!lt4A=g55zW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uq42e|5Yq`1GMGVqTT<}isY}$Bz_77|B3AX>y9SEnDGVdiXX5mI4{-M
z=<BFA*`f<}kh+2L?rtVUVxC`PZvBzPE&o_+v%6n_9T(rTUIP&OfY=A_%>M22%;i}-
z1GJMsI|;OtKsyPvlmAuiB(R+A5AKBngexFi0pWV-geyX@4}=Zca`9{7zq0WAnp{w0
l*!`x|KGt>+xUvL{Kp@0_e^yOK9YIPi%!B?vFJS2D{{`$K?8*QD

literal 0
HcmV?d00001

diff --git a/tests/btrfs/311.out b/tests/btrfs/311.out
new file mode 100644
index 00000000..87a66bc4
--- /dev/null
+++ b/tests/btrfs/311.out
@@ -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)