Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e39602d

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: compress: fix to check zstd compress level correctly in mount option
f2fs only support to config zstd compress level w/ a positive number due to layout design, but since commit e0c1b49 ("lib: zstd: Upgrade to latest upstream zstd version 1.4.10"), zstd supports negative compress level, so that zstd_min_clevel() may return a negative number, then w/ below mount option, .compress_level can be configed w/ a negative number, which is not allowed to f2fs, let's add check condition to avoid it. mount -o compress_algorithm=zstd:4294967295 /dev/sdx /mnt/f2fs Fixes: 00e120b ("f2fs: assign default compression level") Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 1ff61a3 commit e39602d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

fs/f2fs/super.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str)
627627
#ifdef CONFIG_F2FS_FS_ZSTD
628628
static int f2fs_set_zstd_level(struct f2fs_sb_info *sbi, const char *str)
629629
{
630-
unsigned int level;
630+
int level;
631631
int len = 4;
632632

633633
if (strlen(str) == len) {
@@ -641,9 +641,15 @@ static int f2fs_set_zstd_level(struct f2fs_sb_info *sbi, const char *str)
641641
f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>");
642642
return -EINVAL;
643643
}
644-
if (kstrtouint(str + 1, 10, &level))
644+
if (kstrtoint(str + 1, 10, &level))
645645
return -EINVAL;
646646

647+
/* f2fs does not support negative compress level now */
648+
if (level < 0) {
649+
f2fs_info(sbi, "do not support negative compress level: %d", level);
650+
return -ERANGE;
651+
}
652+
647653
if (!f2fs_is_compress_level_valid(COMPRESS_ZSTD, level)) {
648654
f2fs_info(sbi, "invalid zstd compress level: %d", level);
649655
return -EINVAL;

0 commit comments

Comments
 (0)