diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-10-25 00:14:51 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-10-25 00:14:51 -0400 |
commit | 8e0dfb6b8e7a0933c14ded7348e7b778a603aa37 (patch) | |
tree | dc277c14a8f76ebe851aad252baa1c6d09dc1259 /src/journal | |
parent | 0c0f1bc8f76dadb6ccaf89e8df778188503a56cf (diff) | |
parent | 0240c603691e006165d8687d6a2c70859755b11f (diff) |
Merge pull request #1663 from poettering/journal-compress-fix
journal: fix error handling when compressing journal objects
Diffstat (limited to 'src/journal')
-rw-r--r-- | src/journal/compress.c | 9 | ||||
-rw-r--r-- | src/journal/journal-file.c | 13 | ||||
-rw-r--r-- | src/journal/journal-file.h | 5 |
3 files changed, 17 insertions, 10 deletions
diff --git a/src/journal/compress.c b/src/journal/compress.c index 8c92e26edd..fb40bed594 100644 --- a/src/journal/compress.c +++ b/src/journal/compress.c @@ -57,10 +57,11 @@ int compress_blob_xz(const void *src, uint64_t src_size, void *dst, size_t *dst_ #ifdef HAVE_XZ static const lzma_options_lzma opt = { 1u << 20u, NULL, 0, LZMA_LC_DEFAULT, LZMA_LP_DEFAULT, - LZMA_PB_DEFAULT, LZMA_MODE_FAST, 128, LZMA_MF_HC3, 4}; - static const lzma_filter filters[2] = { - {LZMA_FILTER_LZMA2, (lzma_options_lzma*) &opt}, - {LZMA_VLI_UNKNOWN, NULL} + LZMA_PB_DEFAULT, LZMA_MODE_FAST, 128, LZMA_MF_HC3, 4 + }; + static const lzma_filter filters[] = { + { LZMA_FILTER_LZMA2, (lzma_options_lzma*) &opt }, + { LZMA_VLI_UNKNOWN, NULL } }; lzma_ret ret; size_t out_pos = 0; diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 1071c6d6d7..fadc0e4286 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -1057,7 +1057,7 @@ static int journal_file_append_data( r = journal_file_find_data_object_with_hash(f, data, size, hash, &o, &p); if (r < 0) return r; - else if (r > 0) { + if (r > 0) { if (ret) *ret = o; @@ -1076,23 +1076,24 @@ static int journal_file_append_data( o->data.hash = htole64(hash); #if defined(HAVE_XZ) || defined(HAVE_LZ4) - if (f->compress_xz && - size >= COMPRESSION_SIZE_THRESHOLD) { + if (JOURNAL_FILE_COMPRESS(f) && size >= COMPRESSION_SIZE_THRESHOLD) { size_t rsize = 0; compression = compress_blob(data, size, o->data.payload, &rsize); - if (compression) { + if (compression >= 0) { o->object.size = htole64(offsetof(Object, data.payload) + rsize); o->object.flags |= compression; log_debug("Compressed data object %"PRIu64" -> %zu using %s", size, rsize, object_compressed_to_string(compression)); - } + } else + /* Compression didn't work, we don't really care why, let's continue without compression */ + compression = 0; } #endif - if (!compression && size > 0) + if (compression == 0 && size > 0) memcpy(o->data.payload, data, size); r = journal_file_link_data(f, o, p, hash); diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h index f2c07356c8..898d12d992 100644 --- a/src/journal/journal-file.h +++ b/src/journal/journal-file.h @@ -235,3 +235,8 @@ bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec); 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) { + assert(f); + return f->compress_xz || f->compress_lz4; +} |