Skip to content

Commit

Permalink
Add support to read lz4 compressed journals
Browse files Browse the repository at this point in the history
Functionality already in codebase, but deactivated in RHEL
Changed calling of LZ4 functions due to deprecation of the originals.
Fixed typecasting of max_bytes to size_t in debuglog()

Resolves: rhbz#1431687

changes to .spec file:

@@ -552,6 +553,7 @@ BuildRequires:  libblkid-devel
 BuildRequires:  xz-devel
 BuildRequires:  zlib-devel
 BuildRequires:  bzip2-devel
+BuildRequires:  lz4-devel
 BuildRequires:  libidn-devel
 BuildRequires:  libcurl-devel
 BuildRequires:  kmod-devel
@@ -742,6 +744,7 @@ CONFIGURE_OPTS=(
     --enable-compat-libs
     --disable-sysusers
     --disable-ldconfig
+    --enable-lz4
 %ifarch s390 s390x ppc %{power64} aarch64
     --disable-lto
 %endif
  • Loading branch information
jrybar-rh authored and lnykryn committed Nov 16, 2017
1 parent add02d6 commit bae0c1d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
11 changes: 8 additions & 3 deletions src/journal/compress.c
Expand Up @@ -98,7 +98,12 @@ int compress_blob_lz4(const void *src, uint64_t src_size, void *dst, size_t *dst
if (src_size < 9)
return -ENOBUFS;

r = LZ4_compress_limitedOutput(src, dst + 8, src_size, src_size - 8 - 1);
#if LZ4_VERSION_NUMBER >= 10700
r = LZ4_compress_default(src, (char*)dst + 8, src_size, src_size - 8 - 1);
#else
r = LZ4_compress_limitedOutput(src, (char*)dst + 8, src_size, src_size - 8 - 1);
#endif

if (r <= 0)
return -ENOBUFS;

Expand Down Expand Up @@ -458,7 +463,7 @@ int compress_stream_lz4(int fdf, int fdt, off_t max_bytes) {

total_in += n;

r = LZ4_compress_continue(&lz4_data, buf, out, n);
r = LZ4_compress_fast_continue(&lz4_data, buf, out, n, LZ4_COMPRESSBOUND(LZ4_BUFSIZE), 0);
if (r == 0) {
log_error("LZ4 compression failed.");
return -EBADMSG;
Expand Down Expand Up @@ -634,7 +639,7 @@ int decompress_stream_lz4(int fdf, int fdt, off_t max_bytes) {
total_out += r;

if (max_bytes != -1 && total_out > (size_t) max_bytes) {
log_debug("Decompressed stream longer than %zd bytes", max_bytes);
log_debug("Decompressed stream longer than %zd bytes", (size_t) max_bytes);
return -EFBIG;
}

Expand Down
11 changes: 0 additions & 11 deletions src/journal/compress.h
Expand Up @@ -35,15 +35,9 @@ int compress_blob_lz4(const void *src, uint64_t src_size, void *dst, size_t *dst

static inline int compress_blob(const void *src, uint64_t src_size, void *dst, size_t *dst_size) {
int r;
#ifdef HAVE_LZ4
r = compress_blob_lz4(src, src_size, dst, dst_size);
if (r == 0)
return OBJECT_COMPRESSED_LZ4;
#else
r = compress_blob_xz(src, src_size, dst, dst_size);
if (r == 0)
return OBJECT_COMPRESSED_XZ;
#endif
return r;
}

Expand Down Expand Up @@ -75,12 +69,7 @@ int compress_stream_lz4(int fdf, int fdt, off_t max_bytes);
int decompress_stream_xz(int fdf, int fdt, off_t max_size);
int decompress_stream_lz4(int fdf, int fdt, off_t max_size);

#ifdef HAVE_LZ4
# define compress_stream compress_stream_lz4
# define COMPRESSED_EXT ".lz4"
#else
# define compress_stream compress_stream_xz
# define COMPRESSED_EXT ".xz"
#endif

int decompress_stream(const char *filename, int fdf, int fdt, off_t max_bytes);
5 changes: 2 additions & 3 deletions src/journal/journal-file.c
Expand Up @@ -2615,9 +2615,8 @@ int journal_file_open(
f->flags = flags;
f->prot = prot_from_flags(flags);
f->writable = (flags & O_ACCMODE) != O_RDONLY;
#if defined(HAVE_LZ4)
f->compress_lz4 = compress;
#elif defined(HAVE_XZ)

#if defined(HAVE_XZ)
f->compress_xz = compress;
#endif
#ifdef HAVE_GCRYPT
Expand Down

0 comments on commit bae0c1d

Please sign in to comment.