2014-04-07 22:38:18 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Sergey Senozhatsky.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/lz4.h>
|
2016-01-14 23:22:29 +00:00
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <linux/mm.h>
|
2014-04-07 22:38:18 +00:00
|
|
|
|
|
|
|
#include "zcomp_lz4.h"
|
|
|
|
|
2016-01-14 23:22:32 +00:00
|
|
|
static void *zcomp_lz4_create(gfp_t flags)
|
2014-04-07 22:38:18 +00:00
|
|
|
{
|
2016-01-14 23:22:29 +00:00
|
|
|
void *ret;
|
|
|
|
|
2016-01-14 23:22:35 +00:00
|
|
|
ret = kmalloc(LZ4_MEM_COMPRESS, flags);
|
2016-01-14 23:22:29 +00:00
|
|
|
if (!ret)
|
|
|
|
ret = __vmalloc(LZ4_MEM_COMPRESS,
|
2016-01-14 23:22:35 +00:00
|
|
|
flags | __GFP_HIGHMEM,
|
2016-01-14 23:22:29 +00:00
|
|
|
PAGE_KERNEL);
|
|
|
|
return ret;
|
2014-04-07 22:38:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void zcomp_lz4_destroy(void *private)
|
|
|
|
{
|
2016-01-14 23:22:29 +00:00
|
|
|
kvfree(private);
|
2014-04-07 22:38:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int zcomp_lz4_compress(const unsigned char *src, unsigned char *dst,
|
|
|
|
size_t *dst_len, void *private)
|
|
|
|
{
|
|
|
|
/* return : Success if return 0 */
|
|
|
|
return lz4_compress(src, PAGE_SIZE, dst, dst_len, private);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int zcomp_lz4_decompress(const unsigned char *src, size_t src_len,
|
|
|
|
unsigned char *dst)
|
|
|
|
{
|
|
|
|
size_t dst_len = PAGE_SIZE;
|
|
|
|
/* return : Success if return 0 */
|
|
|
|
return lz4_decompress_unknownoutputsize(src, src_len, dst, &dst_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct zcomp_backend zcomp_lz4 = {
|
|
|
|
.compress = zcomp_lz4_compress,
|
|
|
|
.decompress = zcomp_lz4_decompress,
|
|
|
|
.create = zcomp_lz4_create,
|
|
|
|
.destroy = zcomp_lz4_destroy,
|
|
|
|
.name = "lz4",
|
|
|
|
};
|