diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-01-31 19:20:27 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-03-02 10:03:15 +0100 |
commit | 206f0f397edf1144c63a158fb30f496c3e89f256 (patch) | |
tree | d16777bd74b799acc0440efdf15cfe70869b8f47 /src | |
parent | 7a67afe33192ce4a55e6825b80554fb4ebbb4b03 (diff) | |
download | systemd-206f0f397edf1144c63a158fb30f496c3e89f256.tar.gz |
journal-file: journal-file: extend journal header to always carry offset of most recent entry
This way we can quickly find the most recent entry, without searching or
traversing entry array chains.
This is relevant later, as it it allows us to quickly determine the most
recent timestamps of each journal file, in a roughly atomic way.
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd/sd-journal/journal-def.h | 4 | ||||
-rw-r--r-- | src/libsystemd/sd-journal/journal-file.c | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/libsystemd/sd-journal/journal-def.h b/src/libsystemd/sd-journal/journal-def.h index fb22fc45f3..2f048c0198 100644 --- a/src/libsystemd/sd-journal/journal-def.h +++ b/src/libsystemd/sd-journal/journal-def.h @@ -239,12 +239,14 @@ enum { /* Added in 252 */ \ le32_t tail_entry_array_offset; \ le32_t tail_entry_array_n_entries; \ + /* Added in 254 */ \ + le64_t tail_entry_offset; \ } struct Header struct_Header__contents; struct Header__packed struct_Header__contents _packed_; assert_cc(sizeof(struct Header) == sizeof(struct Header__packed)); -assert_cc(sizeof(struct Header) == 264); +assert_cc(sizeof(struct Header) == 272); #define FSS_HEADER_SIGNATURE \ ((const char[]) { 'K', 'S', 'H', 'H', 'R', 'H', 'L', 'P' }) diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index e6b31d4e7c..e92e351809 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -505,6 +505,11 @@ static int journal_file_verify_header(JournalFile *f) { !VALID64(le64toh(f->header->entry_array_offset))) return -ENODATA; + if (JOURNAL_HEADER_CONTAINS(f->header, tail_entry_offset) && + le64toh(f->header->tail_entry_offset) != 0 && + !VALID64(le64toh(f->header->tail_entry_offset))) + return -ENODATA; + if (journal_file_writable(f)) { sd_id128_t machine_id; uint8_t state; @@ -2053,6 +2058,7 @@ static int journal_file_link_entry( f->header->tail_entry_realtime = o->entry.realtime; f->header->tail_entry_monotonic = o->entry.monotonic; + f->header->tail_entry_offset = offset; /* Link up the items */ for (uint64_t i = 0; i < n_items; i++) { |