Skip to content

Commit fd08324

Browse files
pwojtaszczyk-tshsdenx
authored andcommitted
fs: ubifs: Add support for ZSTD decompression
ZSTD can be a better tradeoff between NAND IO operations and decompression speed giving a better boot time. Signed-off-by: Piotr Wojtaszczyk <[email protected]> Reviewed-by: Heiko Schocher <[email protected]>
1 parent 65fbdab commit fd08324

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

fs/ubifs/ubifs-media.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,14 @@ enum {
320320
* UBIFS_COMPR_NONE: no compression
321321
* UBIFS_COMPR_LZO: LZO compression
322322
* UBIFS_COMPR_ZLIB: ZLIB compression
323+
* UBIFS_COMPR_ZSTD: ZSTD compression
323324
* UBIFS_COMPR_TYPES_CNT: count of supported compression types
324325
*/
325326
enum {
326327
UBIFS_COMPR_NONE,
327328
UBIFS_COMPR_LZO,
328329
UBIFS_COMPR_ZLIB,
330+
UBIFS_COMPR_ZSTD,
329331
UBIFS_COMPR_TYPES_CNT,
330332
};
331333

fs/ubifs/ubifs.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
#include <linux/err.h>
2727
#include <linux/lzo.h>
2828

29+
#if IS_ENABLED(CONFIG_ZSTD)
30+
#include <linux/zstd.h>
31+
#include <abuf.h>
32+
#endif
33+
2934
DECLARE_GLOBAL_DATA_PTR;
3035

3136
/* compress.c */
@@ -41,6 +46,25 @@ static int gzip_decompress(const unsigned char *in, size_t in_len,
4146
(unsigned long *)out_len, 0, 0);
4247
}
4348

49+
#if IS_ENABLED(CONFIG_ZSTD)
50+
static int zstd_decompress_wrapper(const unsigned char *in, size_t in_len,
51+
unsigned char *out, size_t *out_len)
52+
{
53+
struct abuf abuf_in, abuf_out;
54+
int ret;
55+
56+
abuf_init_set(&abuf_in, (void *)in, in_len);
57+
abuf_init_set(&abuf_out, (void *)out, *out_len);
58+
59+
ret = zstd_decompress(&abuf_in, &abuf_out);
60+
if (ret < 0)
61+
return ret;
62+
63+
*out_len = ret;
64+
return 0;
65+
}
66+
#endif
67+
4468
/* Fake description object for the "none" compressor */
4569
static struct ubifs_compressor none_compr = {
4670
.compr_type = UBIFS_COMPR_NONE,
@@ -70,8 +94,21 @@ static struct ubifs_compressor zlib_compr = {
7094
.decompress = gzip_decompress,
7195
};
7296

97+
#if IS_ENABLED(CONFIG_ZSTD)
98+
static struct ubifs_compressor zstd_compr = {
99+
.compr_type = UBIFS_COMPR_ZSTD,
100+
#ifndef __UBOOT__
101+
.comp_mutex = &zstd_enc_mutex,
102+
.decomp_mutex = &zstd_dec_mutex,
103+
#endif
104+
.name = "zstd",
105+
.capi_name = "zstd",
106+
.decompress = zstd_decompress_wrapper,
107+
};
108+
#endif
109+
73110
/* All UBIFS compressors */
74-
struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
111+
struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT] = {NULL};
75112

76113

77114
#ifdef __UBOOT__
@@ -165,8 +202,14 @@ int ubifs_decompress(const struct ubifs_info *c, const void *in_buf,
165202

166203
compr = ubifs_compressors[compr_type];
167204

205+
if (unlikely(!compr)) {
206+
ubifs_err(c, "compression type %d is not compiled in", compr_type);
207+
return -EINVAL;
208+
}
209+
168210
if (unlikely(!compr->capi_name)) {
169-
ubifs_err(c, "%s compression is not compiled in", compr->name);
211+
ubifs_err(c, "%s compression is not compiled in",
212+
compr->name ? compr->name : "unknown");
170213
return -EINVAL;
171214
}
172215

@@ -231,6 +274,12 @@ int __init ubifs_compressors_init(void)
231274
if (err)
232275
return err;
233276

277+
#if IS_ENABLED(CONFIG_ZSTD)
278+
err = compr_init(&zstd_compr);
279+
if (err)
280+
return err;
281+
#endif
282+
234283
err = compr_init(&none_compr);
235284
if (err)
236285
return err;

0 commit comments

Comments
 (0)