X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fjournal-file.c;h=419e15e46fa583c36c808720c2d3e1281e038e10;hb=ebda471d898063887008ede9811ffbe1acbc38e5;hp=fd2e9ebbbcf1cb0a9d7905714537e35a12f9f328;hpb=babfc09177c1e71cec6c1ef9602e265ed40cfe4f;p=elogind.git diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index fd2e9ebbb..419e15e46 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -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; } @@ -283,7 +286,7 @@ static int journal_file_map( } static int journal_file_move_to(JournalFile *f, int wt, uint64_t offset, uint64_t size, void **ret) { - void *p; + void *p = NULL; uint64_t delta; int r; Window *w; @@ -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 && @@ -318,21 +330,18 @@ static int journal_file_move_to(JournalFile *f, int wt, uint64_t offset, uint64_ * the window space before and half behind the * requested mapping */ - delta = PAGE_ALIGN((DEFAULT_WINDOW_SIZE - size) / 2); + delta = (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); + size = (uint64_t) f->last_stat.st_size - offset; if (size <= 0) return -EADDRNOTAVAIL; @@ -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, @@ -906,7 +917,7 @@ static int journal_file_link_entry(JournalFile *f, Object *o, uint64_t offset) { if (r < 0) return r; - log_error("=> %s seqnr=%lu n_entries=%lu", f->path, (unsigned long) o->entry.seqnum, (unsigned long) f->header->n_entries); + /* log_debug("=> %s seqnr=%lu n_entries=%lu", f->path, (unsigned long) o->entry.seqnum, (unsigned long) f->header->n_entries); */ if (f->header->head_entry_realtime == 0) f->header->head_entry_realtime = o->entry.realtime; @@ -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++) { @@ -1036,7 +1044,7 @@ static int generic_array_get(JournalFile *f, Object **ret, uint64_t *offset) { Object *o; - uint64_t p, a; + uint64_t p = 0, a; int r; assert(f);