[RFC][PATCH 1/4] zram: introduce zcomp_backend flags callback

From: Sergey Senozhatsky
Date: Thu Aug 13 2015 - 09:56:42 EST


Add ->flags() callback to struct zcomp_backend and zcomp_flags()
function. Compression backends can define own flags and let
compression frontend/zram know them. This is a preparation
patch to enable ZLIB compression backend support.

This also adds two new functions to zcomp: zcomp_decompress_begin()
and zcomp_decompress_end(). These functions are here to hide
backend specific ->flags from zram. For backends that don't
require zstrm for read path zcomp_decompress_begin() will return
NULL, passing it to zcomp_decompress_end() will do no harm.
For backends that do require zstrm for decompression it will
provide opaque pointer to zstrm.

IOW, it goes like this:

void *decomp_data = zcomp_decompress_begin(zram->comp);
ret = zram_decompress_page(zram, decomp_data, uncmem, index);
zcomp_decompress_end(zram->comp, decomp_data);

For backends that require decompress zstrm, zcomp_decompress_begin()
calls zcomp_strm_find(), so it can sleep.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@xxxxxxxxx>
---
drivers/block/zram/zcomp.c | 9 +++++++++
drivers/block/zram/zcomp.h | 5 +++++
drivers/block/zram/zcomp_lz4.c | 6 ++++++
drivers/block/zram/zcomp_lzo.c | 6 ++++++
4 files changed, 26 insertions(+)

diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index 965d1af..61e06b4 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -325,6 +325,15 @@ void zcomp_destroy(struct zcomp *comp)
kfree(comp);
}

+void *zcomp_decompress_begin(struct zcomp *comp)
+{
+ return NULL;
+}
+
+void zcomp_decompress_end(struct zcomp *comp, void *private)
+{
+}
+
/*
* search available compressors for requested algorithm.
* allocate new zcomp and initialize it. return compressing
diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h
index 46e2b9f..b8cf0b0 100644
--- a/drivers/block/zram/zcomp.h
+++ b/drivers/block/zram/zcomp.h
@@ -33,6 +33,8 @@ struct zcomp_backend {
int (*decompress)(const unsigned char *src, size_t src_len,
unsigned char *dst);

+ int (*flags)(void);
+
void *(*create)(void);
void (*destroy)(void *private);

@@ -56,6 +58,9 @@ bool zcomp_available_algorithm(const char *comp);
struct zcomp *zcomp_create(const char *comp, int max_strm);
void zcomp_destroy(struct zcomp *comp);

+void *zcomp_decompress_begin(struct zcomp *comp);
+void zcomp_decompress_end(struct zcomp *comp, void *private);
+
struct zcomp_strm *zcomp_strm_find(struct zcomp *comp);
void zcomp_strm_release(struct zcomp *comp, struct zcomp_strm *zstrm);

diff --git a/drivers/block/zram/zcomp_lz4.c b/drivers/block/zram/zcomp_lz4.c
index f2afb7e..99ed995 100644
--- a/drivers/block/zram/zcomp_lz4.c
+++ b/drivers/block/zram/zcomp_lz4.c
@@ -23,6 +23,11 @@ static void zcomp_lz4_destroy(void *private)
kfree(private);
}

+static int zcomp_lz4_flags(void)
+{
+ return 0;
+}
+
static int zcomp_lz4_compress(const unsigned char *src, unsigned char *dst,
size_t *dst_len, void *private)
{
@@ -43,5 +48,6 @@ struct zcomp_backend zcomp_lz4 = {
.decompress = zcomp_lz4_decompress,
.create = zcomp_lz4_create,
.destroy = zcomp_lz4_destroy,
+ .flags = zcomp_lz4_flags,
.name = "lz4",
};
diff --git a/drivers/block/zram/zcomp_lzo.c b/drivers/block/zram/zcomp_lzo.c
index da1bc47..7572d92 100644
--- a/drivers/block/zram/zcomp_lzo.c
+++ b/drivers/block/zram/zcomp_lzo.c
@@ -23,6 +23,11 @@ static void lzo_destroy(void *private)
kfree(private);
}

+static int lzo_flags(void)
+{
+ return 0;
+}
+
static int lzo_compress(const unsigned char *src, unsigned char *dst,
size_t *dst_len, void *private)
{
@@ -43,5 +48,6 @@ struct zcomp_backend zcomp_lzo = {
.decompress = lzo_decompress,
.create = lzo_create,
.destroy = lzo_destroy,
+ .flags = lzo_flags,
.name = "lzo",
};
--
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/