]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
compression: add build-time option to select default
authorLuca Boccassi <bluca@debian.org>
Sat, 9 Apr 2022 17:38:06 +0000 (18:38 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 17 Apr 2022 20:43:59 +0000 (05:43 +0900)
Compression and decompression are controlled by the same build flag,
so if one wants to use, say, LZ4 to compress, ZSTD has to be disabled,
which means one loses the ability to read zstd-compressed journals.

Add a default-compression meson option, that allows to select any of
the available compression algorithms as the default.

meson.build
meson_options.txt
src/libsystemd/sd-journal/compress.h
src/libsystemd/sd-journal/journal-def.h
src/libsystemd/sd-journal/journal-file.c

index d60be1b050618cace02f16dacc654305542cc3c7..723bc8dac15a0da556ae72a55636182e653fd1cf 100644 (file)
@@ -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',
index a315ca47c573ced109093d345bf24d97591ac099..2a030ac28ec05c3f4f8c4a7ed18376385dff8f93 100644 (file)
@@ -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'],
index 005e60e2e3e4b02eb9d0aeee32a5c47694edfead..40ab43c4cbd0b732cbcfcc60b89c7131cc70ba8c 100644 (file)
@@ -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
index d64c70cbe6b13ca839fed8b2e54cd133d9be4381..3259b0a515d86fcd419a2dd0f0baf2e2ccd136ee 100644 (file)
@@ -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,
 };
index e72f041bdc8e3938ff00aeea3a896c95ae04a0ae..a6b2a0f326738d8f8d5607413afc2bea5c8dca9f 100644 (file)
@@ -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 ?