richardphibel / rpms / systemd

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