From patchwork Tue Jan 23 05:05:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13526826 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9AB91FCC; Tue, 23 Jan 2024 05:06:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705986367; cv=none; b=l+nNYe9GM2i4W+BQ5X3eDUXMxCr/6VT7DAP8Bdzeb+MSi5D4nU11krwdgqnPdyzuhygG3MfutBjxZewuZV16QXaxBXQasyr2fo3YQDtp/iPPzW8KV2zZVNN9bGSBwnjmZH9j5bCWaEFlh2Fw0plFeubNA4aZLMSAYo6HKVBgClY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705986367; c=relaxed/simple; bh=PgCLPnx5f3O9X27rpqwdpRlF+oHUvDg28fBczZEWNeE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=e2sE5bTLDlqIsOQ7zxnX/hnKRYKiqw1foKmn9+kxBVcFC5elFBLJWFSVkqYtMlZshmEPQN724gK0i04lZVbOF3KdPKTyjj2FR8rQ93YAOzic1dl2FVWFbWVO5AAxdW3i4pRg/q87+3fCrR3jldssWVydTA39/xqenQT2/sMzZS4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=myErJ7Ad; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=kJWYTQyQ; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="myErJ7Ad"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="kJWYTQyQ" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E1B321F7A9; Tue, 23 Jan 2024 05:06:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1705986363; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Shn2i5q0+F3k0lsMXQ1tLtWyw5sKWMY2EUy1PVQKdLY=; b=myErJ7Adl96KJXhQcX8vDbQCWJFZaJ7vMTLOzweD8HWNrc7nZHGrxclgEWhlLJbF3fMQDF 2ZA7mvHwdfc/8lb4GXX+og+hwlccOmWGypZsIqxap1tBywdq6QORIco2F/jgV7TndtAe1a QQjqcZmF6cocUbdiSOf6BGSguBJEXhI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1705986362; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Shn2i5q0+F3k0lsMXQ1tLtWyw5sKWMY2EUy1PVQKdLY=; b=kJWYTQyQw51RsfWjdvIrNfjm5+4C6RUSqiOHi2CsIazCfsS1Oe940fEHpT+WDD4VdOmG5Z IkTjskuK+uWUKlmumJf2UxKGfqjECLlnbzn3ict9D/VvLV5A/WMusfVQ7qn/AV2jYRyEdj SPpc6YkmhZP+i86aRFITPJuibsKza6Y= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 9B771136A4; Tue, 23 Jan 2024 05:06:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id n/VBFzlJr2UNPgAAD6G6ig (envelope-from ); Tue, 23 Jan 2024 05:06:01 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH] fstests: btrfs: verify subpage reflinking of a compressed inline extent Date: Tue, 23 Jan 2024 15:35:43 +1030 Message-ID: <20240123050543.30741-1-wqu@suse.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: fstests@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: **** X-Spam-Score: 5.00 X-Spamd-Result: default: False [5.00 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_TWO(0.00)[2]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; NEURAL_SPAM_LONG(3.30)[0.942]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO [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 --- 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 --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=PtaH z9|{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sx`D<-YAj5zR12XJV zO+Nu836vyIl0ZrRCr@w!81|hQrUMoQeX>d%rzyS}>mpnq!>~vqdM-oJ__3j$rmQTHbk3%nk1<_>Sz>;7w_?D+_-+Fu;gbI8 zyO2=MyGB)fPMgb-M23hNfFg%f-ZHbka;6jcyFvYb zGj;m^?zZ5kN8JMw?Yk2Vpo8zE10Y~Pzy9SEnDGVdiXX5mI4{-M z=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)