Skip to content

Commit 7e1b150

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: compress: fix to avoid redundant compress extension
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]>
1 parent 2aaea53 commit 7e1b150

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

fs/f2fs/super.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,29 @@ static int f2fs_set_test_dummy_encryption(struct super_block *sb,
547547
}
548548

549549
#ifdef CONFIG_F2FS_FS_COMPRESSION
550+
static bool is_compress_extension_exist(struct f2fs_sb_info *sbi,
551+
const char *new_ext, bool is_ext)
552+
{
553+
unsigned char (*ext)[F2FS_EXTENSION_LEN];
554+
int ext_cnt;
555+
int i;
556+
557+
if (is_ext) {
558+
ext = F2FS_OPTION(sbi).extensions;
559+
ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
560+
} else {
561+
ext = F2FS_OPTION(sbi).noextensions;
562+
ext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
563+
}
564+
565+
for (i = 0; i < ext_cnt; i++) {
566+
if (!strcasecmp(new_ext, ext[i]))
567+
return true;
568+
}
569+
570+
return false;
571+
}
572+
550573
/*
551574
* 1. The same extension name cannot not appear in both compress and non-compress extension
552575
* at the same time.
@@ -1149,6 +1172,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
11491172
return -EINVAL;
11501173
}
11511174

1175+
if (is_compress_extension_exist(sbi, name, true)) {
1176+
kfree(name);
1177+
break;
1178+
}
1179+
11521180
strcpy(ext[ext_cnt], name);
11531181
F2FS_OPTION(sbi).compress_ext_cnt++;
11541182
kfree(name);
@@ -1173,6 +1201,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
11731201
return -EINVAL;
11741202
}
11751203

1204+
if (is_compress_extension_exist(sbi, name, false)) {
1205+
kfree(name);
1206+
break;
1207+
}
1208+
11761209
strcpy(noext[noext_cnt], name);
11771210
F2FS_OPTION(sbi).nocompress_ext_cnt++;
11781211
kfree(name);

0 commit comments

Comments
 (0)