daandemeyer / rpms / systemd

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