diff options
author | Michal Schmidt <mschmidt@redhat.com> | 2014-12-16 21:03:36 +0100 |
---|---|---|
committer | Michal Schmidt <mschmidt@redhat.com> | 2014-12-18 12:17:20 +0100 |
commit | 6573ef05a3cbe15949acfbbf1ad03726068907bd (patch) | |
tree | cb3d38ce419ba37de77b8cb358e82883573d8e22 /src/journal | |
parent | journal: abstract the resetting of JournalFile's location (diff) | |
download | systemd-6573ef05a3cbe15949acfbbf1ad03726068907bd.tar.xz systemd-6573ef05a3cbe15949acfbbf1ad03726068907bd.zip |
journal: keep per-JournalFile location info during iteration
In next_beyond_location() when we find a candidate entry in a journal
file, save its location information in struct JournalFile.
The purpose of remembering the locations of candidate entries is to be
able to save work in the next iteration. This patch does only the
remembering part.
LOCATION_SEEK means the location identifies a candidate entry.
When a winner is picked from among candidates, it becomes
LOCATION_DISCRETE.
LOCATION_TAIL here signifies we've iterated the file to the end (or the
beginning in the case of reversed direction).
Diffstat (limited to 'src/journal')
-rw-r--r-- | src/journal/journal-file.c | 17 | ||||
-rw-r--r-- | src/journal/journal-file.h | 7 | ||||
-rw-r--r-- | src/journal/sd-journal.c | 10 |
3 files changed, 33 insertions, 1 deletions
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 8cbdbb9f96..7b9815c69f 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -1929,7 +1929,24 @@ int journal_file_move_to_entry_by_monotonic( } void journal_file_reset_location(JournalFile *f) { + f->location_type = LOCATION_HEAD; f->current_offset = 0; + f->current_seqnum = 0; + f->current_realtime = 0; + f->current_monotonic = 0; + zero(f->current_boot_id); + f->current_xor_hash = 0; +} + +void journal_file_save_location(JournalFile *f, direction_t direction, Object *o, uint64_t offset) { + f->last_direction = direction; + f->location_type = LOCATION_SEEK; + f->current_offset = offset; + f->current_seqnum = le64toh(o->entry.seqnum); + f->current_realtime = le64toh(o->entry.realtime); + f->current_monotonic = le64toh(o->entry.monotonic); + f->current_boot_id = o->entry.boot_id; + f->current_xor_hash = le64toh(o->entry.xor_hash); } int journal_file_next_entry( diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h index 3a19827fb7..2bdfff782e 100644 --- a/src/journal/journal-file.h +++ b/src/journal/journal-file.h @@ -77,6 +77,7 @@ typedef struct JournalFile { bool tail_entry_monotonic_valid:1; direction_t last_direction; + LocationType location_type; char *path; struct stat last_stat; @@ -86,6 +87,11 @@ typedef struct JournalFile { HashItem *field_hash_table; uint64_t current_offset; + uint64_t current_seqnum; + uint64_t current_realtime; + uint64_t current_monotonic; + sd_id128_t current_boot_id; + uint64_t current_xor_hash; JournalMetrics metrics; MMapCache *mmap; @@ -190,6 +196,7 @@ int journal_file_find_field_object(JournalFile *f, const void *field, uint64_t s int journal_file_find_field_object_with_hash(JournalFile *f, const void *field, uint64_t size, uint64_t hash, Object **ret, uint64_t *offset); void journal_file_reset_location(JournalFile *f); +void journal_file_save_location(JournalFile *f, direction_t direction, Object *o, uint64_t offset); int journal_file_next_entry(JournalFile *f, Object *o, uint64_t p, direction_t direction, Object **ret, uint64_t *offset); int journal_file_next_entry_for_data(JournalFile *f, Object *o, uint64_t p, uint64_t data_offset, direction_t direction, Object **ret, uint64_t *offset); diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index adaf402f46..71b056c234 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -128,6 +128,10 @@ static void set_location(sd_journal *j, LocationType type, JournalFile *f, Objec f->last_direction = direction; f->current_offset = offset; + + /* Let f know its candidate entry was picked. */ + assert(f->location_type == LOCATION_SEEK); + f->location_type = LOCATION_DISCRETE; } static int match_is_valid(const void *data, size_t size) { @@ -855,6 +859,8 @@ static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direc found = true; if (found) { + journal_file_save_location(f, direction, c, cp); + if (ret) *ret = c; if (offset) @@ -887,8 +893,10 @@ static int real_journal_next(sd_journal *j, direction_t direction) { log_debug_errno(r, "Can't iterate through %s, ignoring: %m", f->path); remove_file_real(j, f); continue; - } else if (r == 0) + } else if (r == 0) { + f->location_type = LOCATION_TAIL; continue; + } if (!new_file) found = true; |