From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org, fstests@vger.kernel.org
Cc: Filipe Manana <fdmanana@suse.com>
Subject: [PATCH v2] fstests: btrfs: add a test case for failed compressed inline attempt
Date: Tue, 17 Feb 2026 07:59:24 +1030 [thread overview]
Message-ID: <20260216212924.34590-1-wqu@suse.com> (raw)
[BUG]
There is a long existing behavior that if a compressed inline attempt
failed, the whole inode is marked incompressible.
Furthermore, the default threshold for compressed inline implies a
pretty high compression ratio (2K max inline vs 4K block size, thus 50%
compression ratio).
This makes btrfs to mark inodes incompressible prematurely.
[TEST]
The new test case is based on the previous btrfs/343 one, which will do:
- Create and mount the fs with compress,max_inline=4
4 bytes will be too small for any header, thus all compressed inline
writes should fail.
- Do the following operations:
* Buffered write [0, blocksize / 2)
Which can be inlined if using the default max_inline mount option
and 4K fs block.
But the new max_inline=4 will reject such compressed inline attempt.
And such one block write should not trigger compression thus no
compression ratio based check.
* Sync
For unpatched kernels, this will set the inode with NOCOMPRESS flag
and reject all future compression on that inode.
* Buffered write [1M, 2M)
For unpatched kernels, the range will not be compressed due to the
NOCOMPRESS flag.
- Unmount the fs
- Maker sure that:
* The inode has no NOCOMPRESS flag
* File extent at file offset 1M is being compressed
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
Changelog:
v2:
- Minor grammar error fixes
---
tests/btrfs/344 | 53 +++++++++++++++++++++++++++++++++++++++++++++
tests/btrfs/344.out | 2 ++
2 files changed, 55 insertions(+)
create mode 100755 tests/btrfs/344
create mode 100644 tests/btrfs/344.out
diff --git a/tests/btrfs/344 b/tests/btrfs/344
new file mode 100755
index 00000000..4695104f
--- /dev/null
+++ b/tests/btrfs/344
@@ -0,0 +1,53 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 SUSE S.A. All Rights Reserved.
+#
+# FS QA Test 344
+#
+# Check if a failed inline attempt for compression write will mark
+# the whole inode as incompressible
+#
+. ./common/preamble
+_begin_fstest auto quick compress
+
+_require_scratch
+_require_btrfs_command inspect-internal dump-tree
+
+_fixed_by_kernel_commit xxxxxxxxxxxx \
+ "btrfs: do not mark inode incompressible after inline attempt failed"
+
+_scratch_mkfs >>$seqres.full 2>&1
+
+# This inline limit is too small for any header.
+# Thus all compressed inline attempt should fail.
+_scratch_mount "-o compress,max_inline=4"
+
+blocksize=$(_get_file_block_size $SCRATCH_MNT)
+
+# The initial half block write can be compressed, but the compressed
+# size will not meet the 4 bytes limits, thus it will not be inlined.
+#
+# Normally such single block write itself should not mark the inode
+# incompressible, no matter if there is an inline attempt or not.
+#
+# The 1M write should be compressed.
+$XFS_IO_PROG -f -c "pwrite 0 $(( $blocksize / 2 ))" -c sync \
+ -c "pwrite 1m 1m" $SCRATCH_MNT/foobar >> $seqres.full
+ino=$(stat -c "%i" $SCRATCH_MNT/foobar)
+_scratch_unmount
+
+# Dump the fs tree into seqres.full for debug.
+$BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV >> $seqres.full
+
+# Check the NOCOMPRESS flag of the inode.
+$BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV |\
+grep -A 4 -e "item .* key ($ino INODE_ITEM 0)" | grep -q NOCOMPRESS
+[ $? -eq 0 ] && echo "inode $ino has NOCOMPRESS flag"
+
+# Check the file extent at file offset 1m.
+$BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV |\
+grep -A 4 -e "item .* key ($ino EXTENT_DATA 1048576)" | grep -q "compression 0"
+[ $? -eq 0 ] && echo "inode $ino file offset 1M is not compressed"
+
+echo "Silence is golden"
+_exit 0
diff --git a/tests/btrfs/344.out b/tests/btrfs/344.out
new file mode 100644
index 00000000..b950d5ae
--- /dev/null
+++ b/tests/btrfs/344.out
@@ -0,0 +1,2 @@
+QA output created by 344
+Silence is golden
--
2.51.2
reply other threads:[~2026-02-16 21:29 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260216212924.34590-1-wqu@suse.com \
--to=wqu@suse.com \
--cc=fdmanana@suse.com \
--cc=fstests@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox