chiark / gitweb /
journal: it's not a problem if the realtime jumps, hence don't ensure monotonicity...
[elogind.git] / src / journal / journal-file.c
index 45aab0e54a0eacfb2b3923a6c1ae2c8e50e66f0f..4de1daf6a0b177bed7105fc32ea493cc8da4a95c 100644 (file)
@@ -138,6 +138,9 @@ static int journal_file_refresh_header(JournalFile *f) {
         f->header->boot_id = boot_id;
 
         f->header->state = STATE_ONLINE;
+
+        __sync_synchronize();
+
         return 0;
 }
 
@@ -293,6 +296,15 @@ static int journal_file_move_to(JournalFile *f, int wt, uint64_t offset, uint64_
         assert(wt >= 0);
         assert(wt < _WINDOW_MAX);
 
+        if (offset + size > (uint64_t) f->last_stat.st_size) {
+                /* Hmm, out of range? Let's refresh the fstat() data
+                 * first, before we trust that check. */
+
+                if (fstat(f->fd, &f->last_stat) < 0 ||
+                    offset + size > (uint64_t) f->last_stat.st_size)
+                        return -EADDRNOTAVAIL;
+        }
+
         w = f->windows + wt;
 
         if (_likely_(w->ptr &&
@@ -320,17 +332,14 @@ static int journal_file_move_to(JournalFile *f, int wt, uint64_t offset, uint64_
 
                 delta = PAGE_ALIGN((DEFAULT_WINDOW_SIZE - size) / 2);
 
-                if (offset < delta)
+                if (delta > offset)
                         delta = offset;
 
                 offset -= delta;
-                size += (DEFAULT_WINDOW_SIZE - delta);
+                size = DEFAULT_WINDOW_SIZE;
         } else
                 delta = 0;
 
-        if (offset > (uint64_t) f->last_stat.st_size)
-                return -EADDRNOTAVAIL;
-
         if (offset + size > (uint64_t) f->last_stat.st_size)
                 size = PAGE_ALIGN((uint64_t) f->last_stat.st_size - offset);
 
@@ -898,6 +907,8 @@ static int journal_file_link_entry(JournalFile *f, Object *o, uint64_t offset) {
         assert(offset > 0);
         assert(o->object.type == OBJECT_ENTRY);
 
+        __sync_synchronize();
+
         /* Link up the entry itself */
         r = link_entry_into_array(f,
                                   &f->header->entry_array_offset,
@@ -1005,9 +1016,6 @@ int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const st
             ts->monotonic < le64toh(f->header->tail_entry_monotonic))
                 return -EINVAL;
 
-        if (ts->realtime < le64toh(f->header->tail_entry_realtime))
-                return -EINVAL;
-
         items = alloca(sizeof(EntryItem) * n_iovec);
 
         for (i = 0; i < n_iovec; i++) {