chiark / gitweb /
journal: abstract the resetting of JournalFile's location
[elogind.git] / src / journal / sd-journal.c
index 5e2da9912632f41049c5ee779c9a60379aafe353..adaf402f46ced2781f32b590444dd80f390b6c27 100644 (file)
@@ -87,7 +87,7 @@ static void detach_location(sd_journal *j) {
         j->current_field = 0;
 
         ORDERED_HASHMAP_FOREACH(f, j->files, i)
-                f->current_offset = 0;
+                journal_file_reset_location(f);
 }
 
 static void reset_location(sd_journal *j) {
@@ -497,47 +497,6 @@ static int compare_entry_order(JournalFile *af, Object *_ao,
         return 0;
 }
 
-static bool whole_file_precedes_location(JournalFile *f, Location *l, direction_t direction) {
-        assert(f);
-        assert(l);
-
-        if (l->type != LOCATION_DISCRETE && l->type != LOCATION_SEEK)
-                return false;
-
-        if (l->seqnum_set && sd_id128_equal(l->seqnum_id, f->header->seqnum_id))
-                return direction == DIRECTION_DOWN ?
-                        l->seqnum > le64toh(f->header->tail_entry_seqnum) :
-                        l->seqnum < le64toh(f->header->head_entry_seqnum);
-
-        if (l->realtime_set)
-                return direction == DIRECTION_DOWN ?
-                        l->realtime > le64toh(f->header->tail_entry_realtime) :
-                        l->realtime < le64toh(f->header->head_entry_realtime);
-
-        return false;
-}
-
-static bool file_may_have_preceding_entry(JournalFile *f, JournalFile *of, uint64_t op, direction_t direction) {
-        Object *o;
-        int r;
-
-        assert(f);
-        assert(of);
-
-        r = journal_file_move_to_object(of, OBJECT_ENTRY, op, &o);
-        if (r < 0)
-                return true;
-
-        if (sd_id128_equal(f->header->seqnum_id, of->header->seqnum_id))
-                return direction == DIRECTION_DOWN ?
-                        le64toh(o->entry.seqnum) >= le64toh(f->header->head_entry_seqnum) :
-                        le64toh(o->entry.seqnum) <= le64toh(f->header->tail_entry_seqnum);
-
-        return direction == DIRECTION_DOWN ?
-                le64toh(o->entry.realtime) >= le64toh(f->header->head_entry_realtime) :
-                le64toh(o->entry.realtime) <= le64toh(f->header->tail_entry_realtime);
-}
-
 _pure_ static int compare_with_location(JournalFile *af, Object *ao, Location *l) {
         uint64_t a;
 
@@ -923,12 +882,6 @@ static int real_journal_next(sd_journal *j, direction_t direction) {
         ORDERED_HASHMAP_FOREACH(f, j->files, i) {
                 bool found;
 
-                if (whole_file_precedes_location(f, &j->current_location, direction))
-                        continue;
-
-                if (new_file && !file_may_have_preceding_entry(f, new_file, new_offset, direction))
-                        continue;
-
                 r = next_beyond_location(j, f, direction, &o, &p);
                 if (r < 0) {
                         log_debug_errno(r, "Can't iterate through %s, ignoring: %m", f->path);
@@ -2320,7 +2273,6 @@ static int determine_change(sd_journal *j) {
 }
 
 _public_ int sd_journal_process(sd_journal *j) {
-        uint8_t buffer[sizeof(struct inotify_event) + FILENAME_MAX] _alignas_(struct inotify_event);
         bool got_something = false;
 
         assert_return(j, -EINVAL);
@@ -2329,6 +2281,7 @@ _public_ int sd_journal_process(sd_journal *j) {
         j->last_process_usec = now(CLOCK_MONOTONIC);
 
         for (;;) {
+                uint8_t buffer[INOTIFY_EVENT_MAX] _alignas_(struct inotify_event);
                 struct inotify_event *e;
                 ssize_t l;
 
@@ -2342,18 +2295,8 @@ _public_ int sd_journal_process(sd_journal *j) {
 
                 got_something = true;
 
-                e = (struct inotify_event*) buffer;
-                while (l > 0) {
-                        size_t step;
-
+                FOREACH_INOTIFY_EVENT(e, buffer, l)
                         process_inotify_event(j, e);
-
-                        step = sizeof(struct inotify_event) + e->len;
-                        assert(step <= (size_t) l);
-
-                        e = (struct inotify_event*) ((uint8_t*) e + step);
-                        l -= step;
-                }
         }
 }
 
@@ -2573,7 +2516,6 @@ _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_
                 size_t ol;
                 bool found;
                 int r;
-                void *release_cookie;
 
                 /* Proceed to next data object in the field's linked list */
                 if (j->unique_offset == 0) {
@@ -2599,10 +2541,10 @@ _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_
                         continue;
                 }
 
-                /* We do not use the type context here, but 0 instead,
-                 * so that we can look at this data object at the same
+                /* We do not use OBJECT_DATA context here, but OBJECT_UNUSED
+                 * instead, so that we can look at this data object at the same
                  * time as one on another file */
-                r = journal_file_move_to_object(j->unique_file, 0, j->unique_offset, &o);
+                r = journal_file_move_to_object(j->unique_file, OBJECT_UNUSED, j->unique_offset, &o);
                 if (r < 0)
                         return r;
 
@@ -2614,10 +2556,6 @@ _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_
                         return -EBADMSG;
                 }
 
-                r = journal_file_object_keep(j->unique_file, o, j->unique_offset, &release_cookie);
-                if (r < 0)
-                        return r;
-
                 r = return_data(j, j->unique_file, o, &odata, &ol);
                 if (r < 0)
                         return r;
@@ -2662,10 +2600,6 @@ _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_
                                 found = true;
                 }
 
-                r = journal_file_object_release(j->unique_file, release_cookie);
-                if (r < 0)
-                        return r;
-
                 if (found)
                         continue;