systemd/0001-journal-set-STATE_ARCHIVED-as-part-of-offlining-2740.patch
Franck Bui 35fc3cae4d - Added patches to fix journal with FSS protection enabled (bsc#1000435)
0001-journal-fix-HMAC-calculation-when-appending-a-data-o.patch
   0001-journal-set-STATE_ARCHIVED-as-part-of-offlining-2740.patch
   0001-journal-warn-when-we-fail-to-append-a-tag-to-a-journ.patch

OBS-URL: https://build.opensuse.org/package/show/Base:System/systemd?expand=0&rev=952
2016-09-26 09:11:19 +00:00

94 lines
3.9 KiB
Diff

From 0d0bad044f8f19c472acb69d10861a66d3d267b6 Mon Sep 17 00:00:00 2001
From: Vito Caputo <vcaputo@gnugeneration.com>
Date: Tue, 26 Apr 2016 23:29:43 -0700
Subject: [PATCH 1/1] journal: set STATE_ARCHIVED as part of offlining (#2740)
The only code path which makes a journal durable is via
journal_file_set_offline().
When we perform a rotate the journal's header->state is being set to
STATE_ARCHIVED prior to journal_file_set_offline() being called.
In journal_file_set_offline(), we short-circuit the entire offline when
f->header->state != STATE_ONLINE.
This all results in none of the journal_file_set_offline() fsync() calls
being reached when rotate archives a journal, so archived journals are
never explicitly made durable.
What we do now is instead of setting the f->header->state to
STATE_ARCHIVED directly in journal_file_rotate() prior to
journal_file_close(), we set an archive flag in f->archive for the
journal_file_set_offline() machinery to honor by committing
STATE_ARCHIVED instead of STATE_OFFLINE when set.
Prior to this, rotated journals were never getting fsync() explicitly
performed on them, since journal_file_set_offline() short-circuited.
Obviously this is undesirable, and depends entirely on the underlying
filesystem as to how much durability was achieved when simply closing
the file.
Note that this problem existed prior to the recent asynchronous fsync
changes, but those changes do facilitate our performing this durable
offline on rotate without blocking, regardless of the underlying
filesystem sync-on-close semantics.
(cherry picked from commit 8eb851711fd166024297c425e9261200c36f489d)
[fbui: context adjustment: the asynchronous journal_file_set_offline()
thingie doesn't exist in v228]
[fbui: this also fixes the case when we wanted to append a tag (for
FSS verification) when closing the journal. Before this patch,
journal_file_append_tag() failed (silently) because re-opening
the journal to write the tag was not possible since it was
already in "archived" mode.]
---
src/journal/journal-file.c | 10 ++++++++--
src/journal/journal-file.h | 1 +
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index f9ff954..e7eecad 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -130,7 +130,7 @@ int journal_file_set_offline(JournalFile *f) {
if (mmap_cache_got_sigbus(f->mmap, f->fd))
return -EIO;
- f->header->state = STATE_OFFLINE;
+ f->header->state = f->archive ? STATE_ARCHIVED : STATE_OFFLINE;
if (mmap_cache_got_sigbus(f->mmap, f->fd))
return -EIO;
@@ -2813,7 +2813,13 @@ int journal_file_rotate(JournalFile **f, bool compress, bool seal) {
if (r < 0 && errno != ENOENT)
return -errno;
- old_file->header->state = STATE_ARCHIVED;
+ /* Set as archive so offlining commits w/state=STATE_ARCHIVED.
+ * Previously we would set old_file->header->state to STATE_ARCHIVED directly here,
+ * but journal_file_set_offline() short-circuits when state != STATE_ONLINE, which
+ * would result in the rotated journal never getting fsync() called before closing.
+ * Now we simply queue the archive state by setting an archive bit, leaving the state
+ * as STATE_ONLINE so proper offlining occurs. */
+ old_file->archive = true;
/* Currently, btrfs is not very good with out write patterns
* and fragments heavily. Let's defrag our journal files when
diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h
index 898d12d..436e5ff 100644
--- a/src/journal/journal-file.h
+++ b/src/journal/journal-file.h
@@ -76,6 +76,7 @@ typedef struct JournalFile {
bool compress_lz4:1;
bool seal:1;
bool defrag_on_close:1;
+ bool archive:1;
bool tail_entry_monotonic_valid:1;
--
2.10.0