Re: [PATCHv5 04/23] zram: introduce custom comp backends API
From: Thomas Weißschuh
Date: Sat Jul 06 2024 - 03:51:10 EST
On 2024-07-06 13:56:06+0000, Sergey Senozhatsky wrote:
> Moving to custom backends implementation gives us ability to
> have our own minimalistic and extendable API, and algorithms
> tunings becomes possible.
>
> The list of compression backends is empty at this point,
> we will add backends in the followup patches.
>
> Signed-off-by: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>
> ---
> drivers/block/zram/Kconfig | 39 +--------
> drivers/block/zram/zcomp.c | 151 +++++++++++-----------------------
> drivers/block/zram/zcomp.h | 29 ++++---
> drivers/block/zram/zram_drv.c | 9 +-
> 4 files changed, 76 insertions(+), 152 deletions(-)
<snip>
> --- a/drivers/block/zram/zcomp.h
> +++ b/drivers/block/zram/zcomp.h
> @@ -1,7 +1,4 @@
> /* SPDX-License-Identifier: GPL-2.0-or-later */
> -/*
> - * Copyright (C) 2014 Sergey Senozhatsky.
> - */
>
> #ifndef _ZCOMP_H_
> #define _ZCOMP_H_
> @@ -12,13 +9,26 @@ struct zcomp_strm {
> local_lock_t lock;
> /* compression/decompression buffer */
> void *buffer;
> - struct crypto_comp *tfm;
> + void *ctx;
> +};
> +
> +struct zcomp_ops {
> + int (*compress)(void *ctx, const unsigned char *src, size_t src_len,
> + unsigned char *dst, size_t *dst_len);
> +
> + int (*decompress)(void *ctx, const unsigned char *src, size_t src_len,
> + unsigned char *dst, size_t dst_len);
> +
> + void *(*create_ctx)(void);
> + void (*destroy_ctx)(void *ctx);
> +
> + const char *name;
> };
>
> /* dynamic per-device compression frontend */
> struct zcomp {
> struct zcomp_strm __percpu *stream;
> - const char *name;
> + struct zcomp_ops *ops;
If this is "const struct zcomp_ops *ops" then all the backend struct
zcomp_ops definitions could be constified, improving security.
"zcomp_ops" could also be added to scripts/const_structs.checkpatch,
but there probably won't be many of them anyways.
> struct hlist_node node;
> };
<snip>