summaryrefslogtreecommitdiff
path: root/src/journal/journal-file.c
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2014-12-17 14:06:28 +0100
committerMichal Schmidt <mschmidt@redhat.com>2014-12-18 12:26:00 +0100
commitd8ae66d7faee23a74a69119270bf622100705f72 (patch)
tree356d0423a16d760c6b7f914f4d2b83207d30967c /src/journal/journal-file.c
parent1eb6332d557e6e510a9ce723296cb3b658d7e9a4 (diff)
journal: compare candidate entries using JournalFiles' locations
When comparing the locations of candidate entries, we can rely on the location information stored in struct JournalFile.
Diffstat (limited to 'src/journal/journal-file.c')
-rw-r--r--src/journal/journal-file.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 7b9815c69f..35f3ea92a4 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -1949,6 +1949,58 @@ void journal_file_save_location(JournalFile *f, direction_t direction, Object *o
f->current_xor_hash = le64toh(o->entry.xor_hash);
}
+int journal_file_compare_locations(JournalFile *af, JournalFile *bf) {
+ assert(af);
+ assert(bf);
+ assert(af->location_type == LOCATION_SEEK);
+ assert(bf->location_type == LOCATION_SEEK);
+
+ /* If contents and timestamps match, these entries are
+ * identical, even if the seqnum does not match */
+ if (sd_id128_equal(af->current_boot_id, bf->current_boot_id) &&
+ af->current_monotonic == bf->current_monotonic &&
+ af->current_realtime == bf->current_realtime &&
+ af->current_xor_hash == bf->current_xor_hash)
+ return 0;
+
+ if (sd_id128_equal(af->header->seqnum_id, bf->header->seqnum_id)) {
+
+ /* If this is from the same seqnum source, compare
+ * seqnums */
+ if (af->current_seqnum < bf->current_seqnum)
+ return -1;
+ if (af->current_seqnum > bf->current_seqnum)
+ return 1;
+
+ /* Wow! This is weird, different data but the same
+ * seqnums? Something is borked, but let's make the
+ * best of it and compare by time. */
+ }
+
+ if (sd_id128_equal(af->current_boot_id, bf->current_boot_id)) {
+
+ /* If the boot id matches, compare monotonic time */
+ if (af->current_monotonic < bf->current_monotonic)
+ return -1;
+ if (af->current_monotonic > bf->current_monotonic)
+ return 1;
+ }
+
+ /* Otherwise, compare UTC time */
+ if (af->current_realtime < bf->current_realtime)
+ return -1;
+ if (af->current_realtime > bf->current_realtime)
+ return 1;
+
+ /* Finally, compare by contents */
+ if (af->current_xor_hash < bf->current_xor_hash)
+ return -1;
+ if (af->current_xor_hash > bf->current_xor_hash)
+ return 1;
+
+ return 0;
+}
+
int journal_file_next_entry(
JournalFile *f,
Object *o, uint64_t p,