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