mirror of
git://git.yoctoproject.org/linux-yocto.git
synced 2025-07-05 21:35:46 +02:00
zram: introduce zcomp_req structure
Encapsulate compression/decompression data in zcomp_req structure. Link: https://lkml.kernel.org/r/20240902105656.1383858-18-senozhatsky@chromium.org Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: Minchan Kim <minchan@kernel.org> Cc: Nick Terrell <terrelln@fb.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
dea77d7aea
commit
52c7b4e2ba
|
@ -38,25 +38,24 @@ error:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compress_842(void *ctx, const unsigned char *src, size_t src_len,
|
static int compress_842(void *ctx, struct zcomp_req *req)
|
||||||
unsigned char *dst, size_t *dst_len)
|
|
||||||
{
|
{
|
||||||
struct sw842_ctx *zctx = ctx;
|
struct sw842_ctx *zctx = ctx;
|
||||||
unsigned int dlen = *dst_len;
|
unsigned int dlen = req->dst_len;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = sw842_compress(src, src_len, dst, &dlen, zctx->mem);
|
ret = sw842_compress(req->src, req->src_len, req->dst, &dlen,
|
||||||
|
zctx->mem);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
*dst_len = dlen;
|
req->dst_len = dlen;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int decompress_842(void *ctx, const unsigned char *src, size_t src_len,
|
static int decompress_842(void *ctx, struct zcomp_req *req)
|
||||||
unsigned char *dst, size_t dst_len)
|
|
||||||
{
|
{
|
||||||
unsigned int dlen = dst_len;
|
unsigned int dlen = req->dst_len;
|
||||||
|
|
||||||
return sw842_decompress(src, src_len, dst, &dlen);
|
return sw842_decompress(req->src, req->src_len, req->dst, &dlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct zcomp_ops backend_842 = {
|
const struct zcomp_ops backend_842 = {
|
||||||
|
|
|
@ -74,9 +74,7 @@ error:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int deflate_compress(void *ctx, const unsigned char *src,
|
static int deflate_compress(void *ctx, struct zcomp_req *req)
|
||||||
size_t src_len, unsigned char *dst,
|
|
||||||
size_t *dst_len)
|
|
||||||
{
|
{
|
||||||
struct deflate_ctx *zctx = ctx;
|
struct deflate_ctx *zctx = ctx;
|
||||||
struct z_stream_s *deflate;
|
struct z_stream_s *deflate;
|
||||||
|
@ -87,22 +85,20 @@ static int deflate_compress(void *ctx, const unsigned char *src,
|
||||||
if (ret != Z_OK)
|
if (ret != Z_OK)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
deflate->next_in = (u8 *)src;
|
deflate->next_in = (u8 *)req->src;
|
||||||
deflate->avail_in = src_len;
|
deflate->avail_in = req->src_len;
|
||||||
deflate->next_out = (u8 *)dst;
|
deflate->next_out = (u8 *)req->dst;
|
||||||
deflate->avail_out = *dst_len;
|
deflate->avail_out = req->dst_len;
|
||||||
|
|
||||||
ret = zlib_deflate(deflate, Z_FINISH);
|
ret = zlib_deflate(deflate, Z_FINISH);
|
||||||
if (ret != Z_STREAM_END)
|
if (ret != Z_STREAM_END)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
*dst_len = deflate->total_out;
|
req->dst_len = deflate->total_out;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int deflate_decompress(void *ctx, const unsigned char *src,
|
static int deflate_decompress(void *ctx, struct zcomp_req *req)
|
||||||
size_t src_len, unsigned char *dst,
|
|
||||||
size_t dst_len)
|
|
||||||
{
|
{
|
||||||
struct deflate_ctx *zctx = ctx;
|
struct deflate_ctx *zctx = ctx;
|
||||||
struct z_stream_s *inflate;
|
struct z_stream_s *inflate;
|
||||||
|
@ -114,10 +110,10 @@ static int deflate_decompress(void *ctx, const unsigned char *src,
|
||||||
if (ret != Z_OK)
|
if (ret != Z_OK)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
inflate->next_in = (u8 *)src;
|
inflate->next_in = (u8 *)req->src;
|
||||||
inflate->avail_in = src_len;
|
inflate->avail_in = req->src_len;
|
||||||
inflate->next_out = (u8 *)dst;
|
inflate->next_out = (u8 *)req->dst;
|
||||||
inflate->avail_out = dst_len;
|
inflate->avail_out = req->dst_len;
|
||||||
|
|
||||||
ret = zlib_inflate(inflate, Z_SYNC_FLUSH);
|
ret = zlib_inflate(inflate, Z_SYNC_FLUSH);
|
||||||
if (ret != Z_STREAM_END)
|
if (ret != Z_STREAM_END)
|
||||||
|
|
|
@ -41,26 +41,25 @@ error:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lz4_compress(void *ctx, const unsigned char *src, size_t src_len,
|
static int lz4_compress(void *ctx, struct zcomp_req *req)
|
||||||
unsigned char *dst, size_t *dst_len)
|
|
||||||
{
|
{
|
||||||
struct lz4_ctx *zctx = ctx;
|
struct lz4_ctx *zctx = ctx;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = LZ4_compress_fast(src, dst, src_len, *dst_len,
|
ret = LZ4_compress_fast(req->src, req->dst, req->src_len,
|
||||||
zctx->level, zctx->mem);
|
req->dst_len, zctx->level, zctx->mem);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
*dst_len = ret;
|
req->dst_len = ret;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lz4_decompress(void *ctx, const unsigned char *src,
|
static int lz4_decompress(void *ctx, struct zcomp_req *req)
|
||||||
size_t src_len, unsigned char *dst, size_t dst_len)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = LZ4_decompress_safe(src, dst, src_len, dst_len);
|
ret = LZ4_decompress_safe(req->src, req->dst, req->src_len,
|
||||||
|
req->dst_len);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -41,26 +41,25 @@ error:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lz4hc_compress(void *ctx, const unsigned char *src, size_t src_len,
|
static int lz4hc_compress(void *ctx, struct zcomp_req *req)
|
||||||
unsigned char *dst, size_t *dst_len)
|
|
||||||
{
|
{
|
||||||
struct lz4hc_ctx *zctx = ctx;
|
struct lz4hc_ctx *zctx = ctx;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = LZ4_compress_HC(src, dst, src_len, *dst_len,
|
ret = LZ4_compress_HC(req->src, req->dst, req->src_len, req->dst_len,
|
||||||
zctx->level, zctx->mem);
|
zctx->level, zctx->mem);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
*dst_len = ret;
|
req->dst_len = ret;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lz4hc_decompress(void *ctx, const unsigned char *src,
|
static int lz4hc_decompress(void *ctx, struct zcomp_req *req)
|
||||||
size_t src_len, unsigned char *dst, size_t dst_len)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = LZ4_decompress_safe(src, dst, src_len, dst_len);
|
ret = LZ4_decompress_safe(req->src, req->dst, req->src_len,
|
||||||
|
req->dst_len);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -16,21 +16,21 @@ static void lzo_destroy(void *ctx)
|
||||||
kfree(ctx);
|
kfree(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lzo_compress(void *ctx, const unsigned char *src, size_t src_len,
|
static int lzo_compress(void *ctx, struct zcomp_req *req)
|
||||||
unsigned char *dst, size_t *dst_len)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = lzo1x_1_compress(src, src_len, dst, dst_len, ctx);
|
ret = lzo1x_1_compress(req->src, req->src_len, req->dst,
|
||||||
|
&req->dst_len, ctx);
|
||||||
return ret == LZO_E_OK ? 0 : ret;
|
return ret == LZO_E_OK ? 0 : ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lzo_decompress(void *ctx, const unsigned char *src, size_t src_len,
|
static int lzo_decompress(void *ctx, struct zcomp_req *req)
|
||||||
unsigned char *dst, size_t dst_len)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = lzo1x_decompress_safe(src, src_len, dst, &dst_len);
|
ret = lzo1x_decompress_safe(req->src, req->src_len,
|
||||||
|
req->dst, &req->dst_len);
|
||||||
return ret == LZO_E_OK ? 0 : ret;
|
return ret == LZO_E_OK ? 0 : ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,22 +16,21 @@ static void lzorle_destroy(void *ctx)
|
||||||
kfree(ctx);
|
kfree(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lzorle_compress(void *ctx, const unsigned char *src, size_t src_len,
|
static int lzorle_compress(void *ctx, struct zcomp_req *req)
|
||||||
unsigned char *dst, size_t *dst_len)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = lzorle1x_1_compress(src, src_len, dst, dst_len, ctx);
|
ret = lzorle1x_1_compress(req->src, req->src_len, req->dst,
|
||||||
|
&req->dst_len, ctx);
|
||||||
return ret == LZO_E_OK ? 0 : ret;
|
return ret == LZO_E_OK ? 0 : ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lzorle_decompress(void *ctx, const unsigned char *src,
|
static int lzorle_decompress(void *ctx, struct zcomp_req *req)
|
||||||
size_t src_len, unsigned char *dst,
|
|
||||||
size_t dst_len)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = lzo1x_decompress_safe(src, src_len, dst, &dst_len);
|
ret = lzo1x_decompress_safe(req->src, req->src_len,
|
||||||
|
req->dst, &req->dst_len);
|
||||||
return ret == LZO_E_OK ? 0 : ret;
|
return ret == LZO_E_OK ? 0 : ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,27 +67,26 @@ error:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int zstd_compress(void *ctx, const unsigned char *src, size_t src_len,
|
static int zstd_compress(void *ctx, struct zcomp_req *req)
|
||||||
unsigned char *dst, size_t *dst_len)
|
|
||||||
{
|
{
|
||||||
struct zstd_ctx *zctx = ctx;
|
struct zstd_ctx *zctx = ctx;
|
||||||
size_t ret;
|
size_t ret;
|
||||||
|
|
||||||
ret = zstd_compress_cctx(zctx->cctx, dst, *dst_len,
|
ret = zstd_compress_cctx(zctx->cctx, req->dst, req->dst_len,
|
||||||
src, src_len, &zctx->cprm);
|
req->src, req->src_len, &zctx->cprm);
|
||||||
if (zstd_is_error(ret))
|
if (zstd_is_error(ret))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
*dst_len = ret;
|
req->dst_len = ret;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int zstd_decompress(void *ctx, const unsigned char *src, size_t src_len,
|
static int zstd_decompress(void *ctx, struct zcomp_req *req)
|
||||||
unsigned char *dst, size_t dst_len)
|
|
||||||
{
|
{
|
||||||
struct zstd_ctx *zctx = ctx;
|
struct zstd_ctx *zctx = ctx;
|
||||||
size_t ret;
|
size_t ret;
|
||||||
|
|
||||||
ret = zstd_decompress_dctx(zctx->dctx, dst, dst_len, src, src_len);
|
ret = zstd_decompress_dctx(zctx->dctx, req->dst, req->dst_len,
|
||||||
|
req->src, req->src_len);
|
||||||
if (zstd_is_error(ret))
|
if (zstd_is_error(ret))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -119,22 +119,31 @@ void zcomp_stream_put(struct zcomp *comp)
|
||||||
int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm,
|
int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm,
|
||||||
const void *src, unsigned int *dst_len)
|
const void *src, unsigned int *dst_len)
|
||||||
{
|
{
|
||||||
/* The dst buffer should always be 2 * PAGE_SIZE */
|
struct zcomp_req req = {
|
||||||
size_t dlen = 2 * PAGE_SIZE;
|
.src = src,
|
||||||
|
.dst = zstrm->buffer,
|
||||||
|
.src_len = PAGE_SIZE,
|
||||||
|
.dst_len = 2 * PAGE_SIZE,
|
||||||
|
};
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = comp->ops->compress(zstrm->ctx, src, PAGE_SIZE,
|
ret = comp->ops->compress(zstrm->ctx, &req);
|
||||||
zstrm->buffer, &dlen);
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
*dst_len = dlen;
|
*dst_len = req.dst_len;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int zcomp_decompress(struct zcomp *comp, struct zcomp_strm *zstrm,
|
int zcomp_decompress(struct zcomp *comp, struct zcomp_strm *zstrm,
|
||||||
const void *src, unsigned int src_len, void *dst)
|
const void *src, unsigned int src_len, void *dst)
|
||||||
{
|
{
|
||||||
return comp->ops->decompress(zstrm->ctx, src, src_len,
|
struct zcomp_req req = {
|
||||||
dst, PAGE_SIZE);
|
.src = src,
|
||||||
|
.dst = dst,
|
||||||
|
.src_len = src_len,
|
||||||
|
.dst_len = PAGE_SIZE,
|
||||||
|
};
|
||||||
|
|
||||||
|
return comp->ops->decompress(zstrm->ctx, &req);
|
||||||
}
|
}
|
||||||
|
|
||||||
int zcomp_cpu_up_prepare(unsigned int cpu, struct hlist_node *node)
|
int zcomp_cpu_up_prepare(unsigned int cpu, struct hlist_node *node)
|
||||||
|
|
|
@ -21,12 +21,17 @@ struct zcomp_strm {
|
||||||
void *ctx;
|
void *ctx;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct zcomp_ops {
|
struct zcomp_req {
|
||||||
int (*compress)(void *ctx, const unsigned char *src, size_t src_len,
|
const unsigned char *src;
|
||||||
unsigned char *dst, size_t *dst_len);
|
const size_t src_len;
|
||||||
|
|
||||||
int (*decompress)(void *ctx, const unsigned char *src, size_t src_len,
|
unsigned char *dst;
|
||||||
unsigned char *dst, size_t dst_len);
|
size_t dst_len;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct zcomp_ops {
|
||||||
|
int (*compress)(void *ctx, struct zcomp_req *req);
|
||||||
|
int (*decompress)(void *ctx, struct zcomp_req *req);
|
||||||
|
|
||||||
void *(*create_ctx)(struct zcomp_params *params);
|
void *(*create_ctx)(struct zcomp_params *params);
|
||||||
void (*destroy_ctx)(void *ctx);
|
void (*destroy_ctx)(void *ctx);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user