923a60
From bae0c1d66cba62b19d39a3a79cb76fbd5d4ef7e7 Mon Sep 17 00:00:00 2001
923a60
From: Jan Rybar <jrybar@redhat.com>
923a60
Date: Thu, 17 Aug 2017 14:38:11 +0200
923a60
Subject: [PATCH] Add support to read lz4 compressed journals
923a60
923a60
Functionality already in codebase, but deactivated in RHEL
923a60
Changed calling of LZ4 functions due to deprecation of the originals.
923a60
Fixed typecasting of max_bytes to size_t in debuglog()
923a60
923a60
Resolves: rhbz#1431687
923a60
923a60
changes to .spec file:
923a60
923a60
@@ -552,6 +553,7 @@ BuildRequires:  libblkid-devel
923a60
 BuildRequires:  xz-devel
923a60
 BuildRequires:  zlib-devel
923a60
 BuildRequires:  bzip2-devel
923a60
+BuildRequires:  lz4-devel
923a60
 BuildRequires:  libidn-devel
923a60
 BuildRequires:  libcurl-devel
923a60
 BuildRequires:  kmod-devel
923a60
@@ -742,6 +744,7 @@ CONFIGURE_OPTS=(
923a60
     --enable-compat-libs
923a60
     --disable-sysusers
923a60
     --disable-ldconfig
923a60
+    --enable-lz4
923a60
 %ifarch s390 s390x ppc %{power64} aarch64
923a60
     --disable-lto
923a60
 %endif
923a60
---
923a60
 src/journal/compress.c     | 11 ++++++++---
923a60
 src/journal/compress.h     | 11 -----------
923a60
 src/journal/journal-file.c |  5 ++---
923a60
 3 files changed, 10 insertions(+), 17 deletions(-)
923a60
923a60
diff --git a/src/journal/compress.c b/src/journal/compress.c
923a60
index 4fb09f5965..3baf9e4ad7 100644
923a60
--- a/src/journal/compress.c
923a60
+++ b/src/journal/compress.c
923a60
@@ -98,7 +98,12 @@ int compress_blob_lz4(const void *src, uint64_t src_size, void *dst, size_t *dst
923a60
         if (src_size < 9)
923a60
                 return -ENOBUFS;
923a60
 
923a60
-        r = LZ4_compress_limitedOutput(src, dst + 8, src_size, src_size - 8 - 1);
923a60
+#if LZ4_VERSION_NUMBER >= 10700
923a60
+        r = LZ4_compress_default(src, (char*)dst + 8, src_size, src_size - 8 - 1);
923a60
+#else
923a60
+        r = LZ4_compress_limitedOutput(src, (char*)dst + 8, src_size, src_size - 8 - 1);
923a60
+#endif
923a60
+
923a60
         if (r <= 0)
923a60
                 return -ENOBUFS;
923a60
 
923a60
@@ -458,7 +463,7 @@ int compress_stream_lz4(int fdf, int fdt, off_t max_bytes) {
923a60
 
923a60
                 total_in += n;
923a60
 
923a60
-                r = LZ4_compress_continue(&lz4_data, buf, out, n);
923a60
+                r = LZ4_compress_fast_continue(&lz4_data, buf, out, n, LZ4_COMPRESSBOUND(LZ4_BUFSIZE), 0);
923a60
                 if (r == 0) {
923a60
                         log_error("LZ4 compression failed.");
923a60
                         return -EBADMSG;
923a60
@@ -634,7 +639,7 @@ int decompress_stream_lz4(int fdf, int fdt, off_t max_bytes) {
923a60
                 total_out += r;
923a60
 
923a60
                 if (max_bytes != -1 && total_out > (size_t) max_bytes) {
923a60
-                        log_debug("Decompressed stream longer than %zd bytes", max_bytes);
923a60
+                        log_debug("Decompressed stream longer than %zd bytes", (size_t) max_bytes);
923a60
                         return -EFBIG;
923a60
                 }
923a60
 
923a60
diff --git a/src/journal/compress.h b/src/journal/compress.h
923a60
index 136dda6d39..0f62a58d6e 100644
923a60
--- a/src/journal/compress.h
923a60
+++ b/src/journal/compress.h
923a60
@@ -35,15 +35,9 @@ int compress_blob_lz4(const void *src, uint64_t src_size, void *dst, size_t *dst
923a60
 
923a60
 static inline int compress_blob(const void *src, uint64_t src_size, void *dst, size_t *dst_size) {
923a60
         int r;
923a60
-#ifdef HAVE_LZ4
923a60
-        r = compress_blob_lz4(src, src_size, dst, dst_size);
923a60
-        if (r == 0)
923a60
-                return OBJECT_COMPRESSED_LZ4;
923a60
-#else
923a60
         r = compress_blob_xz(src, src_size, dst, dst_size);
923a60
         if (r == 0)
923a60
                 return OBJECT_COMPRESSED_XZ;
923a60
-#endif
923a60
         return r;
923a60
 }
923a60
 
923a60
@@ -75,12 +69,7 @@ int compress_stream_lz4(int fdf, int fdt, off_t max_bytes);
923a60
 int decompress_stream_xz(int fdf, int fdt, off_t max_size);
923a60
 int decompress_stream_lz4(int fdf, int fdt, off_t max_size);
923a60
 
923a60
-#ifdef HAVE_LZ4
923a60
-#  define compress_stream compress_stream_lz4
923a60
-#  define COMPRESSED_EXT ".lz4"
923a60
-#else
923a60
 #  define compress_stream compress_stream_xz
923a60
 #  define COMPRESSED_EXT ".xz"
923a60
-#endif
923a60
 
923a60
 int decompress_stream(const char *filename, int fdf, int fdt, off_t max_bytes);
923a60
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
923a60
index 0fd59ec073..ebc8e62305 100644
923a60
--- a/src/journal/journal-file.c
923a60
+++ b/src/journal/journal-file.c
923a60
@@ -2615,9 +2615,8 @@ int journal_file_open(
923a60
         f->flags = flags;
923a60
         f->prot = prot_from_flags(flags);
923a60
         f->writable = (flags & O_ACCMODE) != O_RDONLY;
923a60
-#if defined(HAVE_LZ4)
923a60
-        f->compress_lz4 = compress;
923a60
-#elif defined(HAVE_XZ)
923a60
+
923a60
+#if defined(HAVE_XZ)
923a60
         f->compress_xz = compress;
923a60
 #endif
923a60
 #ifdef HAVE_GCRYPT