]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-file: journal-file: extend journal header to always carry offset of most...
authorLennart Poettering <lennart@poettering.net>
Tue, 31 Jan 2023 18:20:27 +0000 (19:20 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 2 Mar 2023 09:03:15 +0000 (10:03 +0100)
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.

docs/JOURNAL_FILE_FORMAT.md
src/libsystemd/sd-journal/journal-def.h
src/libsystemd/sd-journal/journal-file.c

index 712f3bce36deea6f828c646c3394d91e904b274a..ede9d923a489d28f6aacd3ecb9162f98f7acc9ed 100644 (file)
@@ -178,8 +178,10 @@ _packed_ struct Header {
         le64_t data_hash_chain_depth;
         le64_t field_hash_chain_depth;
         /* Added in 252 */
-        le32_t tail_entry_array_offset;                 \
-        le32_t tail_entry_array_n_entries;              \
+        le32_t tail_entry_array_offset;
+        le32_t tail_entry_array_n_entries;
+        /* Added in 254 */
+        le64_t tail_entry_offset;
 };
 ```
 
@@ -252,6 +254,9 @@ field hash table, minus one.
 **tail_entry_array_offset** and **tail_entry_array_n_entries** allow immediate
 access to the last entry array in the global entry array chain.
 
+**tail_entry_offset** allow immediate access to the last entry in the journal
+file.
+
 ## Extensibility
 
 The format is supposed to be extensible in order to enable future additions of
index fb22fc45f304e111eeaada8c5c782dd595ee27a8..2f048c0198091a12f51d367f78269a66e5e2623d 100644 (file)
@@ -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' })
index e6b31d4e7c022197b1d929231276bfd1325fb7b2..e92e351809c0ff5cb294834c48bafc58bae5fc6b 100644 (file)
@@ -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++) {