diff mbox series

[f2fs-dev,1/4] f2fs: fix to check lz4hc compression when CONFIG_F2FS_FS_LZ4HC is not enabled

Message ID 20230124153346.74881-1-frank.li@vivo.com (mailing list archive)
State New
Headers show
Series [f2fs-dev,1/4] f2fs: fix to check lz4hc compression when CONFIG_F2FS_FS_LZ4HC is not enabled | expand

Commit Message

李扬韬 Jan. 24, 2023, 3:33 p.m. UTC
f2fs supports lz4 compression algorithm and lz4hc compression algorithm,
which the level parameter needs to be passed in. When CONFIG_F2FS_FS_LZ4HC
is not enabled, even if there is no problem with the level parameter, add
the level parameter to the lz4 algorithm will cause the mount to fail.

Let's change it to be the same as other compression algorithms. When the
kernel does not enable the algorithm, ignore this parameter and print msg.

Fixes: 3fde13f817e2 ("f2fs: compress: support compress level")
Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
 fs/f2fs/super.c | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)

Comments

Chao Yu Jan. 29, 2023, 10:21 a.m. UTC | #1
On 2023/1/24 23:33, Yangtao Li wrote:
> f2fs supports lz4 compression algorithm and lz4hc compression algorithm,
> which the level parameter needs to be passed in. When CONFIG_F2FS_FS_LZ4HC
> is not enabled, even if there is no problem with the level parameter, add
> the level parameter to the lz4 algorithm will cause the mount to fail.
> 
> Let's change it to be the same as other compression algorithms. When the
> kernel does not enable the algorithm, ignore this parameter and print msg.
> 
> Fixes: 3fde13f817e2 ("f2fs: compress: support compress level")
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
>   fs/f2fs/super.c | 31 ++++++++++++++-----------------
>   1 file changed, 14 insertions(+), 17 deletions(-)
> 
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index d8a65645ee48..ad5df4d5c39a 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -588,19 +588,11 @@ static int f2fs_test_compress_extension(struct f2fs_sb_info *sbi)
>   	return 0;
>   }
>   
> -#ifdef CONFIG_F2FS_FS_LZ4
> +#ifdef CONFIG_F2FS_FS_LZ4HC
>   static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str)
>   {
> -#ifdef CONFIG_F2FS_FS_LZ4HC
>   	unsigned int level;
> -#endif
>   
> -	if (strlen(str) == 3) {
> -		F2FS_OPTION(sbi).compress_level = 0;
> -		return 0;
> -	}
> -
> -#ifdef CONFIG_F2FS_FS_LZ4HC
>   	str += 3;
>   
>   	if (str[0] != ':') {
> @@ -617,10 +609,6 @@ static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str)
>   
>   	F2FS_OPTION(sbi).compress_level = level;
>   	return 0;
> -#else
> -	f2fs_info(sbi, "kernel doesn't support lz4hc compression");
> -	return -EINVAL;
> -#endif
>   }
>   #endif
>   
> @@ -1085,10 +1073,19 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
>   #endif
>   			} else if (!strncmp(name, "lz4", 3)) {
>   #ifdef CONFIG_F2FS_FS_LZ4
> -				ret = f2fs_set_lz4hc_level(sbi, name);
> -				if (ret) {
> -					kfree(name);
> -					return -EINVAL;
> +				if (strlen(name) == 3) {
> +					F2FS_OPTION(sbi).compress_level = 0;
> +				} else {
> +#ifdef CONFIG_F2FS_FS_LZ4HC
> +					ret = f2fs_set_lz4hc_level(sbi, name);
> +					if (ret) {
> +						kfree(name);
> +						return -EINVAL;
> +					}
> +#else
> +					f2fs_info(sbi, "kernel doesn't support lz4hc compression");

It needs to check <alg_name>:<compr_level> format to make sure user wants to
enable lz4hc w/ specified level, otherwise if parameter is lz4xx, it doesn't
make sense to print:

"kernel doesn't support lz4hc compression"

> +					break;

It will cause memory leak for name.

Thanks,

> +#endif
>   				}
>   				F2FS_OPTION(sbi).compress_algorithm =
>   								COMPRESS_LZ4;
Eric Biggers Jan. 29, 2023, 6:12 p.m. UTC | #2
On Sun, Jan 29, 2023 at 06:21:17PM +0800, Chao Yu wrote:
> On 2023/1/24 23:33, Yangtao Li wrote:
> > f2fs supports lz4 compression algorithm and lz4hc compression algorithm,
> > which the level parameter needs to be passed in. When CONFIG_F2FS_FS_LZ4HC
> > is not enabled, even if there is no problem with the level parameter, add

lz4hc is not a different compression algorithm, but rather just a higher
compression level for lz4.

- Eric
patchwork-bot+f2fs@kernel.org April 5, 2023, 4:20 p.m. UTC | #3
Hello:

This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:

On Tue, 24 Jan 2023 23:33:43 +0800 you wrote:
> f2fs supports lz4 compression algorithm and lz4hc compression algorithm,
> which the level parameter needs to be passed in. When CONFIG_F2FS_FS_LZ4HC
> is not enabled, even if there is no problem with the level parameter, add
> the level parameter to the lz4 algorithm will cause the mount to fail.
> 
> Let's change it to be the same as other compression algorithms. When the
> kernel does not enable the algorithm, ignore this parameter and print msg.
> 
> [...]

Here is the summary with links:
  - [f2fs-dev,1/4] f2fs: fix to check lz4hc compression when CONFIG_F2FS_FS_LZ4HC is not enabled
    (no matching commit)
  - [f2fs-dev,2/4] f2fs: introduce f2fs_set_compress_level()
    (no matching commit)
  - [f2fs-dev,3/4] f2fs: set default compress option only when sb_has_compression
    https://git.kernel.org/jaegeuk/f2fs/c/338abb312bb2
  - [f2fs-dev,4/4] f2fs: merge lz4hc_compress_pages() to lz4_compress_pages()
    (no matching commit)

You are awesome, thank you!
diff mbox series

Patch

diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index d8a65645ee48..ad5df4d5c39a 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -588,19 +588,11 @@  static int f2fs_test_compress_extension(struct f2fs_sb_info *sbi)
 	return 0;
 }
 
-#ifdef CONFIG_F2FS_FS_LZ4
+#ifdef CONFIG_F2FS_FS_LZ4HC
 static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str)
 {
-#ifdef CONFIG_F2FS_FS_LZ4HC
 	unsigned int level;
-#endif
 
-	if (strlen(str) == 3) {
-		F2FS_OPTION(sbi).compress_level = 0;
-		return 0;
-	}
-
-#ifdef CONFIG_F2FS_FS_LZ4HC
 	str += 3;
 
 	if (str[0] != ':') {
@@ -617,10 +609,6 @@  static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str)
 
 	F2FS_OPTION(sbi).compress_level = level;
 	return 0;
-#else
-	f2fs_info(sbi, "kernel doesn't support lz4hc compression");
-	return -EINVAL;
-#endif
 }
 #endif
 
@@ -1085,10 +1073,19 @@  static int parse_options(struct super_block *sb, char *options, bool is_remount)
 #endif
 			} else if (!strncmp(name, "lz4", 3)) {
 #ifdef CONFIG_F2FS_FS_LZ4
-				ret = f2fs_set_lz4hc_level(sbi, name);
-				if (ret) {
-					kfree(name);
-					return -EINVAL;
+				if (strlen(name) == 3) {
+					F2FS_OPTION(sbi).compress_level = 0;
+				} else {
+#ifdef CONFIG_F2FS_FS_LZ4HC
+					ret = f2fs_set_lz4hc_level(sbi, name);
+					if (ret) {
+						kfree(name);
+						return -EINVAL;
+					}
+#else
+					f2fs_info(sbi, "kernel doesn't support lz4hc compression");
+					break;
+#endif
 				}
 				F2FS_OPTION(sbi).compress_algorithm =
 								COMPRESS_LZ4;