Skip to content

Commit

Permalink
f2fs: compress: fix to avoid redundant compress extension
Browse files Browse the repository at this point in the history
[ Upstream commit 7e1b150 ]

With below script, redundant compress extension will be parsed and added
by parse_options(), because parse_options() doesn't check whether the
extension is existed or not, fix it.

1. mount -t f2fs -o compress_extension=so /dev/vdb /mnt/f2fs
2. mount -t f2fs -o remount,compress_extension=so /mnt/f2fs
3. mount|grep f2fs

/dev/vdb on /mnt/f2fs type f2fs (...,compress_extension=so,compress_extension=so,...)

Fixes: 4c8ff70 ("f2fs: support data compression")
Fixes: 151b198 ("f2fs: compress: add nocompress extensions support")
Signed-off-by: Chao Yu <[email protected]>
Signed-off-by: Jaegeuk Kim <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
chaseyu authored and gregkh committed Nov 20, 2023
1 parent 8c4504c commit e9f598a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions fs/f2fs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,29 @@ static int f2fs_set_test_dummy_encryption(struct super_block *sb,
}

#ifdef CONFIG_F2FS_FS_COMPRESSION
static bool is_compress_extension_exist(struct f2fs_sb_info *sbi,
const char *new_ext, bool is_ext)
{
unsigned char (*ext)[F2FS_EXTENSION_LEN];
int ext_cnt;
int i;

if (is_ext) {
ext = F2FS_OPTION(sbi).extensions;
ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
} else {
ext = F2FS_OPTION(sbi).noextensions;
ext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
}

for (i = 0; i < ext_cnt; i++) {
if (!strcasecmp(new_ext, ext[i]))
return true;
}

return false;
}

/*
* 1. The same extension name cannot not appear in both compress and non-compress extension
* at the same time.
Expand Down Expand Up @@ -1154,6 +1177,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
return -EINVAL;
}

if (is_compress_extension_exist(sbi, name, true)) {
kfree(name);
break;
}

strcpy(ext[ext_cnt], name);
F2FS_OPTION(sbi).compress_ext_cnt++;
kfree(name);
Expand All @@ -1178,6 +1206,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
return -EINVAL;
}

if (is_compress_extension_exist(sbi, name, false)) {
kfree(name);
break;
}

strcpy(noext[noext_cnt], name);
F2FS_OPTION(sbi).nocompress_ext_cnt++;
kfree(name);
Expand Down

0 comments on commit e9f598a

Please sign in to comment.