mirror of
https://github.com/systemd/systemd.git
synced 2024-11-23 10:13:34 +08:00
meson: use a single constant for default compression setting
Suggested by Daniele Nicolodi: https://github.com/systemd/systemd/pull/23160#discussion_r855853716 This is possible only if the macro is never used in #if, but only in C code. This means that all places that use #if have to be refactored into C, but we reduce the duplication a bit, and C is nicer to read than preprocessor conditionals.
This commit is contained in:
parent
1d997b8114
commit
ee00684c50
@ -1470,9 +1470,9 @@ elif compression == 'lz4' and not have_lz4
|
||||
elif compression == 'xz' and not have_xz
|
||||
error('default-compression=xz requires xz')
|
||||
endif
|
||||
conf.set10('DEFAULT_COMPRESSION_ZSTD', compression == 'zstd')
|
||||
conf.set10('DEFAULT_COMPRESSION_LZ4', compression == 'lz4')
|
||||
conf.set10('DEFAULT_COMPRESSION_XZ', compression == 'xz')
|
||||
conf.set('DEFAULT_COMPRESSION',
|
||||
compression == 'none' ? 0 :
|
||||
'OBJECT_COMPRESSED_@0@'.format(compression.to_upper()))
|
||||
|
||||
want_xkbcommon = get_option('xkbcommon')
|
||||
if want_xkbcommon != 'false' and not skip_deps
|
||||
|
@ -462,7 +462,7 @@ static int save_external_coredump(
|
||||
if (lseek(fd, 0, SEEK_SET) == (off_t) -1)
|
||||
return log_error_errno(errno, "Failed to seek on coredump %s: %m", fn);
|
||||
|
||||
fn_compressed = strjoin(fn, COMPRESSED_EXT);
|
||||
fn_compressed = strjoin(fn, default_compression_extension());
|
||||
if (!fn_compressed)
|
||||
return log_oom();
|
||||
|
||||
|
@ -53,37 +53,42 @@ int decompress_stream_zstd(int fdf, int fdt, uint64_t max_size);
|
||||
|
||||
static inline int compress_blob(const void *src, uint64_t src_size,
|
||||
void *dst, size_t dst_alloc_size, size_t *dst_size) {
|
||||
#if DEFAULT_COMPRESSION_ZSTD
|
||||
return compress_blob_zstd(src, src_size, dst, dst_alloc_size, dst_size);
|
||||
#elif DEFAULT_COMPRESSION_LZ4
|
||||
return compress_blob_lz4(src, src_size, dst, dst_alloc_size, dst_size);
|
||||
#elif DEFAULT_COMPRESSION_XZ
|
||||
return compress_blob_xz(src, src_size, dst, dst_alloc_size, dst_size);
|
||||
#else
|
||||
return -EOPNOTSUPP;
|
||||
#endif
|
||||
switch (DEFAULT_COMPRESSION) {
|
||||
case OBJECT_COMPRESSED_ZSTD:
|
||||
return compress_blob_zstd(src, src_size, dst, dst_alloc_size, dst_size);
|
||||
case OBJECT_COMPRESSED_LZ4:
|
||||
return compress_blob_lz4(src, src_size, dst, dst_alloc_size, dst_size);
|
||||
case OBJECT_COMPRESSED_XZ:
|
||||
return compress_blob_xz(src, src_size, dst, dst_alloc_size, dst_size);
|
||||
default:
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
}
|
||||
|
||||
static inline int compress_stream(int fdf, int fdt, uint64_t max_bytes, uint64_t *ret_uncompressed_size) {
|
||||
#if DEFAULT_COMPRESSION_ZSTD
|
||||
return compress_stream_zstd(fdf, fdt, max_bytes, ret_uncompressed_size);
|
||||
#elif DEFAULT_COMPRESSION_LZ4
|
||||
return compress_stream_lz4(fdf, fdt, max_bytes, ret_uncompressed_size);
|
||||
#elif DEFAULT_COMPRESSION_XZ
|
||||
return compress_stream_xz(fdf, fdt, max_bytes, ret_uncompressed_size);
|
||||
#else
|
||||
return -EOPNOTSUPP;
|
||||
#endif
|
||||
switch (DEFAULT_COMPRESSION) {
|
||||
case OBJECT_COMPRESSED_ZSTD:
|
||||
return compress_stream_zstd(fdf, fdt, max_bytes, ret_uncompressed_size);
|
||||
case OBJECT_COMPRESSED_LZ4:
|
||||
return compress_stream_lz4(fdf, fdt, max_bytes, ret_uncompressed_size);
|
||||
case OBJECT_COMPRESSED_XZ:
|
||||
return compress_stream_xz(fdf, fdt, max_bytes, ret_uncompressed_size);
|
||||
default:
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
}
|
||||
|
||||
#if DEFAULT_COMPRESSION_ZSTD
|
||||
# define COMPRESSED_EXT ".zst"
|
||||
#elif DEFAULT_COMPRESSION_LZ4
|
||||
# define COMPRESSED_EXT ".lz4"
|
||||
#elif DEFAULT_COMPRESSION_XZ
|
||||
# define COMPRESSED_EXT ".xz"
|
||||
#else
|
||||
# define COMPRESSED_EXT ""
|
||||
#endif
|
||||
static inline const char* default_compression_extension(void) {
|
||||
switch (DEFAULT_COMPRESSION) {
|
||||
case OBJECT_COMPRESSED_ZSTD:
|
||||
return ".zst";
|
||||
case OBJECT_COMPRESSED_LZ4:
|
||||
return ".lz4";
|
||||
case OBJECT_COMPRESSED_XZ:
|
||||
return ".xz";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
int decompress_stream(const char *filename, int fdf, int fdt, uint64_t max_bytes);
|
||||
|
@ -3359,13 +3359,6 @@ int journal_file_open(
|
||||
.open_flags = open_flags,
|
||||
.writable = (open_flags & O_ACCMODE) != O_RDONLY,
|
||||
|
||||
#if DEFAULT_COMPRESSION_ZSTD
|
||||
.compress_zstd = FLAGS_SET(file_flags, JOURNAL_COMPRESS),
|
||||
#elif DEFAULT_COMPRESSION_LZ4
|
||||
.compress_lz4 = FLAGS_SET(file_flags, JOURNAL_COMPRESS),
|
||||
#elif DEFAULT_COMPRESSION_XZ
|
||||
.compress_xz = FLAGS_SET(file_flags, JOURNAL_COMPRESS),
|
||||
#endif
|
||||
.compress_threshold_bytes = compress_threshold_bytes == UINT64_MAX ?
|
||||
DEFAULT_COMPRESS_THRESHOLD :
|
||||
MAX(MIN_COMPRESS_THRESHOLD, compress_threshold_bytes),
|
||||
@ -3374,6 +3367,13 @@ int journal_file_open(
|
||||
#endif
|
||||
};
|
||||
|
||||
if (DEFAULT_COMPRESSION == OBJECT_COMPRESSED_ZSTD)
|
||||
f->compress_zstd = FLAGS_SET(file_flags, JOURNAL_COMPRESS);
|
||||
else if (DEFAULT_COMPRESSION == OBJECT_COMPRESSED_LZ4)
|
||||
f->compress_lz4 = FLAGS_SET(file_flags, JOURNAL_COMPRESS);
|
||||
else if (DEFAULT_COMPRESSION == OBJECT_COMPRESSED_XZ)
|
||||
f->compress_xz = FLAGS_SET(file_flags, JOURNAL_COMPRESS);
|
||||
|
||||
/* We turn on keyed hashes by default, but provide an environment variable to turn them off, if
|
||||
* people really want that */
|
||||
r = getenv_bool("SYSTEMD_JOURNAL_KEYED_HASH");
|
||||
|
Loading…
Reference in New Issue
Block a user