tree-wide: add new HAVE_COMPRESSION compile time flag

let's simplify the checks for ZSTD/LZ4/XZ

As suggested:

https://github.com/systemd/systemd/pull/16096#discussion_r440705585
This commit is contained in:
Lennart Poettering 2020-06-24 16:33:41 +02:00
parent 70cd1e561c
commit d80b051cea
9 changed files with 26 additions and 24 deletions

View File

@ -1190,36 +1190,38 @@ want_xz = get_option('xz')
if want_xz != 'false' and not skip_deps
libxz = dependency('liblzma',
required : want_xz == 'true')
have = libxz.found()
have_xz = libxz.found()
else
have = false
have_xz = false
libxz = []
endif
conf.set10('HAVE_XZ', have)
conf.set10('HAVE_XZ', have_xz)
want_lz4 = get_option('lz4')
if want_lz4 != 'false' and not skip_deps
liblz4 = dependency('liblz4',
version : '>= 1.3.0',
required : want_lz4 == 'true')
have = liblz4.found()
have_lz4 = liblz4.found()
else
have = false
have_lz4 = false
liblz4 = []
endif
conf.set10('HAVE_LZ4', have)
conf.set10('HAVE_LZ4', have_lz4)
want_zstd = get_option('zstd')
if want_zstd != 'false' and not skip_deps
libzstd = dependency('libzstd',
required : want_zstd == 'true',
version : '>= 1.4.0')
have = libzstd.found()
have_zstd = libzstd.found()
else
have = false
have_zstd = false
libzstd = []
endif
conf.set10('HAVE_ZSTD', have)
conf.set10('HAVE_ZSTD', have_zstd)
conf.set10('HAVE_COMPRESSION', have_xz or have_lz4 or have_zstd)
want_xkbcommon = get_option('xkbcommon')
if want_xkbcommon != 'false' and not skip_deps

View File

@ -423,7 +423,7 @@ static int save_external_coredump(
goto fail;
}
#if HAVE_XZ || HAVE_LZ4 || HAVE_ZSTD
#if HAVE_COMPRESSION
/* If we will remove the coredump anyway, do not compress. */
if (arg_compress && !maybe_remove_external_coredump(NULL, st.st_size)) {

View File

@ -824,7 +824,7 @@ static int save_core(sd_journal *j, FILE *file, char **path, bool *unlink_temp)
}
if (filename) {
#if HAVE_XZ || HAVE_LZ4 || HAVE_ZSTD
#if HAVE_COMPRESSION
_cleanup_close_ int fdf;
fdf = open(filename, O_RDONLY | O_CLOEXEC);

View File

@ -392,7 +392,7 @@ JournalFile* journal_file_close(JournalFile *f) {
ordered_hashmap_free_free(f->chain_cache);
#if HAVE_XZ || HAVE_LZ4 || HAVE_ZSTD
#if HAVE_COMPRESSION
free(f->compress_buffer);
#endif
@ -1455,7 +1455,7 @@ int journal_file_find_data_object_with_hash(
goto next;
if (o->object.flags & OBJECT_COMPRESSION_MASK) {
#if HAVE_XZ || HAVE_LZ4 || HAVE_ZSTD
#if HAVE_COMPRESSION
uint64_t l;
size_t rsize = 0;
@ -1624,7 +1624,7 @@ static int journal_file_append_data(
o->data.hash = htole64(hash);
#if HAVE_XZ || HAVE_LZ4 || HAVE_ZSTD
#if HAVE_COMPRESSION
if (JOURNAL_FILE_COMPRESS(f) && size >= f->compress_threshold_bytes) {
size_t rsize = 0;
@ -3852,7 +3852,7 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6
return -E2BIG;
if (o->object.flags & OBJECT_COMPRESSION_MASK) {
#if HAVE_XZ || HAVE_LZ4 || HAVE_ZSTD
#if HAVE_COMPRESSION
size_t rsize = 0;
r = decompress_blob(o->object.flags & OBJECT_COMPRESSION_MASK,

View File

@ -107,7 +107,7 @@ typedef struct JournalFile {
unsigned last_seen_generation;
uint64_t compress_threshold_bytes;
#if HAVE_XZ || HAVE_LZ4 || HAVE_ZSTD
#if HAVE_COMPRESSION
void *compress_buffer;
size_t compress_buffer_size;
#endif

View File

@ -2327,7 +2327,7 @@ _public_ int sd_journal_get_data(sd_journal *j, const char *field, const void **
compression = o->object.flags & OBJECT_COMPRESSION_MASK;
if (compression) {
#if HAVE_XZ || HAVE_LZ4 || HAVE_ZSTD
#if HAVE_COMPRESSION
r = decompress_startswith(compression,
o->data.payload, l,
&f->compress_buffer, &f->compress_buffer_size,
@ -2394,7 +2394,7 @@ static int return_data(sd_journal *j, JournalFile *f, Object *o, const void **da
compression = o->object.flags & OBJECT_COMPRESSION_MASK;
if (compression) {
#if HAVE_XZ || HAVE_LZ4 || HAVE_ZSTD
#if HAVE_COMPRESSION
size_t rsize;
int r;

View File

@ -17,7 +17,7 @@ typedef int (compress_t)(const void *src, uint64_t src_size, void *dst,
typedef int (decompress_t)(const void *src, uint64_t src_size,
void **dst, size_t *dst_alloc_size, size_t* dst_size, size_t dst_max);
#if HAVE_XZ || HAVE_LZ4 || HAVE_ZSTD
#if HAVE_COMPRESSION
static usec_t arg_duration;
static size_t arg_start;
@ -143,7 +143,7 @@ static void test_compress_decompress(const char* label, const char* type,
#endif
int main(int argc, char *argv[]) {
#if HAVE_XZ || HAVE_LZ4 || HAVE_ZSTD
#if HAVE_COMPRESSION
test_setup_logging(LOG_INFO);
if (argc >= 2) {

View File

@ -44,7 +44,7 @@ typedef int (decompress_sw_t)(const void *src, uint64_t src_size,
typedef int (compress_stream_t)(int fdf, int fdt, uint64_t max_bytes);
typedef int (decompress_stream_t)(int fdf, int fdt, uint64_t max_size);
#if HAVE_XZ || HAVE_LZ4 || HAVE_ZSTD
#if HAVE_COMPRESSION
_unused_ static void test_compress_decompress(const char *compression,
compress_blob_t compress,
decompress_blob_t decompress,
@ -265,7 +265,7 @@ static void test_lz4_decompress_partial(void) {
#endif
int main(int argc, char *argv[]) {
#if HAVE_XZ || HAVE_LZ4 || HAVE_ZSTD
#if HAVE_COMPRESSION
_unused_ const char text[] =
"text\0foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF"
"foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF";

View File

@ -157,7 +157,7 @@ static void test_empty(void) {
(void) journal_file_close(f4);
}
#if HAVE_XZ || HAVE_LZ4 || HAVE_ZSTD
#if HAVE_COMPRESSION
static bool check_compressed(uint64_t compress_threshold, uint64_t data_size) {
dual_timestamp ts;
JournalFile *f;
@ -251,7 +251,7 @@ int main(int argc, char *argv[]) {
test_non_empty();
test_empty();
#if HAVE_XZ || HAVE_LZ4 || HAVE_ZSTD
#if HAVE_COMPRESSION
test_min_compress_size();
#endif