|
|
923a60 |
From f45b66a348f5778bd391ad1b0a0e09bf5789b415 Mon Sep 17 00:00:00 2001
|
|
|
923a60 |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
923a60 |
Date: Sat, 24 Oct 2015 13:17:54 +0200
|
|
|
923a60 |
Subject: [PATCH] journal: fix error handling when compressing journal objects
|
|
|
923a60 |
|
|
|
923a60 |
Let's make sure we handle compression errors properly, and don't
|
|
|
923a60 |
misunderstand an error for success.
|
|
|
923a60 |
|
|
|
923a60 |
Also, let's actually compress things if lz4 is enabled.
|
|
|
923a60 |
|
|
|
923a60 |
Fixes #1662.
|
|
|
923a60 |
|
|
|
923a60 |
Cherry-picked from: d1afbcd22170e95c79261340071d376fe41fc3af
|
|
|
923a60 |
Resolves: #1292447
|
|
|
923a60 |
---
|
|
|
923a60 |
src/journal/journal-file.c | 12 +++++++-----
|
|
|
923a60 |
src/journal/journal-file.h | 5 +++++
|
|
|
923a60 |
2 files changed, 12 insertions(+), 5 deletions(-)
|
|
|
923a60 |
|
|
|
923a60 |
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
|
|
|
923a60 |
index f500568fec..a8f92e23a9 100644
|
|
|
923a60 |
--- a/src/journal/journal-file.c
|
|
|
923a60 |
+++ b/src/journal/journal-file.c
|
|
|
923a60 |
@@ -1051,23 +1051,25 @@ static int journal_file_append_data(
|
|
|
923a60 |
o->data.hash = htole64(hash);
|
|
|
923a60 |
|
|
|
923a60 |
#if defined(HAVE_XZ) || defined(HAVE_LZ4)
|
|
|
923a60 |
- if (f->compress_xz &&
|
|
|
923a60 |
- size >= COMPRESSION_SIZE_THRESHOLD) {
|
|
|
923a60 |
+ if (JOURNAL_FILE_COMPRESS(f) && size >= COMPRESSION_SIZE_THRESHOLD) {
|
|
|
923a60 |
size_t rsize;
|
|
|
923a60 |
|
|
|
923a60 |
compression = compress_blob(data, size, o->data.payload, &rsize);
|
|
|
923a60 |
|
|
|
923a60 |
- if (compression) {
|
|
|
923a60 |
+ if (compression >= 0) {
|
|
|
923a60 |
o->object.size = htole64(offsetof(Object, data.payload) + rsize);
|
|
|
923a60 |
o->object.flags |= compression;
|
|
|
923a60 |
|
|
|
923a60 |
log_debug("Compressed data object %"PRIu64" -> %zu using %s",
|
|
|
923a60 |
size, rsize, object_compressed_to_string(compression));
|
|
|
923a60 |
- }
|
|
|
923a60 |
+ } else
|
|
|
923a60 |
+ /* Compression didn't work, we don't really care why, let's continue without compression */
|
|
|
923a60 |
+ compression = 0;
|
|
|
923a60 |
+
|
|
|
923a60 |
}
|
|
|
923a60 |
#endif
|
|
|
923a60 |
|
|
|
923a60 |
- if (!compression && size > 0)
|
|
|
923a60 |
+ if (compression == 0 && size > 0)
|
|
|
923a60 |
memcpy(o->data.payload, data, size);
|
|
|
923a60 |
|
|
|
923a60 |
r = journal_file_link_data(f, o, p, hash);
|
|
|
923a60 |
diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h
|
|
|
923a60 |
index 403c8f760c..0f29b092b7 100644
|
|
|
923a60 |
--- a/src/journal/journal-file.h
|
|
|
923a60 |
+++ b/src/journal/journal-file.h
|
|
|
923a60 |
@@ -229,3 +229,8 @@ int journal_file_get_cutoff_realtime_usec(JournalFile *f, usec_t *from, usec_t *
|
|
|
923a60 |
int journal_file_get_cutoff_monotonic_usec(JournalFile *f, sd_id128_t boot, usec_t *from, usec_t *to);
|
|
|
923a60 |
|
|
|
923a60 |
bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec);
|
|
|
923a60 |
+
|
|
|
923a60 |
+static inline bool JOURNAL_FILE_COMPRESS(JournalFile *f) {
|
|
|
923a60 |
+ assert(f);
|
|
|
923a60 |
+ return f->compress_xz || f->compress_lz4;
|
|
|
923a60 |
+}
|