zcomp_lz4.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (C) 2014 Sergey Senozhatsky.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/slab.h>
  11. #include <linux/lz4.h>
  12. #include "zcomp_lz4.h"
  13. static void *zcomp_lz4_create(void)
  14. {
  15. return kzalloc(LZ4_MEM_COMPRESS, GFP_KERNEL);
  16. }
  17. static void zcomp_lz4_destroy(void *private)
  18. {
  19. kfree(private);
  20. }
  21. #ifdef CONFIG_ZSM
  22. static int zcomp_lz4_compress_zram(const unsigned char *src, unsigned char *dst,
  23. size_t *dst_len, void *private, int *checksum)
  24. {
  25. /* return : Success if return 0 */
  26. return lz4_compress_zram(src, PAGE_SIZE, dst, dst_len, private, checksum);
  27. }
  28. #else
  29. static int zcomp_lz4_compress(const unsigned char *src, unsigned char *dst,
  30. size_t *dst_len, void *private)
  31. {
  32. /* return : Success if return 0 */
  33. return lz4_compress(src, PAGE_SIZE, dst, dst_len, private);
  34. }
  35. #endif
  36. static int zcomp_lz4_decompress(const unsigned char *src, size_t src_len,
  37. unsigned char *dst)
  38. {
  39. size_t dst_len = PAGE_SIZE;
  40. /* return : Success if return 0 */
  41. return lz4_decompress_unknownoutputsize(src, src_len, dst, &dst_len);
  42. }
  43. #ifdef CONFIG_ZSM
  44. struct zcomp_backend zcomp_lz4 = {
  45. .compress = zcomp_lz4_compress_zram,
  46. .decompress = zcomp_lz4_decompress,
  47. .create = zcomp_lz4_create,
  48. .destroy = zcomp_lz4_destroy,
  49. .name = "lz4",
  50. };
  51. #else
  52. struct zcomp_backend zcomp_lz4 = {
  53. .compress = zcomp_lz4_compress,
  54. .decompress = zcomp_lz4_decompress,
  55. .create = zcomp_lz4_create,
  56. .destroy = zcomp_lz4_destroy,
  57. .name = "lz4",
  58. };
  59. #endif