Re: [PATCH v3 1/5] btrfs: fix -o compress= level getting inherited by compression xattr property

Zygo Blaxell <[email protected]>
Newsgroups org.kernel.vger.linux-btrfs
Message-ID <[email protected]>
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 <[email protected]>
> Signed-off-by: koraynilay <[email protected]>
> ---
>  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.

>  	}
>  
>  	/* 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
> 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.