Skip to content

Commit

Permalink
btrfs: prepare for extensions in compression options
Browse files Browse the repository at this point in the history
This is a minimal patch intended to be backported to older kernels.
We're going to extend the string specifying the compression method and
this would fail on kernels before that change (the string is compared
exactly).

Relax the string matching only to the prefix, ie. ignoring anything that
goes after "zlib" or "lzo", regardless of th format extension we decide
to use. This applies to the mount options and properties.

That way, patched old kernels could be booted on systems already
utilizing the new compression spec.

Applicable since commit 6354192, v3.14.

Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
David Sterba committed Aug 16, 2017
1 parent 1e20d1c commit a7164fa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions fs/btrfs/props.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ static int prop_compression_apply(struct inode *inode,
return 0;
}

if (!strncmp("lzo", value, len))
if (!strncmp("lzo", value, 3))
type = BTRFS_COMPRESS_LZO;
else if (!strncmp("zlib", value, len))
else if (!strncmp("zlib", value, 4))
type = BTRFS_COMPRESS_ZLIB;
else
return -EINVAL;
Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,14 +499,14 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
btrfs_test_opt(info, FORCE_COMPRESS);
if (token == Opt_compress ||
token == Opt_compress_force ||
strcmp(args[0].from, "zlib") == 0) {
strncmp(args[0].from, "zlib", 4) == 0) {
compress_type = "zlib";
info->compress_type = BTRFS_COMPRESS_ZLIB;
btrfs_set_opt(info->mount_opt, COMPRESS);
btrfs_clear_opt(info->mount_opt, NODATACOW);
btrfs_clear_opt(info->mount_opt, NODATASUM);
no_compress = 0;
} else if (strcmp(args[0].from, "lzo") == 0) {
} else if (strncmp(args[0].from, "lzo", 3) == 0) {
compress_type = "lzo";
info->compress_type = BTRFS_COMPRESS_LZO;
btrfs_set_opt(info->mount_opt, COMPRESS);
Expand Down

0 comments on commit a7164fa

Please sign in to comment.