mirror of
https://github.com/systemd/systemd.git
synced 2024-10-29 21:55:36 +03:00
journal: move journal_file_compare_locations() from journal-file.c → sd-journal.c
It's only used from sd-journal.c, and we soon would like to pass in an sd_journal object, hence let's move this over. This only moves code, doesn't change behaviour
This commit is contained in:
parent
d59025698f
commit
01e4f03f34
@ -3193,56 +3193,6 @@ void journal_file_save_location(JournalFile *f, Object *o, uint64_t offset) {
|
|||||||
f->current_xor_hash = le64toh(o->entry.xor_hash);
|
f->current_xor_hash = le64toh(o->entry.xor_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
int journal_file_compare_locations(JournalFile *af, JournalFile *bf) {
|
|
||||||
int r;
|
|
||||||
|
|
||||||
assert(af);
|
|
||||||
assert(af->header);
|
|
||||||
assert(bf);
|
|
||||||
assert(bf->header);
|
|
||||||
assert(af->location_type == LOCATION_SEEK);
|
|
||||||
assert(bf->location_type == LOCATION_SEEK);
|
|
||||||
|
|
||||||
/* If contents, timestamps and seqnum match, these entries are
|
|
||||||
* identical. */
|
|
||||||
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 &&
|
|
||||||
sd_id128_equal(af->header->seqnum_id, bf->header->seqnum_id) &&
|
|
||||||
af->current_seqnum == bf->current_seqnum)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (sd_id128_equal(af->header->seqnum_id, bf->header->seqnum_id)) {
|
|
||||||
|
|
||||||
/* If this is from the same seqnum source, compare
|
|
||||||
* seqnums */
|
|
||||||
r = CMP(af->current_seqnum, bf->current_seqnum);
|
|
||||||
if (r != 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
/* 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 */
|
|
||||||
r = CMP(af->current_monotonic, bf->current_monotonic);
|
|
||||||
if (r != 0)
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Otherwise, compare UTC time */
|
|
||||||
r = CMP(af->current_realtime, bf->current_realtime);
|
|
||||||
if (r != 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
/* Finally, compare by contents */
|
|
||||||
return CMP(af->current_xor_hash, bf->current_xor_hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool check_properly_ordered(uint64_t new_offset, uint64_t old_offset, direction_t direction) {
|
static bool check_properly_ordered(uint64_t new_offset, uint64_t old_offset, direction_t direction) {
|
||||||
|
|
||||||
/* Consider it an error if any of the two offsets is uninitialized */
|
/* Consider it an error if any of the two offsets is uninitialized */
|
||||||
|
@ -275,7 +275,6 @@ int journal_file_find_field_object_with_hash(JournalFile *f, const void *field,
|
|||||||
|
|
||||||
void journal_file_reset_location(JournalFile *f);
|
void journal_file_reset_location(JournalFile *f);
|
||||||
void journal_file_save_location(JournalFile *f, Object *o, uint64_t offset);
|
void journal_file_save_location(JournalFile *f, Object *o, uint64_t offset);
|
||||||
int journal_file_compare_locations(JournalFile *af, JournalFile *bf);
|
|
||||||
int journal_file_next_entry(JournalFile *f, uint64_t p, direction_t direction, Object **ret_object, uint64_t *ret_offset);
|
int journal_file_next_entry(JournalFile *f, uint64_t p, direction_t direction, Object **ret_object, uint64_t *ret_offset);
|
||||||
|
|
||||||
int journal_file_next_entry_for_data(JournalFile *f, Object *d, direction_t direction, Object **ret_object, uint64_t *ret_offset);
|
int journal_file_next_entry_for_data(JournalFile *f, Object *d, direction_t direction, Object **ret_object, uint64_t *ret_offset);
|
||||||
|
@ -801,6 +801,51 @@ static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int compare_locations(JournalFile *af, JournalFile *bf) {
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(af);
|
||||||
|
assert(af->header);
|
||||||
|
assert(bf);
|
||||||
|
assert(bf->header);
|
||||||
|
assert(af->location_type == LOCATION_SEEK);
|
||||||
|
assert(bf->location_type == LOCATION_SEEK);
|
||||||
|
|
||||||
|
/* If contents, timestamps and seqnum match, these entries are identical. */
|
||||||
|
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 &&
|
||||||
|
sd_id128_equal(af->header->seqnum_id, bf->header->seqnum_id) &&
|
||||||
|
af->current_seqnum == bf->current_seqnum)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (sd_id128_equal(af->header->seqnum_id, bf->header->seqnum_id)) {
|
||||||
|
/* If this is from the same seqnum source, compare seqnums */
|
||||||
|
r = CMP(af->current_seqnum, bf->current_seqnum);
|
||||||
|
if (r != 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
|
r = CMP(af->current_monotonic, bf->current_monotonic);
|
||||||
|
if (r != 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Otherwise, compare UTC time */
|
||||||
|
r = CMP(af->current_realtime, bf->current_realtime);
|
||||||
|
if (r != 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
/* Finally, compare by contents */
|
||||||
|
return CMP(af->current_xor_hash, bf->current_xor_hash);
|
||||||
|
}
|
||||||
|
|
||||||
static int real_journal_next(sd_journal *j, direction_t direction) {
|
static int real_journal_next(sd_journal *j, direction_t direction) {
|
||||||
JournalFile *new_file = NULL;
|
JournalFile *new_file = NULL;
|
||||||
unsigned n_files;
|
unsigned n_files;
|
||||||
@ -834,7 +879,7 @@ static int real_journal_next(sd_journal *j, direction_t direction) {
|
|||||||
else {
|
else {
|
||||||
int k;
|
int k;
|
||||||
|
|
||||||
k = journal_file_compare_locations(f, new_file);
|
k = compare_locations(f, new_file);
|
||||||
|
|
||||||
found = direction == DIRECTION_DOWN ? k < 0 : k > 0;
|
found = direction == DIRECTION_DOWN ? k < 0 : k > 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user