Skip to content

Commit 00e120b

Browse files
author
Jaegeuk Kim
committed
f2fs: assign default compression level
Let's avoid any confusion from assigning compress_level=0 for LZ4HC and ZSTD. Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent ccf3ff2 commit 00e120b

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

fs/f2fs/compress.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,6 @@ static const struct f2fs_compress_ops f2fs_lz4_ops = {
317317
#endif
318318

319319
#ifdef CONFIG_F2FS_FS_ZSTD
320-
#define F2FS_ZSTD_DEFAULT_CLEVEL 1
321-
322320
static int zstd_init_compress_ctx(struct compress_ctx *cc)
323321
{
324322
zstd_parameters params;
@@ -327,6 +325,7 @@ static int zstd_init_compress_ctx(struct compress_ctx *cc)
327325
unsigned int workspace_size;
328326
unsigned char level = F2FS_I(cc->inode)->i_compress_level;
329327

328+
/* Need to remain this for backward compatibility */
330329
if (!level)
331330
level = F2FS_ZSTD_DEFAULT_CLEVEL;
332331

fs/f2fs/f2fs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,8 @@ struct compress_data {
14401440

14411441
#define F2FS_COMPRESSED_PAGE_MAGIC 0xF5F2C000
14421442

1443+
#define F2FS_ZSTD_DEFAULT_CLEVEL 1
1444+
14431445
#define COMPRESS_LEVEL_OFFSET 8
14441446

14451447
/* compress context */

fs/f2fs/super.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,12 @@ static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str)
589589
{
590590
#ifdef CONFIG_F2FS_FS_LZ4HC
591591
unsigned int level;
592-
#endif
593592

594593
if (strlen(str) == 3) {
595-
F2FS_OPTION(sbi).compress_level = 0;
594+
F2FS_OPTION(sbi).compress_level = LZ4HC_DEFAULT_CLEVEL;
596595
return 0;
597596
}
598597

599-
#ifdef CONFIG_F2FS_FS_LZ4HC
600598
str += 3;
601599

602600
if (str[0] != ':') {
@@ -614,6 +612,10 @@ static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str)
614612
F2FS_OPTION(sbi).compress_level = level;
615613
return 0;
616614
#else
615+
if (strlen(str) == 3) {
616+
F2FS_OPTION(sbi).compress_level = 0;
617+
return 0;
618+
}
617619
f2fs_info(sbi, "kernel doesn't support lz4hc compression");
618620
return -EINVAL;
619621
#endif
@@ -627,7 +629,7 @@ static int f2fs_set_zstd_level(struct f2fs_sb_info *sbi, const char *str)
627629
int len = 4;
628630

629631
if (strlen(str) == len) {
630-
F2FS_OPTION(sbi).compress_level = 0;
632+
F2FS_OPTION(sbi).compress_level = F2FS_ZSTD_DEFAULT_CLEVEL;
631633
return 0;
632634
}
633635

@@ -640,7 +642,7 @@ static int f2fs_set_zstd_level(struct f2fs_sb_info *sbi, const char *str)
640642
if (kstrtouint(str + 1, 10, &level))
641643
return -EINVAL;
642644

643-
if (!level || level > zstd_max_clevel()) {
645+
if (level < zstd_min_clevel() || level > zstd_max_clevel()) {
644646
f2fs_info(sbi, "invalid zstd compress level: %d", level);
645647
return -EINVAL;
646648
}

0 commit comments

Comments
 (0)