[PATCH] fs: ubifs: Add support for ZSTD decompression

Signed-off-by: Piotr Wojtaszczyk piotr.wojtaszczyk@timesys.com ---
fs/ubifs/ubifs-media.h | 2 ++ fs/ubifs/ubifs.c | 55 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/fs/ubifs/ubifs-media.h b/fs/ubifs/ubifs-media.h index 2b5b26a01b..299d80f928 100644 --- a/fs/ubifs/ubifs-media.h +++ b/fs/ubifs/ubifs-media.h @@ -320,12 +320,14 @@ enum { * UBIFS_COMPR_NONE: no compression * UBIFS_COMPR_LZO: LZO compression * UBIFS_COMPR_ZLIB: ZLIB compression + * UBIFS_COMPR_ZSTD: ZSTD compression * UBIFS_COMPR_TYPES_CNT: count of supported compression types */ enum { UBIFS_COMPR_NONE, UBIFS_COMPR_LZO, UBIFS_COMPR_ZLIB, + UBIFS_COMPR_ZSTD, UBIFS_COMPR_TYPES_CNT, };
diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c index a509584e5d..4df7cbb951 100644 --- a/fs/ubifs/ubifs.c +++ b/fs/ubifs/ubifs.c @@ -27,6 +27,11 @@ #include <linux/err.h> #include <linux/lzo.h>
+#if IS_ENABLED(CONFIG_ZSTD) +#include <linux/zstd.h> +#include <abuf.h> +#endif + DECLARE_GLOBAL_DATA_PTR;
/* compress.c */ @@ -42,6 +47,26 @@ static int gzip_decompress(const unsigned char *in, size_t in_len, (unsigned long *)out_len, 0, 0); }
+#if IS_ENABLED(CONFIG_ZSTD) +static int zstd_decompress_wrapper(const unsigned char *in, size_t in_len, + unsigned char *out, size_t *out_len) +{ + struct abuf abuf_in, abuf_out; + int ret; + + abuf_init_set(&abuf_in, (void *)in, in_len); + abuf_init_set(&abuf_out, (void *)out, *out_len); + + ret = zstd_decompress(&abuf_in, &abuf_out); + if (ret < 0) { + return ret; + } + + *out_len = ret; + return 0; +} +#endif + /* Fake description object for the "none" compressor */ static struct ubifs_compressor none_compr = { .compr_type = UBIFS_COMPR_NONE, @@ -71,8 +96,22 @@ static struct ubifs_compressor zlib_compr = { .decompress = gzip_decompress, };
+#if IS_ENABLED(CONFIG_ZSTD) +static struct ubifs_compressor zstd_compr = { + .compr_type = UBIFS_COMPR_ZSTD, +#ifndef __UBOOT__ + .comp_mutex = &zstd_enc_mutex, + .decomp_mutex = &zstd_dec_mutex, +#endif + .name = "zstd", + .capi_name = "zstd", + .decompress = zstd_decompress_wrapper, +}; +#endif + + /* All UBIFS compressors */ -struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT]; +struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT] = {NULL};
#ifdef __UBOOT__ @@ -166,8 +205,14 @@ int ubifs_decompress(const struct ubifs_info *c, const void *in_buf,
compr = ubifs_compressors[compr_type];
+ if (unlikely(!compr)) { + ubifs_err(c, "compression type %d is not compiled in", compr_type); + return -EINVAL; + } + if (unlikely(!compr->capi_name)) { - ubifs_err(c, "%s compression is not compiled in", compr->name); + ubifs_err(c, "%s compression is not compiled in", + compr->name ? compr->name : "unknown"); return -EINVAL; }
@@ -232,6 +277,12 @@ int __init ubifs_compressors_init(void) if (err) return err;
+#if IS_ENABLED(CONFIG_ZSTD) + err = compr_init(&zstd_compr); + if (err) + return err; +#endif + err = compr_init(&none_compr); if (err) return err;

Hello Piotr,
On 30.04.24 12:23, Piotr Wojtaszczyk wrote:
Signed-off-by: Piotr Wojtaszczyk piotr.wojtaszczyk@timesys.com
fs/ubifs/ubifs-media.h | 2 ++ fs/ubifs/ubifs.c | 55 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-)
Looks good to me, thanks!
Acked-by: Heiko Schocher hs@denx.de
bye, Heiko

Hello Piotr,
On 06.05.24 16:07, Heiko Schocher wrote:
Hello Piotr,
On 30.04.24 12:23, Piotr Wojtaszczyk wrote:
Signed-off-by: Piotr Wojtaszczyk piotr.wojtaszczyk@timesys.com
fs/ubifs/ubifs-media.h | 2 ++ fs/ubifs/ubifs.c | 55 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-)
Looks good to me, thanks!
Acked-by: Heiko Schocher hs@denx.de
Just tried to apply your patch (sorry for being so late) and checkpatch dropped some warnings, see below. Could you please fix them?
Thanks!
bye, Heiko [1] checkpatch warnings
WARNING: Missing commit description - Add an appropriate one
WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible #160: FILE: fs/ubifs/ubifs.c:30: +#if IS_ENABLED(CONFIG_ZSTD)
WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible #172: FILE: fs/ubifs/ubifs.c:50: +#if IS_ENABLED(CONFIG_ZSTD)
CHECK: Alignment should match open parenthesis #174: FILE: fs/ubifs/ubifs.c:52: +static int zstd_decompress_wrapper(const unsigned char *in, size_t in_len, + unsigned char *out, size_t *out_len)
WARNING: braces {} are not necessary for single statement blocks #183: FILE: fs/ubifs/ubifs.c:61: + if (ret < 0) { + return ret; + }
WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible #199: FILE: fs/ubifs/ubifs.c:99: +#if IS_ENABLED(CONFIG_ZSTD)
CHECK: Please don't use multiple blank lines #212: FILE: fs/ubifs/ubifs.c:112: + +
CHECK: Alignment should match open parenthesis #231: FILE: fs/ubifs/ubifs.c:215: + ubifs_err(c, "%s compression is not compiled in", + compr->name ? compr->name : "unknown");
WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible #239: FILE: fs/ubifs/ubifs.c:280: +#if IS_ENABLED(CONFIG_ZSTD)
total: 0 errors, 6 warnings, 3 checks, 101 lines checked
NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace.
mbox has style problems, please review.
NOTE: Ignored message types: COMPLEX_MACRO CONSIDER_KSTRTO ENOSYS MINMAX MULTISTATEMENT_MACRO_USE_DO_WHILE NETWORKING_BLOCK_COMMENT_STYLE PREFER_ETHER_ADDR_COPY USLEEP_RANGE
NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS. Wende an: fs: ubifs: Add support for ZSTD decompression
participants (2)
-
Heiko Schocher
-
Piotr Wojtaszczyk