]> git.hungrycats.org Git - linux/commitdiff
btrfs: prepare for extensions in compression options
authorDavid Sterba <dsterba@suse.com>
Mon, 17 Jul 2017 16:11:10 +0000 (18:11 +0200)
committerZygo Blaxell <zblaxell@thirteen.furryterror.org>
Fri, 28 Jul 2017 17:50:19 +0000 (13:50 -0400)
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 63541927c8d11, v3.14.

Signed-off-by: David Sterba <dsterba@suse.com>
(cherry picked from commit df50c972e896fedf7c4a853c685aa3bce81798bd)

fs/btrfs/props.c
fs/btrfs/super.c

index f9e60231f6854545d514d8df53b8ba21be92762e..f8932d1bd1cc325e7a75b092b7b46c330467cb87 100644 (file)
@@ -399,9 +399,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;
index 78ca664703a9beb0b30130bf66c6dc840f92dfdb..9ba83223edb8483b4012621fa27bdddd7bc45e45 100644 (file)
@@ -493,14 +493,14 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
                                btrfs_test_opt(root, 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);