|
Zbigniew Jędrzejewski-Szmek |
03e93e |
From 9a9a2deb4b5c7dcd07ba64e1d01a21d00fbe08f3 Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
From: Lennart Poettering <lennart@poettering.net>
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
Date: Mon, 12 Dec 2016 20:54:45 +0100
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
Subject: [PATCH] journald: don't flush to /var/log/journal before we get asked
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
to
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
This changes journald to not write to /var/log/journal until it received
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
SIGUSR1 for the first time, thus having been requested to flush the runtime
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
journal to disk.
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
This makes the journal work nicer with systems which have the root file system
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
writable early, but still need to rearrange /var before journald should start
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
writing and creating files to it, for example because ACLs need to be applied
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
first, or because /var is to be mounted from another file system, NFS or tmpfs
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
(as is the case for systemd.volatile=state).
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
Before this change we required setupts with /var split out to mount the root
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
disk read-only early on, and ship an /etc/fstab that remounted it writable only
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
after having placed /var at the right place. But even that was racy for various
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
preparations as journald might end up accessing the file system before it was
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
entirely set up, as soon as it was writable.
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
With this change we make scheduling when to start writing to /var/log/journal
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
explicit. This means persistent mode now requires
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
systemd-journal-flush.service in the mix to work, as otherwise journald would
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
never write to the directory.
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
See: #1397
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
(cherry picked from commit f78273c8dacf678cc8fd7387f678e6344a99405c)
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
---
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
src/journal/journald-server.c | 21 +++++++++++----------
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
src/journal/journald-server.h | 2 +-
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
src/journal/journald.c | 2 +-
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
3 files changed, 13 insertions(+), 12 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
index 1d2fce8dc7..ced0ad6f21 100644
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
--- a/src/journal/journald-server.c
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+++ b/src/journal/journald-server.c
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
@@ -283,17 +283,16 @@ static int open_journal(
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
}
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
static bool flushed_flag_is_set(void) {
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
- return (access("/run/systemd/journal/flushed", F_OK) >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+ return access("/run/systemd/journal/flushed", F_OK) >= 0;
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
}
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
static int system_journal_open(Server *s, bool flush_requested) {
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
- bool flushed = false;
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
const char *fn;
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
int r = 0;
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
if (!s->system_journal &&
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
- (s->storage == STORAGE_PERSISTENT || s->storage == STORAGE_AUTO) &&
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
- (flush_requested || (flushed = flushed_flag_is_set()))) {
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+ IN_SET(s->storage, STORAGE_PERSISTENT, STORAGE_AUTO) &&
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+ (flush_requested || flushed_flag_is_set())) {
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
/* If in auto mode: first try to create the machine
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
* path, but not the prefix.
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
@@ -326,8 +325,8 @@ static int system_journal_open(Server *s, bool flush_requested) {
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
* Perform an implicit flush to var, leaving the runtime
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
* journal closed, now that the system journal is back.
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
*/
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
- if (s->runtime_journal && flushed)
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
- (void) server_flush_to_var(s);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+ if (!flush_requested)
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+ (void) server_flush_to_var(s, true);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
}
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
if (!s->runtime_journal &&
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
@@ -1183,7 +1182,7 @@ finish:
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
dispatch_message_real(s, iovec, n, m, ucred, tv, label, label_len, unit_id, priority, object_pid);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
}
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
-int server_flush_to_var(Server *s) {
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+int server_flush_to_var(Server *s, bool require_flag_file) {
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
sd_id128_t machine;
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
sd_journal *j = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
char ts[FORMAT_TIMESPAN_MAX];
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
@@ -1193,13 +1192,15 @@ int server_flush_to_var(Server *s) {
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
assert(s);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
- if (s->storage != STORAGE_AUTO &&
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
- s->storage != STORAGE_PERSISTENT)
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+ if (!IN_SET(s->storage, STORAGE_AUTO, STORAGE_PERSISTENT))
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
return 0;
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
if (!s->runtime_journal)
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
return 0;
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+ if (require_flag_file && !flushed_flag_is_set())
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+ return 0;
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
(void) system_journal_open(s, true);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
if (!s->system_journal)
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
@@ -1411,7 +1412,7 @@ static int dispatch_sigusr1(sd_event_source *es, const struct signalfd_siginfo *
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
log_info("Received request to flush runtime journal from PID " PID_FMT, si->ssi_pid);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
- (void) server_flush_to_var(s);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+ (void) server_flush_to_var(s, false);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
server_sync(s);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
server_vacuum(s, false);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
index 99d91496be..de1c48f805 100644
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
--- a/src/journal/journald-server.h
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+++ b/src/journal/journald-server.h
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
@@ -197,7 +197,7 @@ void server_sync(Server *s);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
int server_vacuum(Server *s, bool verbose);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
void server_rotate(Server *s);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
int server_schedule_sync(Server *s, int priority);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
-int server_flush_to_var(Server *s);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+int server_flush_to_var(Server *s, bool require_flag_file);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
void server_maybe_append_tags(Server *s);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
void server_space_usage_message(Server *s, JournalStorage *storage);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
diff --git a/src/journal/journald.c b/src/journal/journald.c
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
index 7f47ca22dd..9ac21457f6 100644
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
--- a/src/journal/journald.c
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+++ b/src/journal/journald.c
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
@@ -52,7 +52,7 @@ int main(int argc, char *argv[]) {
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
goto finish;
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
server_vacuum(&server, false);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
- server_flush_to_var(&server);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+ server_flush_to_var(&server, true);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
server_flush_dev_kmsg(&server);
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
log_debug("systemd-journald running as pid "PID_FMT, getpid());
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
--
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
2.9.3
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|