Skip to contentSkip to conversation

f2fs: compress: deny setting unsupported compress algorithm

PATCH Superseded Chao Yu 1 participant 1 message Dec 3, 2020 F2FS file system

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 f2fs: compress: deny setting unsupported compress algorithm

If kernel doesn't support certain kinds of compress algorithm, deny to set them as compress algorithm of f2fs via 'compress_algorithm=%s' mount option.

---
 fs/f2fs/super.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
fs/f2fs/super.c +16 -5
index 6e186e365efc..1b9d2592b1ac 100644
@@ -504,15 +504,10 @@ static int f2fs_compress_set_level(struct f2fs_sb_info *sbi, const char *str,
 		return 0;
 #endif
 	} else if (type == COMPRESS_ZSTD) {
-#ifdef CONFIG_F2FS_FS_ZSTD
 		if (!level || level > ZSTD_maxCLevel()) {
 			f2fs_info(sbi, "invalid zstd compress level: %d", level);
 			return -EINVAL;
 		}
-#else
-		f2fs_info(sbi, "doesn't support zstd compression");
-		return 0;
-#endif
 	}
 	F2FS_OPTION(sbi).compress_level = level;
 	return 0;
@@ -937,9 +932,14 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 			if (!name)
 				return -ENOMEM;
 			if (!strcmp(name, "lzo")) {
+#ifdef CONFIG_F2FS_FS_LZO
 				F2FS_OPTION(sbi).compress_algorithm =
 								COMPRESS_LZO;
+#else
+				f2fs_info(sbi, "Image doesn't support lzo compression");
+#endif
 			} else if (!strncmp(name, "lz4", 3)) {
+#ifdef CONFIG_F2FS_FS_LZ4
 				ret = f2fs_compress_set_level(sbi, name,
 								COMPRESS_LZ4);
 				if (ret) {
@@ -948,7 +948,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 				}
 				F2FS_OPTION(sbi).compress_algorithm =
 								COMPRESS_LZ4;
+#else
+				f2fs_info(sbi, "Image doesn't support lz4 compression");
+#endif
 			} else if (!strncmp(name, "zstd", 4)) {
+#ifdef CONFIG_F2FS_FS_ZSTD
 				ret = f2fs_compress_set_level(sbi, name,
 								COMPRESS_ZSTD);
 				if (ret) {
@@ -957,9 +961,16 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 				}
 				F2FS_OPTION(sbi).compress_algorithm =
 								COMPRESS_ZSTD;
+#else
+				f2fs_info(sbi, "Image doesn't support zstd compression");
+#endif
 			} else if (!strcmp(name, "lzo-rle")) {
+#ifdef CONFIG_F2FS_FS_LZORLE
 				F2FS_OPTION(sbi).compress_algorithm =
 								COMPRESS_LZORLE;
+#else
+				f2fs_info(sbi, "Image doesn't support lzorle compression");
+#endif
 			} else {
 				kfree(name);
 				return -EINVAL;
Signature · 8 lines
2.26.2



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel