[PATCH v3 1/5] btrfs: fix -o compress= level getting inherited by compression xattr property
koraynilay <[email protected]>
| Newsgroups | org.kernel.vger.linux-btrfs |
|---|---|
| Message-ID | <[email protected]> |
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; } /* 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