chiark / gitweb /
journal: store XOR combination of entry data object hashes to identify hash lines
authorLennart Poettering <lennart@poettering.net>
Fri, 7 Oct 2011 19:56:11 +0000 (21:56 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 7 Oct 2011 20:02:06 +0000 (22:02 +0200)
src/journal/journal-def.h
src/journal/sd-journal.c

index 0d865ae..2a519fe 100644 (file)
@@ -74,6 +74,7 @@ _packed_ struct EntryObject {
         uint64_t seqnum;
         uint64_t realtime;
         uint64_t monotonic;
         uint64_t seqnum;
         uint64_t realtime;
         uint64_t monotonic;
+        uint64_t xor_hash;
         uint64_t prev_entry_offset;
         uint64_t next_entry_offset;
         EntryItem items[];
         uint64_t prev_entry_offset;
         uint64_t next_entry_offset;
         EntryItem items[];
index f1dd929..d49f717 100644 (file)
@@ -758,7 +758,12 @@ static int journal_file_link_entry(JournalFile *f, Object *o, uint64_t offset) {
         return 0;
 }
 
         return 0;
 }
 
-static int journal_file_append_entry_internal(JournalFile *f, const dual_timestamp *ts, const EntryItem items[], unsigned n_items, Object **ret, uint64_t *offset) {
+static int journal_file_append_entry_internal(
+                JournalFile *f,
+                const dual_timestamp *ts,
+                uint64_t xor_hash,
+                const EntryItem items[], unsigned n_items,
+                Object **ret, uint64_t *offset) {
         uint64_t np;
         uint64_t osize;
         Object *o;
         uint64_t np;
         uint64_t osize;
         Object *o;
@@ -776,8 +781,9 @@ static int journal_file_append_entry_internal(JournalFile *f, const dual_timesta
         o->object.type = htole64(OBJECT_ENTRY);
         o->entry.seqnum = htole64(journal_file_seqnum(f));
         memcpy(o->entry.items, items, n_items * sizeof(EntryItem));
         o->object.type = htole64(OBJECT_ENTRY);
         o->entry.seqnum = htole64(journal_file_seqnum(f));
         memcpy(o->entry.items, items, n_items * sizeof(EntryItem));
-        o->entry.realtime = htole64(ts->realtime);
-        o->entry.monotonic = htole64(ts->monotonic);
+        o->entry.realtime = ts ? htole64(ts->realtime) : 0;
+        o->entry.monotonic = ts ? htole64(ts->monotonic) : 0;
+        o->entry.xor_hash = htole64(xor_hash);
 
         r = journal_file_link_entry(f, o, np);
         if (r < 0)
 
         r = journal_file_link_entry(f, o, np);
         if (r < 0)
@@ -796,8 +802,10 @@ int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const st
         unsigned i;
         EntryItem *items;
         int r;
         unsigned i;
         EntryItem *items;
         int r;
+        uint64_t xor_hash = 0;
 
         assert(f);
 
         assert(f);
+        assert(iovec || n_iovec == 0);
 
         items = new(EntryItem, n_iovec);
         if (!items)
 
         items = new(EntryItem, n_iovec);
         if (!items)
@@ -805,15 +813,17 @@ int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const st
 
         for (i = 0; i < n_iovec; i++) {
                 uint64_t p;
 
         for (i = 0; i < n_iovec; i++) {
                 uint64_t p;
+                Object *o;
 
 
-                r = journal_file_append_data(f, iovec[i].iov_base, iovec[i].iov_len, NULL, &p);
+                r = journal_file_append_data(f, iovec[i].iov_base, iovec[i].iov_len, &o, &p);
                 if (r < 0)
                         goto finish;
 
                 if (r < 0)
                         goto finish;
 
+                xor_hash ^= le64toh(o->data.hash);
                 items[i].object_offset = htole64(p);
         }
 
                 items[i].object_offset = htole64(p);
         }
 
-        r = journal_file_append_entry_internal(f, ts, items, n_iovec, ret, offset);
+        r = journal_file_append_entry_internal(f, ts, xor_hash, items, n_iovec, ret, offset);
 
 finish:
         free(items);
 
 finish:
         free(items);