Skip to content

Commit 4e8beae

Browse files
jcalvinowenskdave
authored andcommitted
btrfs: accept and ignore compression level for lzo
The compression level is meaningless for lzo, but before commit 3f093cc ("btrfs: harden parsing of compression mount options"), it was silently ignored if passed. After that commit, passing a level with lzo fails to mount: BTRFS error: unrecognized compression value lzo:1 It seems reasonable for users to expect that lzo would permit a numeric level option, as all the other algos do, even though the kernel's implementation of LZO currently only supports a single level. Because it has always worked to pass a level, it seems likely to me that users in the real world are relying on doing so. This patch restores the old behavior, giving "lzo:N" the same semantics as all of the other compression algos. To be clear, silly variants like "lzo:one", "lzo:the_first_option", or "lzo:armageddon" also used to work. This isn't meant to suggest that any possible mis-interpretation of mount options that once worked must continue to work forever. This is an exceptional case where it makes sense to preserve compatibility, both because the mis-interpretation is reasonable, and because nothing tangible is sacrificed. Fixes: 3f093cc ("btrfs: harden parsing of compression mount options") Reviewed-by: Daniel Vacek <[email protected]> Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Calvin Owens <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent c920f3f commit 4e8beae

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/btrfs/super.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,12 @@ static int btrfs_parse_compress(struct btrfs_fs_context *ctx,
297297
btrfs_set_opt(ctx->mount_opt, COMPRESS);
298298
btrfs_clear_opt(ctx->mount_opt, NODATACOW);
299299
btrfs_clear_opt(ctx->mount_opt, NODATASUM);
300-
} else if (btrfs_match_compress_type(string, "lzo", false)) {
300+
} else if (btrfs_match_compress_type(string, "lzo", true)) {
301301
ctx->compress_type = BTRFS_COMPRESS_LZO;
302-
ctx->compress_level = 0;
302+
ctx->compress_level = btrfs_compress_str2level(BTRFS_COMPRESS_LZO,
303+
string + 3);
304+
if (string[3] == ':' && string[4])
305+
btrfs_warn(NULL, "Compression level ignored for LZO");
303306
btrfs_set_opt(ctx->mount_opt, COMPRESS);
304307
btrfs_clear_opt(ctx->mount_opt, NODATACOW);
305308
btrfs_clear_opt(ctx->mount_opt, NODATASUM);

0 commit comments

Comments
 (0)