From 898d5660eba688c566e90d0a15050dfeb8b8265d Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Tue, 2 Dec 2014 22:20:08 -0500 Subject: build-sys: use pkgconfig and lz4 and bump version The new frame api was released in v. 125. --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 2024939ad0..1739fe75cf 100644 --- a/configure.ac +++ b/configure.ac @@ -557,9 +557,9 @@ AM_CONDITIONAL(HAVE_BZIP2, [test "$have_bzip2" = "yes"]) have_lz4=no AC_ARG_ENABLE(lz4, AS_HELP_STRING([--enable-lz4], [Enable optional LZ4 support])) AS_IF([test "x$enable_lz4" = "xyes"], [ - AC_CHECK_HEADERS(lz4.h, + PKG_CHECK_MODULES(LZ4, [ liblz4 >= 125 ], [AC_DEFINE(HAVE_LZ4, 1, [Define in LZ4 is available]) have_lz4=yes], - [AC_MSG_ERROR([*** LZ4 support requested but headers not found])]) + [AC_MSG_ERROR([*** LZ4 support requested but libraries not found])]) ]) AM_CONDITIONAL(HAVE_LZ4, [test "$have_lz4" = "yes"]) -- cgit v1.2.3-54-g00ecf From 4b5bc5396c090ee41c45cab9052372d296c4a2f4 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Sat, 6 Dec 2014 21:33:27 -0500 Subject: coredump: use lz4frame api to compress coredumps This converts the stream compression to use the new lz4frame api, compatible with lz4cat. Previous code used custom headers, so the compressed file was not compatible with lz4 command line tools. I considered this the last blocker to using lz4 by default. Speed seems to be reasonable, although a bit (a few percent) slower than the lz4 binary, even though compression is the same. I don't consider this important. It could be caused by the overhead of library calls, but is probably caused by slightly different buffer sizes or such. The code in this patch uses mmap, since since this allows the buffer to be reused while not making the code more complicated at all. In my testing, this version is noticably faster (~20%) than a naive single-buffered version. mmap can cause the program to be killed with SIGBUS, if the underlying file is truncated or a disk error occurs. We only use this from within coredump and coredumpctl, so I don't consider this an issue. Old decompression code is retained and is used if the new code fails indicating a format error. There have been reports of various smaller distributions using previous lz4 code, i.e. the old format, and it is nice to provide backwards compatibility. We can remove the legacy code in a few versions. The way that blobs are compressed in the journal is not affected. --- src/journal/compress.c | 201 ++++++++++++++++++++++++++++++++------------ src/journal/test-compress.c | 9 +- 2 files changed, 150 insertions(+), 60 deletions(-) diff --git a/src/journal/compress.c b/src/journal/compress.c index c66043e503..8e8403f6f8 100644 --- a/src/journal/compress.c +++ b/src/journal/compress.c @@ -22,6 +22,7 @@ #include #include #include +#include #ifdef HAVE_XZ # include @@ -29,6 +30,7 @@ #ifdef HAVE_LZ4 # include +# include #endif #include "compress.h" @@ -37,6 +39,11 @@ #include "sparse-endian.h" #include "journal-def.h" +#ifdef HAVE_LZ4 +DEFINE_TRIVIAL_CLEANUP_FUNC(LZ4F_compressionContext_t, LZ4F_freeCompressionContext); +DEFINE_TRIVIAL_CLEANUP_FUNC(LZ4F_decompressionContext_t, LZ4F_freeDecompressionContext); +#endif + #define ALIGN_8(l) ALIGN_TO(l, sizeof(size_t)) static const char* const object_compressed_table[_OBJECT_COMPRESSED_MAX] = { @@ -416,81 +423,99 @@ int compress_stream_xz(int fdf, int fdt, uint64_t max_bytes) { #endif } -#define LZ4_BUFSIZE (512*1024) +#define LZ4_BUFSIZE (512*1024u) int compress_stream_lz4(int fdf, int fdt, uint64_t max_bytes) { #ifdef HAVE_LZ4 + LZ4F_errorCode_t c; + _cleanup_(LZ4F_freeCompressionContextp) LZ4F_compressionContext_t ctx = NULL; + _cleanup_free_ char *buf = NULL; + char *src = NULL; + size_t size, n, total_in = 0, total_out = 0, offset = 0, frame_size; + struct stat st; + int r; + static const LZ4F_compressOptions_t options = { + .stableSrc = 1, + }; + static const LZ4F_preferences_t preferences = { + .frameInfo.blockSizeID = 5, + }; - _cleanup_free_ char *buf1 = NULL, *buf2 = NULL, *out = NULL; - char *buf; - LZ4_stream_t lz4_data = {}; - le32_t header; - size_t total_in = 0, total_out = sizeof(header); - ssize_t n; + c = LZ4F_createCompressionContext(&ctx, LZ4F_VERSION); + if (LZ4F_isError(c)) + return -ENOMEM; - assert(fdf >= 0); - assert(fdt >= 0); + if (fstat(fdf, &st) < 0) + return log_error_errno(errno, "fstat() failed: %m"); - buf1 = malloc(LZ4_BUFSIZE); - buf2 = malloc(LZ4_BUFSIZE); - out = malloc(LZ4_COMPRESSBOUND(LZ4_BUFSIZE)); - if (!buf1 || !buf2 || !out) - return log_oom(); + frame_size = LZ4F_compressBound(LZ4_BUFSIZE, &preferences); + size = frame_size + 64*1024; /* add some space for header and trailer */ + buf = malloc(size); + if (!buf) + return -ENOMEM; - buf = buf1; - for (;;) { - size_t m; - int r; + n = offset = LZ4F_compressBegin(ctx, buf, size, &preferences); + if (LZ4F_isError(n)) + return -EINVAL; - m = LZ4_BUFSIZE; - if (max_bytes != (uint64_t) -1 && (uint64_t) m > (max_bytes - total_in)) - m = (size_t) (max_bytes - total_in); + src = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fdf, 0); + if (!src) + return -errno; - n = read(fdf, buf, m); - if (n < 0) - return -errno; - if (n == 0) - break; + log_debug("Buffer size is %zu bytes, header size %zu bytes.", size, n); - total_in += n; + while (total_in < (size_t) st.st_size) { + ssize_t k; - r = LZ4_compress_continue(&lz4_data, buf, out, n); - if (r == 0) { - log_error("LZ4 compression failed."); - return -EBADMSG; + k = MIN(LZ4_BUFSIZE, st.st_size - total_in); + n = LZ4F_compressUpdate(ctx, buf + offset, size - offset, + src + total_in, k, &options); + if (LZ4F_isError(n)) { + r = -ENOTRECOVERABLE; + goto cleanup; } - header = htole32(r); - errno = 0; + total_in += k; + offset += n; + total_out += n; - n = write(fdt, &header, sizeof(header)); - if (n < 0) - return -errno; - if (n != sizeof(header)) - return errno ? -errno : -EIO; + if (max_bytes != (uint64_t) -1 && total_out > (size_t) max_bytes) { + log_debug("Compressed stream longer than %zd bytes", max_bytes); + return -EFBIG; + } - n = loop_write(fdt, out, r, false); - if (n < 0) - return n; + if (size - offset < frame_size + 4) { + log_debug("Writing %zu bytes", offset); - total_out += sizeof(header) + r; + k = loop_write(fdt, buf, offset, false); + if (k < 0) { + r = k; + goto cleanup; + } + offset = 0; + } + } - buf = buf == buf1 ? buf2 : buf1; + n = LZ4F_compressEnd(ctx, buf + offset, size - offset, &options); + if (LZ4F_isError(n)) { + r = -ENOTRECOVERABLE; + goto cleanup; } - header = htole32(0); - n = write(fdt, &header, sizeof(header)); - if (n < 0) - return -errno; - if (n != sizeof(header)) - return errno ? -errno : -EIO; + offset += n; + total_out += n; + log_debug("Writing %zu bytes", offset); + r = loop_write(fdt, buf, offset, false); + if (r < 0) + goto cleanup; log_debug("LZ4 compression finished (%zu -> %zu bytes, %.1f%%)", total_in, total_out, (double) total_out / total_in * 100); - - return 0; + cleanup: + munmap(src, st.st_size); + return r; #else return -EPROTONOSUPPORT; #endif @@ -571,9 +596,9 @@ int decompress_stream_xz(int fdf, int fdt, uint64_t max_bytes) { #endif } -int decompress_stream_lz4(int fdf, int fdt, uint64_t max_bytes) { - #ifdef HAVE_LZ4 +static int decompress_stream_lz4_v1(int fdf, int fdt, uint64_t max_bytes) { + _cleanup_free_ char *buf = NULL, *out = NULL; size_t buf_size = 0; LZ4_streamDecode_t lz4_data = {}; @@ -621,7 +646,7 @@ int decompress_stream_lz4(int fdf, int fdt, uint64_t max_bytes) { r = LZ4_decompress_safe_continue(&lz4_data, buf, out, m, 4*LZ4_BUFSIZE); if (r <= 0) - log_error("LZ4 decompression failed."); + log_error("LZ4 decompression failed (legacy format)."); total_out += r; @@ -635,11 +660,77 @@ int decompress_stream_lz4(int fdf, int fdt, uint64_t max_bytes) { return r; } - log_debug("LZ4 decompression finished (%zu -> %zu bytes, %.1f%%)", + log_debug("LZ4 decompression finished (legacy format, %zu -> %zu bytes, %.1f%%)", total_in, total_out, (double) total_out / total_in * 100); return 0; +} + +static int decompress_stream_lz4_v2(int in, int out, uint64_t max_bytes) { + size_t c; + _cleanup_(LZ4F_freeDecompressionContextp) LZ4F_decompressionContext_t ctx = NULL; + _cleanup_free_ char *buf = NULL; + char *src; + struct stat st; + int r = 0; + size_t total_in = 0, total_out = 0; + + c = LZ4F_createDecompressionContext(&ctx, LZ4F_VERSION); + if (LZ4F_isError(c)) + return -ENOMEM; + + if (fstat(in, &st) < 0) + return log_error_errno(errno, "fstat() failed: %m"); + + buf = malloc(LZ4_BUFSIZE); + if (!buf) + return -ENOMEM; + + src = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, in, 0); + if (!src) + return -errno; + + while (total_in < (size_t) st.st_size) { + size_t produced = LZ4_BUFSIZE; + size_t used = st.st_size - total_in; + + c = LZ4F_decompress(ctx, buf, &produced, src + total_in, &used, NULL); + if (LZ4F_isError(c)) { + r = -EBADMSG; + goto cleanup; + } + + total_in += used; + total_out += produced; + + if (max_bytes != (uint64_t) -1 && total_out > (size_t) max_bytes) { + r = log_debug_errno(EFBIG, "Decompressed stream longer than %zd bytes", max_bytes); + goto cleanup; + } + + r = loop_write(out, buf, produced, false); + if (r < 0) + goto cleanup; + } + + log_debug("LZ4 decompression finished (%zu -> %zu bytes, %.1f%%)", + total_in, total_out, + (double) total_out / total_in * 100); + cleanup: + munmap(src, st.st_size); + return r; +} +#endif + +int decompress_stream_lz4(int fdf, int fdt, uint64_t max_bytes) { +#ifdef HAVE_LZ4 + int r; + + r = decompress_stream_lz4_v2(fdf, fdt, max_bytes); + if (r == -EBADMSG) + r = decompress_stream_lz4_v1(fdf, fdt, max_bytes); + return r; #else log_error("Cannot decompress file. Compiled without LZ4 support."); return -EPROTONOSUPPORT; diff --git a/src/journal/test-compress.c b/src/journal/test-compress.c index f17c00e60d..e51b12407f 100644 --- a/src/journal/test-compress.c +++ b/src/journal/test-compress.c @@ -144,8 +144,8 @@ static void test_compress_stream(int compression, const char *srcfile) { _cleanup_close_ int src = -1, dst = -1, dst2 = -1; - char pattern[] = "/tmp/systemd-test.xz.XXXXXX", - pattern2[] = "/tmp/systemd-test.xz.XXXXXX"; + char pattern[] = "/tmp/systemd-test.compressed.XXXXXX", + pattern2[] = "/tmp/systemd-test.compressed.XXXXXX"; int r; _cleanup_free_ char *cmd = NULL, *cmd2; struct stat st = {}; @@ -185,7 +185,7 @@ static void test_compress_stream(int compression, assert_se(lseek(dst, 1, SEEK_SET) == 1); r = decompress(dst, dst2, st.st_size); - assert_se(r == -EBADMSG); + assert_se(r == -EBADMSG || r == 0); assert_se(lseek(dst, 0, SEEK_SET) == 0); assert_se(lseek(dst2, 0, SEEK_SET) == 0); @@ -236,8 +236,7 @@ int main(int argc, char *argv[]) { compress_blob_lz4, decompress_startswith_lz4, data, sizeof(data), true); - /* Produced stream is not compatible with lz4 binary, skip lz4cat check. */ - test_compress_stream(OBJECT_COMPRESSED_LZ4, NULL, + test_compress_stream(OBJECT_COMPRESSED_LZ4, "lz4cat", compress_stream_lz4, decompress_stream_lz4, argv[0]); #else log_info("/* LZ4 test skipped */"); -- cgit v1.2.3-54-g00ecf From 9f35e8b45894f7e201878e128ca371662a9dc63d Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Sat, 6 Dec 2014 21:53:39 -0500 Subject: test-compress-benchmark: test three cases (zeros, simple, semi-random) Existing test would use highly-compressible repeatable input. Two types of input are added: - zeros - random blocks interspersed with zeros The idea is to get more information about behaviour in various cases. On Intel Xeon the results are: % ./test-compress-benchmark XZ/zeros: compressed & decompressed 2535301373 bytes in 32.56s (74.26MiB/s), mean compresion 99.96%, skipped 3160 bytes LZ4/zeros: compressed & decompressed 2535304362 bytes in 1.16s (2088.69MiB/s), mean compresion 99.60%, skipped 171 bytes XZ/simple: compressed & decompressed 2535300963 bytes in 30.42s (79.48MiB/s), mean compresion 99.95%, skipped 3570 bytes LZ4/simple: compressed & decompressed 2535303543 bytes in 1.22s (1978.86MiB/s), mean compresion 99.60%, skipped 990 bytes XZ/random: compressed & decompressed 381756649 bytes in 60.02s (6.07MiB/s), mean compresion 39.64%, skipped 27813723 bytes LZ4/random: compressed & decompressed 2507385036 bytes in 0.97s (2477.52MiB/s), mean compresion 54.77%, skipped 27919497 bytes If someone has ideas for more realistic test cases, they can be easily added to this framework. --- src/journal/test-compress-benchmark.c | 36 +++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/journal/test-compress-benchmark.c b/src/journal/test-compress-benchmark.c index c8e5b76c6c..0be6820a14 100644 --- a/src/journal/test-compress-benchmark.c +++ b/src/journal/test-compress-benchmark.c @@ -20,6 +20,7 @@ #include "compress.h" #include "util.h" #include "macro.h" +#include "random-util.h" typedef int (compress_t)(const void *src, uint64_t src_size, void *dst, size_t *dst_size); typedef int (decompress_t)(const void *src, uint64_t src_size, @@ -27,20 +28,31 @@ typedef int (decompress_t)(const void *src, uint64_t src_size, #define MAX_SIZE (1024*1024LU) -static char* make_buf(size_t count) { +static char* make_buf(size_t count, const char *type) { char *buf; size_t i; buf = malloc(count); assert_se(buf); - for (i = 0; i < count; i++) - buf[i] = 'a' + i % ('z' - 'a' + 1); + if (streq(type, "zeros")) + memzero(buf, count); + else if (streq(type, "simple")) + for (i = 0; i < count; i++) + buf[i] = 'a' + i % ('z' - 'a' + 1); + else if (streq(type, "random")) { + random_bytes(buf, count/10); + random_bytes(buf + 2*count/10, count/10); + random_bytes(buf + 4*count/10, count/20); + random_bytes(buf + 6*count/10, count/20); + random_bytes(buf + 8*count/10, count/20); + } else + assert_not_reached("here"); return buf; } -static void test_compress_decompress(const char* label, +static void test_compress_decompress(const char* label, const char* type, compress_t compress, decompress_t decompress) { usec_t n, n2 = 0; float dt; @@ -50,7 +62,7 @@ static void test_compress_decompress(const char* label, size_t buf2_allocated = 0; size_t skipped = 0, compressed = 0, total = 0; - text = make_buf(MAX_SIZE); + text = make_buf(MAX_SIZE, type); buf = calloc(MAX_SIZE + 1, 1); assert_se(text && buf); @@ -62,7 +74,8 @@ static void test_compress_decompress(const char* label, r = compress(text, i, buf, &j); /* assume compression must be successful except for small inputs */ - assert_se(r == 0 || (i < 2048 && r == -ENOBUFS)); + assert_se(r == 0 || (i < 2048 && r == -ENOBUFS) || streq(type, "random")); + /* check for overwrites */ assert_se(buf[i] == 0); if (r != 0) { @@ -91,23 +104,26 @@ static void test_compress_decompress(const char* label, dt = (n2-n) / 1e6; - log_info("%s: compressed & decompressed %zu bytes in %.2fs (%.2fMiB/s), " + log_info("%s/%s: compressed & decompressed %zu bytes in %.2fs (%.2fMiB/s), " "mean compresion %.2f%%, skipped %zu bytes", - label, total, dt, + label, type, total, dt, total / 1024. / 1024 / dt, 100 - compressed * 100. / total, skipped); } int main(int argc, char *argv[]) { + const char *i; log_set_max_level(LOG_DEBUG); + NULSTR_FOREACH(i, "zeros\0simple\0random\0") { #ifdef HAVE_XZ - test_compress_decompress("XZ", compress_blob_xz, decompress_blob_xz); + test_compress_decompress("XZ", i, compress_blob_xz, decompress_blob_xz); #endif #ifdef HAVE_LZ4 - test_compress_decompress("LZ4", compress_blob_lz4, decompress_blob_lz4); + test_compress_decompress("LZ4", i, compress_blob_lz4, decompress_blob_lz4); #endif + } return 0; } -- cgit v1.2.3-54-g00ecf From e06851720573d3adb4be54a1decfe35bc750b8f4 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Wed, 14 Oct 2015 10:15:27 -0400 Subject: compress: fix mmap error handling --- src/journal/compress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/journal/compress.c b/src/journal/compress.c index 8e8403f6f8..4ada0f12fd 100644 --- a/src/journal/compress.c +++ b/src/journal/compress.c @@ -460,7 +460,7 @@ int compress_stream_lz4(int fdf, int fdt, uint64_t max_bytes) { return -EINVAL; src = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fdf, 0); - if (!src) + if (src == MAP_FAILED) return -errno; log_debug("Buffer size is %zu bytes, header size %zu bytes.", size, n); @@ -688,7 +688,7 @@ static int decompress_stream_lz4_v2(int in, int out, uint64_t max_bytes) { return -ENOMEM; src = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, in, 0); - if (!src) + if (src == MAP_FAILED) return -errno; while (total_in < (size_t) st.st_size) { -- cgit v1.2.3-54-g00ecf From 5146f9f065dbc06b849f92fa00d8d57bd0096e12 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Wed, 14 Oct 2015 10:42:18 -0400 Subject: compress: return errors without logging, do not fake errno Logging for compression and decompression is assymetrical on purpose: if compiled without some type of compression, those compression code paths should never be invoked. OTOH, it is possible to encounter unsupported format on decompression, so leave those log_debug statements in, to make it easier to diagnose stuff. --- src/journal/compress.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/journal/compress.c b/src/journal/compress.c index 4ada0f12fd..8c92e26edd 100644 --- a/src/journal/compress.c +++ b/src/journal/compress.c @@ -447,7 +447,7 @@ int compress_stream_lz4(int fdf, int fdt, uint64_t max_bytes) { return -ENOMEM; if (fstat(fdf, &st) < 0) - return log_error_errno(errno, "fstat() failed: %m"); + return log_debug_errno(errno, "fstat() failed: %m"); frame_size = LZ4F_compressBound(LZ4_BUFSIZE, &preferences); size = frame_size + 64*1024; /* add some space for header and trailer */ @@ -486,8 +486,6 @@ int compress_stream_lz4(int fdf, int fdt, uint64_t max_bytes) { } if (size - offset < frame_size + 4) { - log_debug("Writing %zu bytes", offset); - k = loop_write(fdt, buf, offset, false); if (k < 0) { r = k; @@ -505,7 +503,6 @@ int compress_stream_lz4(int fdf, int fdt, uint64_t max_bytes) { offset += n; total_out += n; - log_debug("Writing %zu bytes", offset); r = loop_write(fdt, buf, offset, false); if (r < 0) goto cleanup; @@ -535,7 +532,7 @@ int decompress_stream_xz(int fdf, int fdt, uint64_t max_bytes) { ret = lzma_stream_decoder(&s, UINT64_MAX, 0); if (ret != LZMA_OK) { - log_error("Failed to initialize XZ decoder: code %u", ret); + log_debug("Failed to initialize XZ decoder: code %u", ret); return -ENOMEM; } @@ -561,7 +558,7 @@ int decompress_stream_xz(int fdf, int fdt, uint64_t max_bytes) { ret = lzma_code(&s, action); if (ret != LZMA_OK && ret != LZMA_STREAM_END) { - log_error("Decompression failed: code %u", ret); + log_debug("Decompression failed: code %u", ret); return -EBADMSG; } @@ -591,7 +588,7 @@ int decompress_stream_xz(int fdf, int fdt, uint64_t max_bytes) { } } #else - log_error("Cannot decompress file. Compiled without XZ support."); + log_debug("Cannot decompress file. Compiled without XZ support."); return -EPROTONOSUPPORT; #endif } @@ -610,7 +607,7 @@ static int decompress_stream_lz4_v1(int fdf, int fdt, uint64_t max_bytes) { out = malloc(4*LZ4_BUFSIZE); if (!out) - return log_oom(); + return -ENOMEM; for (;;) { ssize_t m; @@ -631,22 +628,24 @@ static int decompress_stream_lz4_v1(int fdf, int fdt, uint64_t max_bytes) { * not accept buffers compressed by newer binaries then. */ if (m > LZ4_COMPRESSBOUND(LZ4_BUFSIZE * 4)) { - log_error("Compressed stream block too big: %zd bytes", m); - return -EBADMSG; + log_debug("Compressed stream block too big: %zd bytes", m); + return -ENOBUFS; } total_in += sizeof(header) + m; if (!GREEDY_REALLOC(buf, buf_size, m)) - return log_oom(); + return -ENOMEM; r = loop_read_exact(fdf, buf, m, false); if (r < 0) return r; r = LZ4_decompress_safe_continue(&lz4_data, buf, out, m, 4*LZ4_BUFSIZE); - if (r <= 0) - log_error("LZ4 decompression failed (legacy format)."); + if (r <= 0) { + log_debug("LZ4 decompression failed (legacy format)."); + return -EBADMSG; + } total_out += r; @@ -681,7 +680,7 @@ static int decompress_stream_lz4_v2(int in, int out, uint64_t max_bytes) { return -ENOMEM; if (fstat(in, &st) < 0) - return log_error_errno(errno, "fstat() failed: %m"); + return log_debug_errno(errno, "fstat() failed: %m"); buf = malloc(LZ4_BUFSIZE); if (!buf) @@ -705,7 +704,8 @@ static int decompress_stream_lz4_v2(int in, int out, uint64_t max_bytes) { total_out += produced; if (max_bytes != (uint64_t) -1 && total_out > (size_t) max_bytes) { - r = log_debug_errno(EFBIG, "Decompressed stream longer than %zd bytes", max_bytes); + log_debug("Decompressed stream longer than %zd bytes", max_bytes); + r = -EFBIG; goto cleanup; } @@ -732,7 +732,7 @@ int decompress_stream_lz4(int fdf, int fdt, uint64_t max_bytes) { r = decompress_stream_lz4_v1(fdf, fdt, max_bytes); return r; #else - log_error("Cannot decompress file. Compiled without LZ4 support."); + log_debug("Cannot decompress file. Compiled without LZ4 support."); return -EPROTONOSUPPORT; #endif } -- cgit v1.2.3-54-g00ecf From 1a2a0ac53bbe724caf41c2bcf22ab9ea32b63d4e Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Wed, 14 Oct 2015 22:57:55 -0400 Subject: build-sys: enable lz4 by default if available --enable-lz4 can be used to force lz4 requirement, --disable-lz4 can be used to skip lz4 support even if available. Also, make surrounding checks for bzip2, xz, and zlib similar in structure. This fixes the check for requested but missing bzip2. --- configure.ac | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/configure.ac b/configure.ac index 1739fe75cf..92aa1f787d 100644 --- a/configure.ac +++ b/configure.ac @@ -520,25 +520,27 @@ AC_SUBST(CERTIFICATEROOT) # ------------------------------------------------------------------------------ have_xz=no AC_ARG_ENABLE(xz, AS_HELP_STRING([--disable-xz], [Disable optional XZ support])) -if test "x$enable_xz" != "xno"; then +AS_IF([test "x$enable_xz" != "xno"], [ PKG_CHECK_MODULES(XZ, [ liblzma ], - [AC_DEFINE(HAVE_XZ, 1, [Define if XZ is available]) have_xz=yes], have_xz=no) - if test "x$have_xz" = xno -a "x$enable_xz" = xyes; then - AC_MSG_ERROR([*** XZ support requested but libraries not found]) - fi -fi + [AC_DEFINE(HAVE_XZ, 1, [Define if XZ is available]) + have_xz=yes], + have_xz=no) + AS_IF([test "x$have_xz" = xno -a "x$enable_xz" = xyes], + [AC_MSG_ERROR([*** XZ support requested but libraries not found])]) +]) AM_CONDITIONAL(HAVE_XZ, [test "$have_xz" = "yes"]) # ------------------------------------------------------------------------------ have_zlib=no AC_ARG_ENABLE(zlib, AS_HELP_STRING([--disable-zlib], [Disable optional ZLIB support])) -if test "x$enable_zlib" != "xno"; then +AS_IF([test "x$enable_zlib" != "xno"], [ PKG_CHECK_MODULES(ZLIB, [ zlib ], - [AC_DEFINE(HAVE_ZLIB, 1, [Define if ZLIB is available]) have_zlib=yes], have_zlib=no) - if test "x$have_zlib" = xno -a "x$enable_zlib" = xyes; then - AC_MSG_ERROR([*** ZLIB support requested but libraries not found]) - fi -fi + [AC_DEFINE(HAVE_ZLIB, 1, [Define if ZLIB is available]) + have_zlib=yes], + have_zlib=no) + AS_IF([test "x$have_zlib" = xno -a "x$enable_zlib" = xyes], + [AC_MSG_ERROR([*** ZLIB support requested but libraries not found])]) +]) AM_CONDITIONAL(HAVE_ZLIB, [test "$have_zlib" = "yes"]) # ------------------------------------------------------------------------------ @@ -546,20 +548,24 @@ have_bzip2=no AC_ARG_ENABLE(bzip2, AS_HELP_STRING([--enable-bzip2], [Disable optional BZIP2 support])) AS_IF([test "x$enable_bzip2" != "xno"], [ AC_CHECK_HEADERS(bzlib.h, - [AC_DEFINE(HAVE_BZIP2, 1, [Define in BZIP2 is available]) + [AC_DEFINE(HAVE_BZIP2, 1, [Define if BZIP2 is available]) have_bzip2=yes], - [AS_IF([test "x$have_bzip2" = xyes], [AC_MSG_ERROR([*** BZIP2 support requested but headers not found])]) - ]) + [AS_IF([test "x$enable_bzip2" = xyes], + [AC_MSG_ERROR([*** BZIP2 support requested but headers not found])])] + ) ]) AM_CONDITIONAL(HAVE_BZIP2, [test "$have_bzip2" = "yes"]) # ------------------------------------------------------------------------------ have_lz4=no -AC_ARG_ENABLE(lz4, AS_HELP_STRING([--enable-lz4], [Enable optional LZ4 support])) -AS_IF([test "x$enable_lz4" = "xyes"], [ +AC_ARG_ENABLE(lz4, AS_HELP_STRING([--disable-lz4], [Disable optional LZ4 support])) +AS_IF([test "x$enable_lz4" != "xno"], [ PKG_CHECK_MODULES(LZ4, [ liblz4 >= 125 ], - [AC_DEFINE(HAVE_LZ4, 1, [Define in LZ4 is available]) have_lz4=yes], - [AC_MSG_ERROR([*** LZ4 support requested but libraries not found])]) + [AC_DEFINE(HAVE_LZ4, 1, [Define in LZ4 is available]) + have_lz4=yes], + have_lz4=no) + AS_IF([test "x$have_lz4" = xno -a "x$enable_lz4" = xyes], + [AC_MSG_ERROR([*** LZ4 support requested but libraries not found])]) ]) AM_CONDITIONAL(HAVE_LZ4, [test "$have_lz4" = "yes"]) -- cgit v1.2.3-54-g00ecf