From e5d60d1b3b0c0b229571823c7fdd390a9562982e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 23 Jan 2023 21:21:21 +0100 Subject: journald: maintain entry seqnum counter in mmap()ed file in /run/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's ensure that entry seqnums remain stable and monotonic across the entire runtime of the system, even if local storage is turned off. Let's do this by maintainer a counter file in /run/ which we mmap() and wherein we maintain the counter from early-boot on till late shutdown. This takes inspiration of the kernel-seqnum file we already maintain like that that tracks which kmsg messages we already processed. In fact, we reuse the same code for maintaining it. This should allow the behaviour entry seqnums to be more predictable, in particular when journal local storage is turned off. Previously, we'd maintain the seqnum simply by always bumping it to the maximum of the last written entry seqnum plus one, and the biggest seqnum so far written to the journal file on disk. If we'd never write a file on disk, or if no journal file was existing during the initrd→seqnum transition we'd completely lose the current seqnum position during daemon restarts (such as the one happening during the switch-root operation). This also will cause a journal file rotation whenever we try to write to a journal file with multiple sequence number IDs, so that we know that from early boot trhough the entire runtime we'll have stable sequence numbers that do not jump, and thus can be used to determine "lost" messages. --- src/journal-remote/journal-remote-write.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/journal-remote') diff --git a/src/journal-remote/journal-remote-write.c b/src/journal-remote/journal-remote-write.c index f6c3d83732..ace4a1cfad 100644 --- a/src/journal-remote/journal-remote-write.c +++ b/src/journal-remote/journal-remote-write.c @@ -99,9 +99,16 @@ int writer_write(Writer *w, return r; } - r = journal_file_append_entry(w->journal->file, ts, boot_id, - iovw->iovec, iovw->count, - &w->seqnum, NULL, NULL); + r = journal_file_append_entry( + w->journal->file, + ts, + boot_id, + iovw->iovec, + iovw->count, + &w->seqnum, + /* seqnum_id= */ NULL, + /* ret_object= */ NULL, + /* ret_offset= */ NULL); if (r >= 0) { if (w->server) w->server->event_count += 1; @@ -120,9 +127,15 @@ int writer_write(Writer *w, return r; log_debug("Retrying write."); - r = journal_file_append_entry(w->journal->file, ts, boot_id, - iovw->iovec, iovw->count, - &w->seqnum, NULL, NULL); + r = journal_file_append_entry( + w->journal->file, + ts, + boot_id, + iovw->iovec, iovw->count, + &w->seqnum, + /* seqnum_id= */ NULL, + /* ret_object= */ NULL, + /* ret_offset= */ NULL); if (r < 0) return r; -- cgit v1.2.1