diff mbox

btrfs: property: Set incompat flag of lzo/zstd compression

Message ID 35713081-318c-8bca-22bc-8b9c4894c0d8@jp.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Misono Tomohiro May 15, 2018, 7:51 a.m. UTC
Incompat flag of lzo/zstd compression should be set at:
 1. mount time (-o compress/compress-force)
 2. when defrag is done
 3. when property is set

Currently 3. is missing and this commit adds this.

Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
---
 fs/btrfs/props.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Su Yue May 15, 2018, 8:05 a.m. UTC | #1
On 05/15/2018 03:51 PM, Misono Tomohiro wrote:
> Incompat flag of lzo/zstd compression should be set at:
>  1. mount time (-o compress/compress-force)
>  2. when defrag is done
>  3. when property is set
> 
> Currently 3. is missing and this commit adds this.
> 

If I don't misunderstand, compression property of an inode is only
apply for *the* inode, not the whole filesystem.
So the original logical should be okay.

Thanks,
Su

> Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
> ---
>  fs/btrfs/props.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
> index 53a8c95828e3..dc6140013ae8 100644
> --- a/fs/btrfs/props.c
> +++ b/fs/btrfs/props.c
> @@ -380,6 +380,7 @@ static int prop_compression_apply(struct inode *inode,
>  				  const char *value,
>  				  size_t len)
>  {
> +	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
>  	int type;
>  
>  	if (len == 0) {
> @@ -390,14 +391,17 @@ static int prop_compression_apply(struct inode *inode,
>  		return 0;
>  	}
>  
> -	if (!strncmp("lzo", value, 3))
> +	if (!strncmp("lzo", value, 3)) {
>  		type = BTRFS_COMPRESS_LZO;
> -	else if (!strncmp("zlib", value, 4))
> +		btrfs_set_fs_incompat(fs_info, COMPRESS_LZO);
> +	} else if (!strncmp("zlib", value, 4)) {
>  		type = BTRFS_COMPRESS_ZLIB;
> -	else if (!strncmp("zstd", value, len))
> +	} else if (!strncmp("zstd", value, len)) {
>  		type = BTRFS_COMPRESS_ZSTD;
> -	else
> +		btrfs_set_fs_incompat(fs_info, COMPRESS_ZSTD);
> +	} else {
>  		return -EINVAL;
> +	}
>  
>  	BTRFS_I(inode)->flags &= ~BTRFS_INODE_NOCOMPRESS;
>  	BTRFS_I(inode)->flags |= BTRFS_INODE_COMPRESS;
>
Anand Jain May 15, 2018, 8:20 a.m. UTC | #2
On 05/15/2018 03:51 PM, Misono Tomohiro wrote:
> Incompat flag of lzo/zstd compression should be set at:
>   1. mount time (-o compress/compress-force)
>   2. when defrag is done
>   3. when property is set
> 
> Currently 3. is missing and this commit adds this.
> 
> Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>

Reviewed-by: Anand Jain <anand.jain@oracle.com>
--
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
Su Yue May 15, 2018, 8:34 a.m. UTC | #3
On 05/15/2018 04:05 PM, Su Yue wrote:
> 
> 
> On 05/15/2018 03:51 PM, Misono Tomohiro wrote:
>> Incompat flag of lzo/zstd compression should be set at:
>>  1. mount time (-o compress/compress-force)
>>  2. when defrag is done
>>  3. when property is set
>>
>> Currently 3. is missing and this commit adds this.
>>
> 
> If I don't misunderstand, compression property of an inode is only

Embarrassed for bad memory about btrfs_set_fs_incompat().
The patch is fine. Just ignore this thread.

> apply for *the* inode, not the whole filesystem.
> So the original logical should be okay.
> 
> Thanks,
> Su
> 
>> Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
>> ---
>>  fs/btrfs/props.c | 12 ++++++++----
>>  1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
>> index 53a8c95828e3..dc6140013ae8 100644
>> --- a/fs/btrfs/props.c
>> +++ b/fs/btrfs/props.c
>> @@ -380,6 +380,7 @@ static int prop_compression_apply(struct inode *inode,
>>  				  const char *value,
>>  				  size_t len)
>>  {
>> +	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
>>  	int type;
>>  
>>  	if (len == 0) {
>> @@ -390,14 +391,17 @@ static int prop_compression_apply(struct inode *inode,
>>  		return 0;
>>  	}
>>  
>> -	if (!strncmp("lzo", value, 3))
>> +	if (!strncmp("lzo", value, 3)) {
>>  		type = BTRFS_COMPRESS_LZO;
>> -	else if (!strncmp("zlib", value, 4))
>> +		btrfs_set_fs_incompat(fs_info, COMPRESS_LZO);
>> +	} else if (!strncmp("zlib", value, 4)) {
>>  		type = BTRFS_COMPRESS_ZLIB;
>> -	else if (!strncmp("zstd", value, len))
>> +	} else if (!strncmp("zstd", value, len)) {
>>  		type = BTRFS_COMPRESS_ZSTD;
>> -	else
>> +		btrfs_set_fs_incompat(fs_info, COMPRESS_ZSTD);
>> +	} else {
>>  		return -EINVAL;
>> +	}
>>  
>>  	BTRFS_I(inode)->flags &= ~BTRFS_INODE_NOCOMPRESS;
>>  	BTRFS_I(inode)->flags |= BTRFS_INODE_COMPRESS;
>>
> 
>
Duncan May 15, 2018, 8:35 a.m. UTC | #4
Su Yue posted on Tue, 15 May 2018 16:05:01 +0800 as excerpted:


> 
> On 05/15/2018 03:51 PM, Misono Tomohiro wrote:
>> Incompat flag of lzo/zstd compression should be set at:
>>  1. mount time (-o compress/compress-force)
>>  2. when defrag is done 3. when property is set
>> 
>> Currently 3. is missing and this commit adds this.
>> 
>> 
> If I don't misunderstand, compression property of an inode is only apply
> for *the* inode, not the whole filesystem.
> So the original logical should be okay.

But the inode is on the filesystem, and if it's compressed with lzo/zstd, 
the incompat flag should be set to avoid mounting with an earlier kernel 
that doesn't understand that compression and would therefore, if we're 
lucky, simply fail to read the data compressed in that file/inode.  (If 
we're unlucky it could blow up with kernel memory corruption like James 
Harvey's current case of unexpected, corrupted compressed data in a nocow 
file that being nocow, doesn't have csum validation to fail and abort the 
decompression, and shouldn't be compressed at all.)

So better to set the incompat flag and refuse to mount at all on kernels 
that don't have the required compression support.
Su Yue May 15, 2018, 8:50 a.m. UTC | #5
On 05/15/2018 04:35 PM, Duncan wrote:
> Su Yue posted on Tue, 15 May 2018 16:05:01 +0800 as excerpted:
> 
> 
>>
>> On 05/15/2018 03:51 PM, Misono Tomohiro wrote:
>>> Incompat flag of lzo/zstd compression should be set at:
>>>  1. mount time (-o compress/compress-force)
>>>  2. when defrag is done 3. when property is set
>>>
>>> Currently 3. is missing and this commit adds this.
>>>
>>>
>> If I don't misunderstand, compression property of an inode is only apply
>> for *the* inode, not the whole filesystem.
>> So the original logical should be okay.
> 
> But the inode is on the filesystem, and if it's compressed with lzo/zstd, 
> the incompat flag should be set to avoid mounting with an earlier kernel 
> that doesn't understand that compression and would therefore, if we're 
> lucky, simply fail to read the data compressed in that file/inode.  (If 
> we're unlucky it could blow up with kernel memory corruption like James 
> Harvey's current case of unexpected, corrupted compressed data in a nocow 
> file that being nocow, doesn't have csum validation to fail and abort the 
> decompression, and shouldn't be compressed at all.)
> 
> So better to set the incompat flag and refuse to mount at all on kernels 
> that don't have the required compression support.
> 

Get it.
As your conclusion, it's indeed better to set the incompat flag.

Thanks,
Su
David Sterba May 15, 2018, 2:07 p.m. UTC | #6
On Tue, May 15, 2018 at 04:51:26PM +0900, Misono Tomohiro wrote:
> Incompat flag of lzo/zstd compression should be set at:
>  1. mount time (-o compress/compress-force)
>  2. when defrag is done
>  3. when property is set
> 
> Currently 3. is missing and this commit adds this.

That was missed during the review, thanks for catching it.

> Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>

Reviewed-by: David Sterba <dsterba@suse.com>

For 4.17-rc and for stable 4.14+.
--
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 53a8c95828e3..dc6140013ae8 100644
--- a/fs/btrfs/props.c
+++ b/fs/btrfs/props.c
@@ -380,6 +380,7 @@  static int prop_compression_apply(struct inode *inode,
 				  const char *value,
 				  size_t len)
 {
+	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
 	int type;
 
 	if (len == 0) {
@@ -390,14 +391,17 @@  static int prop_compression_apply(struct inode *inode,
 		return 0;
 	}
 
-	if (!strncmp("lzo", value, 3))
+	if (!strncmp("lzo", value, 3)) {
 		type = BTRFS_COMPRESS_LZO;
-	else if (!strncmp("zlib", value, 4))
+		btrfs_set_fs_incompat(fs_info, COMPRESS_LZO);
+	} else if (!strncmp("zlib", value, 4)) {
 		type = BTRFS_COMPRESS_ZLIB;
-	else if (!strncmp("zstd", value, len))
+	} else if (!strncmp("zstd", value, len)) {
 		type = BTRFS_COMPRESS_ZSTD;
-	else
+		btrfs_set_fs_incompat(fs_info, COMPRESS_ZSTD);
+	} else {
 		return -EINVAL;
+	}
 
 	BTRFS_I(inode)->flags &= ~BTRFS_INODE_NOCOMPRESS;
 	BTRFS_I(inode)->flags |= BTRFS_INODE_COMPRESS;