diff --git a/meson.build b/meson.build index d60be1b050..723bc8dac1 100644 --- a/meson.build +++ b/meson.build @@ -1452,6 +1452,30 @@ conf.set10('HAVE_ZSTD', have_zstd) conf.set10('HAVE_COMPRESSION', have_xz or have_lz4 or have_zstd) +compression = get_option('default-compression') +if compression == 'auto' + if have_zstd + compression = 'zstd' + elif have_lz4 + compression = 'lz4' + elif have_xz + compression = 'xz' + else + compression = 'none' + endif +elif compression == 'zstd' and not have_zstd + error('default-compression=zstd requires zstd') +elif compression == 'lz4' and not have_lz4 + error('default-compression=lz4 requires lz4') +elif compression == 'xz' and not have_xz + error('default-compression=xz requires xz') +endif +conf.set('OBJECT_COMPRESSED_NONE', 0) +conf.set('OBJECT_COMPRESSED_XZ', 1) +conf.set('OBJECT_COMPRESSED_LZ4', 2) +conf.set('OBJECT_COMPRESSED_ZSTD', 4) +conf.set('DEFAULT_COMPRESSION', 'OBJECT_COMPRESSED_@0@'.format(compression.to_upper())) + want_xkbcommon = get_option('xkbcommon') if want_xkbcommon != 'false' and not skip_deps libxkbcommon = dependency('xkbcommon', diff --git a/meson_options.txt b/meson_options.txt index a315ca47c5..2a030ac28e 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -411,6 +411,8 @@ option('lz4', type : 'combo', choices : ['auto', 'true', 'false'], description : 'lz4 compression support') option('zstd', type : 'combo', choices : ['auto', 'true', 'false'], description : 'zstd compression support') +option('default-compression', type : 'combo', choices : ['auto', 'zstd', 'lz4', 'xz'], value: 'auto', + description : 'default compression algorithm') option('xkbcommon', type : 'combo', choices : ['auto', 'true', 'false'], description : 'xkbcommon keymap support') option('pcre2', type : 'combo', choices : ['auto', 'true', 'false'], diff --git a/src/libsystemd/sd-journal/compress.h b/src/libsystemd/sd-journal/compress.h index 005e60e2e3..40ab43c4cb 100644 --- a/src/libsystemd/sd-journal/compress.h +++ b/src/libsystemd/sd-journal/compress.h @@ -18,15 +18,15 @@ int compress_blob_zstd(const void *src, uint64_t src_size, static inline int compress_blob(const void *src, uint64_t src_size, void *dst, size_t dst_alloc_size, size_t *dst_size) { int r; -#if HAVE_ZSTD +#if DEFAULT_COMPRESSION == OBJECT_COMPRESSED_ZSTD r = compress_blob_zstd(src, src_size, dst, dst_alloc_size, dst_size); if (r == 0) return OBJECT_COMPRESSED_ZSTD; -#elif HAVE_LZ4 +#elif DEFAULT_COMPRESSION == OBJECT_COMPRESSED_LZ4 r = compress_blob_lz4(src, src_size, dst, dst_alloc_size, dst_size); if (r == 0) return OBJECT_COMPRESSED_LZ4; -#elif HAVE_XZ +#elif DEFAULT_COMPRESSION == OBJECT_COMPRESSED_XZ r = compress_blob_xz(src, src_size, dst, dst_alloc_size, dst_size); if (r == 0) return OBJECT_COMPRESSED_XZ; @@ -72,13 +72,13 @@ int decompress_stream_xz(int fdf, int fdt, uint64_t max_size); int decompress_stream_lz4(int fdf, int fdt, uint64_t max_size); int decompress_stream_zstd(int fdf, int fdt, uint64_t max_size); -#if HAVE_ZSTD +#if DEFAULT_COMPRESSION == OBJECT_COMPRESSED_ZSTD # define compress_stream compress_stream_zstd # define COMPRESSED_EXT ".zst" -#elif HAVE_LZ4 +#elif DEFAULT_COMPRESSION == OBJECT_COMPRESSED_LZ4 # define compress_stream compress_stream_lz4 # define COMPRESSED_EXT ".lz4" -#elif HAVE_XZ +#elif DEFAULT_COMPRESSION == OBJECT_COMPRESSED_XZ # define compress_stream compress_stream_xz # define COMPRESSED_EXT ".xz" #else diff --git a/src/libsystemd/sd-journal/journal-def.h b/src/libsystemd/sd-journal/journal-def.h index d64c70cbe6..3259b0a515 100644 --- a/src/libsystemd/sd-journal/journal-def.h +++ b/src/libsystemd/sd-journal/journal-def.h @@ -42,11 +42,9 @@ typedef enum ObjectType { _OBJECT_TYPE_MAX } ObjectType; -/* Object flags */ +/* Object flags + * The per-compression enums are defined in meson.build so that config.h is self-contained */ enum { - OBJECT_COMPRESSED_XZ = 1 << 0, - OBJECT_COMPRESSED_LZ4 = 1 << 1, - OBJECT_COMPRESSED_ZSTD = 1 << 2, OBJECT_COMPRESSION_MASK = (OBJECT_COMPRESSED_XZ | OBJECT_COMPRESSED_LZ4 | OBJECT_COMPRESSED_ZSTD), _OBJECT_COMPRESSED_MAX = OBJECT_COMPRESSION_MASK, }; diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index e72f041bdc..a6b2a0f326 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -3359,11 +3359,11 @@ int journal_file_open( .open_flags = open_flags, .writable = (open_flags & O_ACCMODE) != O_RDONLY, -#if HAVE_ZSTD +#if DEFAULT_COMPRESSION == OBJECT_COMPRESSED_ZSTD .compress_zstd = FLAGS_SET(file_flags, JOURNAL_COMPRESS), -#elif HAVE_LZ4 +#elif DEFAULT_COMPRESSION == OBJECT_COMPRESSED_LZ4 .compress_lz4 = FLAGS_SET(file_flags, JOURNAL_COMPRESS), -#elif HAVE_XZ +#elif DEFAULT_COMPRESSION == OBJECT_COMPRESSED_XZ .compress_xz = FLAGS_SET(file_flags, JOURNAL_COMPRESS), #endif .compress_threshold_bytes = compress_threshold_bytes == UINT64_MAX ?