1 From 272e5326c7837697882ce3162029ba893059b616 Mon Sep 17 00:00:00 2001
2 From: Anand Jain <anand.jain@oracle.com>
3 Date: Tue, 2 Apr 2019 18:07:40 +0800
4 Subject: btrfs: prop: fix vanished compression property after failed set
6 From: Anand Jain <anand.jain@oracle.com>
8 commit 272e5326c7837697882ce3162029ba893059b616 upstream.
10 The compression property resets to NULL, instead of the old value if we
11 fail to set the new compression parameter.
13 $ btrfs prop get /btrfs compression
15 $ btrfs prop set /btrfs compression zli
16 ERROR: failed to set compression for /btrfs: Invalid argument
17 $ btrfs prop get /btrfs compression
19 This is because the compression property ->validate() is successful for
20 'zli' as the strncmp() used the length passed from the userspace.
22 Fix it by using the expected string length in strncmp().
24 Fixes: 63541927c8d1 ("Btrfs: add support for inode properties")
25 Fixes: 5c1aab1dd544 ("btrfs: Add zstd support")
26 CC: stable@vger.kernel.org # 4.14+
27 Reviewed-by: Nikolay Borisov <nborisov@suse.com>
28 Signed-off-by: Anand Jain <anand.jain@oracle.com>
29 Reviewed-by: David Sterba <dsterba@suse.com>
30 Signed-off-by: David Sterba <dsterba@suse.com>
31 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
34 fs/btrfs/props.c | 6 +++---
35 1 file changed, 3 insertions(+), 3 deletions(-)
37 --- a/fs/btrfs/props.c
38 +++ b/fs/btrfs/props.c
39 @@ -366,11 +366,11 @@ int btrfs_subvol_inherit_props(struct bt
41 static int prop_compression_validate(const char *value, size_t len)
43 - if (!strncmp("lzo", value, len))
44 + if (!strncmp("lzo", value, 3))
46 - else if (!strncmp("zlib", value, len))
47 + else if (!strncmp("zlib", value, 4))
49 - else if (!strncmp("zstd", value, len))
50 + else if (!strncmp("zstd", value, 4))