diff mbox

btrfs: prepare for extensions in compression options

Message ID 20170717162222.16926-1-dsterba@suse.com (mailing list archive)
State New, archived
Headers show

Commit Message

David Sterba July 17, 2017, 4:22 p.m. UTC
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>
---
 fs/btrfs/props.c | 4 ++--
 fs/btrfs/super.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

Comments

Anand Jain July 27, 2017, 7:25 a.m. UTC | #1
On 07/18/2017 12:22 AM, David Sterba wrote:
> 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.

  In the view of older kernel with this patch, we need extra logic to
  continue to fail bad string after lzo..
   ----
         mount -o compress=lzoJUNK /dev/sdb /btrfs
           mount: wrong fs type, bad option, bad superblock on /dev/sdb,

           [ 2128.045252] BTRFS error (device sdb): open_ctree failed
    ----

   With this patch. I guess the above mount (or for that matter property
   as well) will be successful. ?

Thanks, Anand


> Applicable since commit 63541927c8d11, v3.14.
> 
> Signed-off-by: David Sterba <dsterba@suse.com>
> ---
>   fs/btrfs/props.c | 4 ++--
>   fs/btrfs/super.c | 4 ++--
>   2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
> index 4b23ae5d0e5c..f41654f05719 100644
> --- a/fs/btrfs/props.c
> +++ b/fs/btrfs/props.c
> @@ -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;
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index 74e47794e63f..147330454c17 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -498,14 +498,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);
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba July 27, 2017, 3:26 p.m. UTC | #2
On Thu, Jul 27, 2017 at 03:25:37PM +0800, Anand Jain wrote:
> On 07/18/2017 12:22 AM, David Sterba wrote:
> > 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.
> 
>   In the view of older kernel with this patch, we need extra logic to
>   continue to fail bad string after lzo..

This would require some validation of the string past 'lzo', which is
intentionally left out of this patch.

>    ----
>          mount -o compress=lzoJUNK /dev/sdb /btrfs
>            mount: wrong fs type, bad option, bad superblock on /dev/sdb,
> 
>            [ 2128.045252] BTRFS error (device sdb): open_ctree failed
>     ----
> 
>    With this patch. I guess the above mount (or for that matter property
>    as well) will be successful. ?

Yes, this will succeed and will behave sanely, lzo will be used.

> > Applicable since commit 63541927c8d11, v3.14.

The patch was not marked for stable so it's up to anybody who wants to
backport it to decide if the relaxed compression algorithm matching is
ok or not.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
index 4b23ae5d0e5c..f41654f05719 100644
--- a/fs/btrfs/props.c
+++ b/fs/btrfs/props.c
@@ -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;
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 74e47794e63f..147330454c17 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -498,14 +498,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);