From: Qu Wenruo <wqu@suse.com>
To: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>,
koraynilay <koray.fra@gmail.com>
Cc: Chris Mason <clm@fb.com>, David Sterba <dsterba@suse.com>,
linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v3 1/5] btrfs: fix -o compress= level getting inherited by compression xattr property
Date: Mon, 10 Aug 2026 07:46:43 +0930 [thread overview]
Message-ID: <60592a20-9280-49a2-ba92-a51f8616b4e3@suse.com> (raw)
In-Reply-To: <anjf71ZUXUC4dd1W@hungrycats.org>
在 2026/8/10 05:45, Zygo Blaxell 写道:
> On Sun, Aug 09, 2026 at 08:52:59PM +0200, koraynilay wrote:
>> When setting the btrfs.compression xattr, btrfs uses the mount option level
>> (since levels in the xattr aren't supported yet) to compress the data, even
>> if the compression algorithm between the property and the compress= option
>> are different (!!).
>> For example, when mounting with compress=zstd:15 and setting
>> btrfs.compression=zlib, the data would get compressed at zlib:9, because
>> btrfs would take "zlib" from the xattr but "15" from the mount option,
>> which would then get correctly clamped at 9.
>>
>> To fix, just hard-code the compress level at 0, forcing the property's
>> algorithm default.
>>
>> Reported-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
>> Signed-off-by: koraynilay <koray.fra@gmail.com>
>> ---
>> fs/btrfs/inode.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
>> index 2534cd9284d5..6d7f2aa2555c 100644
>> --- a/fs/btrfs/inode.c
>> +++ b/fs/btrfs/inode.c
>> @@ -938,6 +938,7 @@ static void compress_file_range(struct btrfs_work *work)
>> compress_level = inode->defrag_compress_level;
>> } else if (inode->prop_compress) {
>> compress_type = inode->prop_compress;
>> + compress_level = 0;
>
> This set to zero should be conditional on inode->prop_compress !=
> fs_info->compress_type; otherwise, it prevents the compress-level mount
> option from working in the common case where 'btrfs.compression=zstd'
> or 'chattr +c' has been set.
No, read this discussion.
https://lore.kernel.org/linux-btrfs/DKK0XWCI89MM.2G6KD41GSR46J@gmail.com/T/#m79e6c1ecbcc61ebb57dca5cbb3eceabd052ecdbc
>
>> }
>>
>> /* Compression level is applied here. */
>> @@ -2326,6 +2327,7 @@ static int run_delalloc_inline(struct btrfs_inode *inode, struct folio *locked_f
>> compress_level = inode->defrag_compress_level;
>> } else if (inode->prop_compress) {
>> compress_type = inode->prop_compress;
>> + compress_level = 0;
>> }
>> cb = btrfs_compress_bio(inode, 0, blocksize, compress_type, compress_level, 0);
>> if (IS_ERR(cb)) {
>> --
>> 2.55.0
>>
>>
next prev parent reply other threads:[~2026-08-09 22:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-09 18:52 [PATCH v3 0/5] btrfs: add per-inode compression levels in xattrs koraynilay
2026-08-09 18:52 ` [PATCH v3 1/5] btrfs: fix -o compress= level getting inherited by compression xattr property koraynilay
2026-08-09 20:15 ` Zygo Blaxell
2026-08-09 22:16 ` Qu Wenruo [this message]
2026-08-09 18:53 ` [PATCH v3 2/5] btrfs: export btrfs_match_compress_type(), move it to compression.h koraynilay
2026-08-09 18:53 ` [PATCH v3 3/5] btrfs: also validate compression levels in btrfs_compress_is_valid_type() koraynilay
2026-08-09 18:53 ` [PATCH v3 4/5] btrfs: add per-inode compression levels in xattrs koraynilay
2026-08-09 18:53 ` [PATCH v3 5/5] btrfs: support inheritance for per-inode compression levels koraynilay
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=60592a20-9280-49a2-ba92-a51f8616b4e3@suse.com \
--to=wqu@suse.com \
--cc=ce3g8jdj@umail.furryterror.org \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=koray.fra@gmail.com \
--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