Permalink
Browse files

journald: flush /run to /var as soon as it becomes available

  • Loading branch information...
poettering committed Dec 29, 2011
1 parent de97b26 commit cf244689e9d1ab50082c9ddd0f3c4d1eb982badc
Showing with 309 additions and 130 deletions.
  1. +85 −8 src/journal/journal-file.c
  2. +4 −0 src/journal/journal-file.h
  3. +1 −1 src/journal/journalctl.c
  4. +185 −63 src/journal/journald.c
  5. +19 −50 src/journal/sd-journal.c
  6. +15 −8 src/journal/sd-journal.h
@@ -950,7 +950,7 @@ static int journal_file_append_entry_internal(
return 0;
}

static void journal_file_post_change(JournalFile *f) {
void journal_file_post_change(JournalFile *f) {
assert(f);

/* inotify() does not receive IN_MODIFY events from file
@@ -989,17 +989,15 @@ int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const st
if (ts->realtime < le64toh(f->header->tail_entry_realtime))
return -EINVAL;

items = new(EntryItem, n_iovec);
if (!items)
return -ENOMEM;
items = alloca(sizeof(EntryItem) * n_iovec);

for (i = 0; i < n_iovec; i++) {
uint64_t p;
Object *o;

r = journal_file_append_data(f, iovec[i].iov_base, iovec[i].iov_len, &o, &p);
if (r < 0)
goto finish;
return r;

xor_hash ^= le64toh(o->data.hash);
items[i].object_offset = htole64(p);
@@ -1010,9 +1008,6 @@ int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const st

journal_file_post_change(f);

finish:
free(items);

return r;
}

@@ -1999,3 +1994,85 @@ int journal_directory_vacuum(const char *directory, uint64_t max_use, uint64_t m

return r;
}

int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint64_t p, uint64_t *seqnum, Object **ret, uint64_t *offset) {
uint64_t i, n;
uint64_t q, xor_hash = 0;
int r;
EntryItem *items;
dual_timestamp ts;

assert(from);
assert(to);
assert(o);
assert(p);

if (!to->writable)
return -EPERM;

ts.monotonic = le64toh(o->entry.monotonic);
ts.realtime = le64toh(o->entry.realtime);

if (to->tail_entry_monotonic_valid &&
ts.monotonic < le64toh(to->header->tail_entry_monotonic))
return -EINVAL;

if (ts.realtime < le64toh(to->header->tail_entry_realtime))
return -EINVAL;

n = journal_file_entry_n_items(o);
items = alloca(sizeof(EntryItem) * n);

for (i = 0; i < n; i++) {
uint64_t le_hash, l, h;
size_t t;
void *data;
Object *u;

q = le64toh(o->entry.items[i].object_offset);
le_hash = o->entry.items[i].hash;

r = journal_file_move_to_object(from, OBJECT_DATA, q, &o);
if (r < 0)
return r;

if (le_hash != o->data.hash)
return -EBADMSG;

l = le64toh(o->object.size) - offsetof(Object, data.payload);
t = (size_t) l;

/* We hit the limit on 32bit machines */
if ((uint64_t) t != l)
return -E2BIG;

if (o->object.flags & OBJECT_COMPRESSED) {
#ifdef HAVE_XZ
uint64_t rsize;

if (!uncompress_blob(o->data.payload, l, &from->compress_buffer, &from->compress_buffer_size, &rsize))
return -EBADMSG;

data = from->compress_buffer;
l = rsize;
#else
return -EPROTONOSUPPORT;
#endif
} else
data = o->data.payload;

r = journal_file_append_data(to, data, l, &u, &h);
if (r < 0)
return r;

xor_hash ^= le64toh(u->data.hash);
items[i].object_offset = htole64(h);
items[i].hash = u->data.hash;

r = journal_file_move_to_object(from, OBJECT_ENTRY, p, &o);
if (r < 0)
return r;
}

return journal_file_append_entry_internal(to, &ts, xor_hash, items, n, seqnum, ret, offset);
}
@@ -113,10 +113,14 @@ int journal_file_move_to_entry_by_monotonic(JournalFile *f, sd_id128_t boot_id,
int journal_file_move_to_entry_by_seqnum_for_data(JournalFile *f, uint64_t data_offset, uint64_t seqnum, direction_t direction, Object **ret, uint64_t *offset);
int journal_file_move_to_entry_by_realtime_for_data(JournalFile *f, uint64_t data_offset, uint64_t realtime, direction_t direction, Object **ret, uint64_t *offset);

int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint64_t p, uint64_t *seqnum, Object **ret, uint64_t *offset);

void journal_file_dump(JournalFile *f);

int journal_file_rotate(JournalFile **f);

int journal_directory_vacuum(const char *directory, uint64_t max_use, uint64_t min_free);

void journal_file_post_change(JournalFile *f);

#endif
@@ -454,7 +454,7 @@ int main(int argc, char *argv[]) {
if (r <= 0)
goto finish;

r = sd_journal_open(&j);
r = sd_journal_open(&j, 0);
if (r < 0) {
log_error("Failed to open journal: %s", strerror(-r));
goto finish;
Oops, something went wrong.

0 comments on commit cf24468

Please sign in to comment.