You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
5.3 KiB
116 lines
5.3 KiB
From 3baac68b2bcad46062b12aa11e15adf8e6d80a40 Mon Sep 17 00:00:00 2001
|
|
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
|
Date: Tue, 4 Apr 2023 18:22:50 +0900
|
|
Subject: [PATCH] sd-journal: always use the compression algorithm specified in
|
|
the header
|
|
|
|
Previously, data object may be compressed with an algorithm that is not
|
|
mentioned in the header.
|
|
|
|
(cherry picked from commit 2360352ef02548723ac0c8eaf5ff6905eb9eeca5)
|
|
|
|
Resolves: #2184929
|
|
---
|
|
src/libsystemd/sd-journal/journal-file.c | 40 ++++++++++++++----------
|
|
src/libsystemd/sd-journal/journal-file.h | 12 +++++--
|
|
2 files changed, 33 insertions(+), 19 deletions(-)
|
|
|
|
diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c
|
|
index 00de564499..1b8f0abf97 100644
|
|
--- a/src/libsystemd/sd-journal/journal-file.c
|
|
+++ b/src/libsystemd/sd-journal/journal-file.c
|
|
@@ -1593,24 +1593,31 @@ static int journal_file_append_field(
|
|
}
|
|
|
|
static Compression maybe_compress_payload(JournalFile *f, uint8_t *dst, const uint8_t *src, uint64_t size, size_t *rsize) {
|
|
- Compression compression = COMPRESSION_NONE;
|
|
-
|
|
assert(f);
|
|
assert(f->header);
|
|
|
|
#if HAVE_COMPRESSION
|
|
- if (JOURNAL_FILE_COMPRESS(f) && size >= f->compress_threshold_bytes) {
|
|
- compression = compress_blob(src, size, dst, size - 1, rsize);
|
|
- if (compression > 0)
|
|
- log_debug("Compressed data object %"PRIu64" -> %zu using %s",
|
|
- size, *rsize, compression_to_string(compression));
|
|
- else
|
|
- /* Compression didn't work, we don't really care why, let's continue without compression */
|
|
- compression = COMPRESSION_NONE;
|
|
+ Compression c;
|
|
+ int r;
|
|
+
|
|
+ c = JOURNAL_FILE_COMPRESSION(f);
|
|
+ if (c == COMPRESSION_NONE || size < f->compress_threshold_bytes)
|
|
+ return COMPRESSION_NONE;
|
|
+
|
|
+ r = compress_blob_explicit(c, src, size, dst, size - 1, rsize);
|
|
+ if (r < 0) {
|
|
+ log_debug_errno(r, "Failed to compress data object using %s, ignoring: %m", compression_to_string(c));
|
|
+ /* Compression didn't work, we don't really care why, let's continue without compression */
|
|
+ return COMPRESSION_NONE;
|
|
}
|
|
-#endif
|
|
|
|
- return compression;
|
|
+ assert(r == c);
|
|
+ log_debug("Compressed data object %"PRIu64" -> %zu using %s", size, *rsize, compression_to_string(c));
|
|
+
|
|
+ return c;
|
|
+#else
|
|
+ return COMPRESSION_NONE;
|
|
+#endif
|
|
}
|
|
|
|
static int journal_file_append_data(
|
|
@@ -3887,20 +3894,21 @@ int journal_file_open(
|
|
f->close_fd = true;
|
|
|
|
if (DEBUG_LOGGING) {
|
|
- static int last_seal = -1, last_compress = -1, last_keyed_hash = -1;
|
|
+ static int last_seal = -1, last_keyed_hash = -1;
|
|
+ static Compression last_compression = _COMPRESSION_INVALID;
|
|
static uint64_t last_bytes = UINT64_MAX;
|
|
|
|
if (last_seal != JOURNAL_HEADER_SEALED(f->header) ||
|
|
last_keyed_hash != JOURNAL_HEADER_KEYED_HASH(f->header) ||
|
|
- last_compress != JOURNAL_FILE_COMPRESS(f) ||
|
|
+ last_compression != JOURNAL_FILE_COMPRESSION(f) ||
|
|
last_bytes != f->compress_threshold_bytes) {
|
|
|
|
log_debug("Journal effective settings seal=%s keyed_hash=%s compress=%s compress_threshold_bytes=%s",
|
|
yes_no(JOURNAL_HEADER_SEALED(f->header)), yes_no(JOURNAL_HEADER_KEYED_HASH(f->header)),
|
|
- yes_no(JOURNAL_FILE_COMPRESS(f)), FORMAT_BYTES(f->compress_threshold_bytes));
|
|
+ compression_to_string(JOURNAL_FILE_COMPRESSION(f)), FORMAT_BYTES(f->compress_threshold_bytes));
|
|
last_seal = JOURNAL_HEADER_SEALED(f->header);
|
|
last_keyed_hash = JOURNAL_HEADER_KEYED_HASH(f->header);
|
|
- last_compress = JOURNAL_FILE_COMPRESS(f);
|
|
+ last_compression = JOURNAL_FILE_COMPRESSION(f);
|
|
last_bytes = f->compress_threshold_bytes;
|
|
}
|
|
}
|
|
diff --git a/src/libsystemd/sd-journal/journal-file.h b/src/libsystemd/sd-journal/journal-file.h
|
|
index 1f3c80c912..0321da4a16 100644
|
|
--- a/src/libsystemd/sd-journal/journal-file.h
|
|
+++ b/src/libsystemd/sd-journal/journal-file.h
|
|
@@ -305,10 +305,16 @@ bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec, int log
|
|
int journal_file_map_data_hash_table(JournalFile *f);
|
|
int journal_file_map_field_hash_table(JournalFile *f);
|
|
|
|
-static inline bool JOURNAL_FILE_COMPRESS(JournalFile *f) {
|
|
+static inline Compression JOURNAL_FILE_COMPRESSION(JournalFile *f) {
|
|
assert(f);
|
|
- return JOURNAL_HEADER_COMPRESSED_XZ(f->header) || JOURNAL_HEADER_COMPRESSED_LZ4(f->header) ||
|
|
- JOURNAL_HEADER_COMPRESSED_ZSTD(f->header);
|
|
+
|
|
+ if (JOURNAL_HEADER_COMPRESSED_XZ(f->header))
|
|
+ return COMPRESSION_XZ;
|
|
+ if (JOURNAL_HEADER_COMPRESSED_LZ4(f->header))
|
|
+ return COMPRESSION_LZ4;
|
|
+ if (JOURNAL_HEADER_COMPRESSED_ZSTD(f->header))
|
|
+ return COMPRESSION_ZSTD;
|
|
+ return COMPRESSION_NONE;
|
|
}
|
|
|
|
uint64_t journal_file_hash_data(JournalFile *f, const void *data, size_t sz);
|