teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame 0002-journal-remember-last-direction-of-search-and-keep-o.patch

Harald Hoyer 670c70
From 87011c25d96e9fbcd8a465ba758fa037c7d08203 Mon Sep 17 00:00:00 2001
Harald Hoyer 670c70
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Harald Hoyer 670c70
Date: Thu, 6 Jun 2013 22:28:05 -0400
Harald Hoyer 670c70
Subject: [PATCH 01/13] journal: remember last direction of search and keep
Harald Hoyer 670c70
 offset cache
Harald Hoyer 670c70
Harald Hoyer 670c70
The fields in JournalFile are moved around to avoid wasting
Harald Hoyer 670c70
7 bytes because of alignment.
Harald Hoyer 670c70
---
Harald Hoyer 670c70
 TODO                       |  3 ---
Harald Hoyer 670c70
 src/journal/journal-file.h | 18 +++++++++++-------
Harald Hoyer 670c70
 src/journal/sd-journal.c   | 11 +++++------
Harald Hoyer 670c70
 3 files changed, 16 insertions(+), 16 deletions(-)
Harald Hoyer 670c70
Harald Hoyer 670c70
diff --git a/TODO b/TODO
Harald Hoyer 670c70
index 0dd19a0..1dc585c 100644
Harald Hoyer 670c70
--- a/TODO
Harald Hoyer 670c70
+++ b/TODO
Harald Hoyer 670c70
@@ -77,9 +77,6 @@ Features:
Harald Hoyer 670c70
 
Harald Hoyer 670c70
 * investigate endianess issues of UUID vs. GUID
Harald Hoyer 670c70
 
Harald Hoyer 670c70
-* see if we can fix https://bugs.freedesktop.org/show_bug.cgi?id=63672
Harald Hoyer 670c70
-  without dropping the location cache entirely.
Harald Hoyer 670c70
-
Harald Hoyer 670c70
 * dbus: when a unit failed to load (i.e. is in UNIT_ERROR state), we
Harald Hoyer 670c70
   should be able to safely try another attempt when the bus call LoadUnit() is invoked.
Harald Hoyer 670c70
 
Harald Hoyer 670c70
diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h
Harald Hoyer 670c70
index 7b1cd42..5cc2c2d 100644
Harald Hoyer 670c70
--- a/src/journal/journal-file.h
Harald Hoyer 670c70
+++ b/src/journal/journal-file.h
Harald Hoyer 670c70
@@ -42,10 +42,14 @@ typedef struct JournalMetrics {
Harald Hoyer 670c70
         uint64_t keep_free;
Harald Hoyer 670c70
 } JournalMetrics;
Harald Hoyer 670c70
 
Harald Hoyer 670c70
+typedef enum direction {
Harald Hoyer 670c70
+        DIRECTION_UP,
Harald Hoyer 670c70
+        DIRECTION_DOWN
Harald Hoyer 670c70
+} direction_t;
Harald Hoyer 670c70
+
Harald Hoyer 670c70
 typedef struct JournalFile {
Harald Hoyer 670c70
         int fd;
Harald Hoyer 670c70
-        char *path;
Harald Hoyer 670c70
-        struct stat last_stat;
Harald Hoyer 670c70
+
Harald Hoyer 670c70
         mode_t mode;
Harald Hoyer 670c70
 
Harald Hoyer 670c70
         int flags;
Harald Hoyer 670c70
@@ -56,6 +60,11 @@ typedef struct JournalFile {
Harald Hoyer 670c70
 
Harald Hoyer 670c70
         bool tail_entry_monotonic_valid;
Harald Hoyer 670c70
 
Harald Hoyer 670c70
+        direction_t last_direction;
Harald Hoyer 670c70
+
Harald Hoyer 670c70
+        char *path;
Harald Hoyer 670c70
+        struct stat last_stat;
Harald Hoyer 670c70
+
Harald Hoyer 670c70
         Header *header;
Harald Hoyer 670c70
         HashItem *data_hash_table;
Harald Hoyer 670c70
         HashItem *field_hash_table;
Harald Hoyer 670c70
@@ -90,11 +99,6 @@ typedef struct JournalFile {
Harald Hoyer 670c70
 #endif
Harald Hoyer 670c70
 } JournalFile;
Harald Hoyer 670c70
 
Harald Hoyer 670c70
-typedef enum direction {
Harald Hoyer 670c70
-        DIRECTION_UP,
Harald Hoyer 670c70
-        DIRECTION_DOWN
Harald Hoyer 670c70
-} direction_t;
Harald Hoyer 670c70
-
Harald Hoyer 670c70
 int journal_file_open(
Harald Hoyer 670c70
                 const char *fname,
Harald Hoyer 670c70
                 int flags,
Harald Hoyer 670c70
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
Harald Hoyer 670c70
index 3aa9ed4..4c4cc2d 100644
Harald Hoyer 670c70
--- a/src/journal/sd-journal.c
Harald Hoyer 670c70
+++ b/src/journal/sd-journal.c
Harald Hoyer 670c70
@@ -102,7 +102,8 @@ static void init_location(Location *l, LocationType type, JournalFile *f, Object
Harald Hoyer 670c70
         l->seqnum_set = l->realtime_set = l->monotonic_set = l->xor_hash_set = true;
Harald Hoyer 670c70
 }
Harald Hoyer 670c70
 
Harald Hoyer 670c70
-static void set_location(sd_journal *j, LocationType type, JournalFile *f, Object *o, uint64_t offset) {
Harald Hoyer 670c70
+static void set_location(sd_journal *j, LocationType type, JournalFile *f, Object *o,
Harald Hoyer 670c70
+                         direction_t direction, uint64_t offset) {
Harald Hoyer 670c70
         assert(j);
Harald Hoyer 670c70
         assert(type == LOCATION_DISCRETE || type == LOCATION_SEEK);
Harald Hoyer 670c70
         assert(f);
Harald Hoyer 670c70
@@ -110,12 +111,10 @@ static void set_location(sd_journal *j, LocationType type, JournalFile *f, Objec
Harald Hoyer 670c70
 
Harald Hoyer 670c70
         init_location(&j->current_location, type, f, o);
Harald Hoyer 670c70
 
Harald Hoyer 670c70
-        if (j->current_file)
Harald Hoyer 670c70
-                j->current_file->current_offset = 0;
Harald Hoyer 670c70
-
Harald Hoyer 670c70
         j->current_file = f;
Harald Hoyer 670c70
         j->current_field = 0;
Harald Hoyer 670c70
 
Harald Hoyer 670c70
+        f->last_direction = direction;
Harald Hoyer 670c70
         f->current_offset = offset;
Harald Hoyer 670c70
 }
Harald Hoyer 670c70
 
Harald Hoyer 670c70
@@ -811,7 +810,7 @@ static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direc
Harald Hoyer 670c70
         assert(j);
Harald Hoyer 670c70
         assert(f);
Harald Hoyer 670c70
 
Harald Hoyer 670c70
-        if (f->current_offset > 0) {
Harald Hoyer 670c70
+        if (f->last_direction == direction && f->current_offset > 0) {
Harald Hoyer 670c70
                 cp = f->current_offset;
Harald Hoyer 670c70
 
Harald Hoyer 670c70
                 r = journal_file_move_to_object(f, OBJECT_ENTRY, cp, &c);
Harald Hoyer 670c70
@@ -908,7 +907,7 @@ static int real_journal_next(sd_journal *j, direction_t direction) {
Harald Hoyer 670c70
         if (r < 0)
Harald Hoyer 670c70
                 return r;
Harald Hoyer 670c70
 
Harald Hoyer 670c70
-        set_location(j, LOCATION_DISCRETE, new_file, o, new_offset);
Harald Hoyer 670c70
+        set_location(j, LOCATION_DISCRETE, new_file, o, direction, new_offset);
Harald Hoyer 670c70
 
Harald Hoyer 670c70
         return 1;
Harald Hoyer 670c70
 }
Harald Hoyer 670c70
-- 
Harald Hoyer 670c70
1.8.2.1
Harald Hoyer 670c70