mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-10-28 20:25:25 +03:00
journal: allow boot_id to be passed to journal_append_entry()
In this commit, this is done only in testing code, i.e. there is no functional change apart from tests.
This commit is contained in:
parent
5a271b08b3
commit
d180c34998
@ -92,7 +92,8 @@ int writer_write(Writer *w,
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = journal_file_append_entry(w->journal, ts, iovw->iovec, iovw->count,
|
r = journal_file_append_entry(w->journal, ts, NULL,
|
||||||
|
iovw->iovec, iovw->count,
|
||||||
&w->seqnum, NULL, NULL);
|
&w->seqnum, NULL, NULL);
|
||||||
if (r >= 0) {
|
if (r >= 0) {
|
||||||
if (w->server)
|
if (w->server)
|
||||||
@ -109,7 +110,8 @@ int writer_write(Writer *w,
|
|||||||
log_debug("%s: Successfully rotated journal", w->journal->path);
|
log_debug("%s: Successfully rotated journal", w->journal->path);
|
||||||
|
|
||||||
log_debug("Retrying write.");
|
log_debug("Retrying write.");
|
||||||
r = journal_file_append_entry(w->journal, ts, iovw->iovec, iovw->count,
|
r = journal_file_append_entry(w->journal, ts, NULL,
|
||||||
|
iovw->iovec, iovw->count,
|
||||||
&w->seqnum, NULL, NULL);
|
&w->seqnum, NULL, NULL);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
@ -1801,6 +1801,7 @@ static int journal_file_link_entry(JournalFile *f, Object *o, uint64_t offset) {
|
|||||||
static int journal_file_append_entry_internal(
|
static int journal_file_append_entry_internal(
|
||||||
JournalFile *f,
|
JournalFile *f,
|
||||||
const dual_timestamp *ts,
|
const dual_timestamp *ts,
|
||||||
|
const sd_id128_t *boot_id,
|
||||||
uint64_t xor_hash,
|
uint64_t xor_hash,
|
||||||
const EntryItem items[], unsigned n_items,
|
const EntryItem items[], unsigned n_items,
|
||||||
uint64_t *seqnum,
|
uint64_t *seqnum,
|
||||||
@ -1826,7 +1827,7 @@ static int journal_file_append_entry_internal(
|
|||||||
o->entry.realtime = htole64(ts->realtime);
|
o->entry.realtime = htole64(ts->realtime);
|
||||||
o->entry.monotonic = htole64(ts->monotonic);
|
o->entry.monotonic = htole64(ts->monotonic);
|
||||||
o->entry.xor_hash = htole64(xor_hash);
|
o->entry.xor_hash = htole64(xor_hash);
|
||||||
o->entry.boot_id = f->header->boot_id;
|
o->entry.boot_id = boot_id ? *boot_id : f->header->boot_id;
|
||||||
|
|
||||||
#if HAVE_GCRYPT
|
#if HAVE_GCRYPT
|
||||||
r = journal_file_hmac_put_object(f, OBJECT_ENTRY, o, np);
|
r = journal_file_hmac_put_object(f, OBJECT_ENTRY, o, np);
|
||||||
@ -1947,7 +1948,14 @@ static int entry_item_cmp(const void *_a, const void *_b) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const struct iovec iovec[], unsigned n_iovec, uint64_t *seqnum, Object **ret, uint64_t *offset) {
|
int journal_file_append_entry(
|
||||||
|
JournalFile *f,
|
||||||
|
const dual_timestamp *ts,
|
||||||
|
const sd_id128_t *boot_id,
|
||||||
|
const struct iovec iovec[], unsigned n_iovec,
|
||||||
|
uint64_t *seqnum,
|
||||||
|
Object **ret, uint64_t *offset) {
|
||||||
|
|
||||||
unsigned i;
|
unsigned i;
|
||||||
EntryItem *items;
|
EntryItem *items;
|
||||||
int r;
|
int r;
|
||||||
@ -1998,7 +2006,7 @@ int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const st
|
|||||||
* times for rotating media. */
|
* times for rotating media. */
|
||||||
qsort_safe(items, n_iovec, sizeof(EntryItem), entry_item_cmp);
|
qsort_safe(items, n_iovec, sizeof(EntryItem), entry_item_cmp);
|
||||||
|
|
||||||
r = journal_file_append_entry_internal(f, ts, xor_hash, items, n_iovec, seqnum, ret, offset);
|
r = journal_file_append_entry_internal(f, ts, boot_id, xor_hash, items, n_iovec, seqnum, ret, offset);
|
||||||
|
|
||||||
/* If the memory mapping triggered a SIGBUS then we return an
|
/* If the memory mapping triggered a SIGBUS then we return an
|
||||||
* IO error and ignore the error code passed down to us, since
|
* IO error and ignore the error code passed down to us, since
|
||||||
@ -3581,6 +3589,7 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6
|
|||||||
int r;
|
int r;
|
||||||
EntryItem *items;
|
EntryItem *items;
|
||||||
dual_timestamp ts;
|
dual_timestamp ts;
|
||||||
|
const sd_id128_t *boot_id;
|
||||||
|
|
||||||
assert(from);
|
assert(from);
|
||||||
assert(to);
|
assert(to);
|
||||||
@ -3592,6 +3601,7 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6
|
|||||||
|
|
||||||
ts.monotonic = le64toh(o->entry.monotonic);
|
ts.monotonic = le64toh(o->entry.monotonic);
|
||||||
ts.realtime = le64toh(o->entry.realtime);
|
ts.realtime = le64toh(o->entry.realtime);
|
||||||
|
boot_id = &o->entry.boot_id;
|
||||||
|
|
||||||
n = journal_file_entry_n_items(o);
|
n = journal_file_entry_n_items(o);
|
||||||
/* alloca() can't take 0, hence let's allocate at least one */
|
/* alloca() can't take 0, hence let's allocate at least one */
|
||||||
@ -3651,7 +3661,8 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = journal_file_append_entry_internal(to, &ts, xor_hash, items, n, seqnum, ret, offset);
|
r = journal_file_append_entry_internal(to, &ts, boot_id, xor_hash, items, n,
|
||||||
|
NULL, NULL, NULL);
|
||||||
|
|
||||||
if (mmap_cache_got_sigbus(to->mmap, to->cache_fd))
|
if (mmap_cache_got_sigbus(to->mmap, to->cache_fd))
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
@ -205,7 +205,14 @@ uint64_t journal_file_entry_array_n_items(Object *o) _pure_;
|
|||||||
uint64_t journal_file_hash_table_n_items(Object *o) _pure_;
|
uint64_t journal_file_hash_table_n_items(Object *o) _pure_;
|
||||||
|
|
||||||
int journal_file_append_object(JournalFile *f, ObjectType type, uint64_t size, Object **ret, uint64_t *offset);
|
int journal_file_append_object(JournalFile *f, ObjectType type, uint64_t size, Object **ret, uint64_t *offset);
|
||||||
int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const struct iovec iovec[], unsigned n_iovec, uint64_t *seqno, Object **ret, uint64_t *offset);
|
int journal_file_append_entry(
|
||||||
|
JournalFile *f,
|
||||||
|
const dual_timestamp *ts,
|
||||||
|
const sd_id128_t *boot_id,
|
||||||
|
const struct iovec iovec[], unsigned n_iovec,
|
||||||
|
uint64_t *seqno,
|
||||||
|
Object **ret,
|
||||||
|
uint64_t *offset);
|
||||||
|
|
||||||
int journal_file_find_data_object(JournalFile *f, const void *data, uint64_t size, Object **ret, uint64_t *offset);
|
int journal_file_find_data_object(JournalFile *f, const void *data, uint64_t size, Object **ret, uint64_t *offset);
|
||||||
int journal_file_find_data_object_with_hash(JournalFile *f, const void *data, uint64_t size, uint64_t hash, Object **ret, uint64_t *offset);
|
int journal_file_find_data_object_with_hash(JournalFile *f, const void *data, uint64_t size, uint64_t hash, Object **ret, uint64_t *offset);
|
||||||
|
@ -692,7 +692,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, size_t n
|
|||||||
|
|
||||||
s->last_realtime_clock = ts.realtime;
|
s->last_realtime_clock = ts.realtime;
|
||||||
|
|
||||||
r = journal_file_append_entry(f, &ts, iovec, n, &s->seqnum, NULL, NULL);
|
r = journal_file_append_entry(f, &ts, NULL, iovec, n, &s->seqnum, NULL, NULL);
|
||||||
if (r >= 0) {
|
if (r >= 0) {
|
||||||
server_schedule_sync(s, priority);
|
server_schedule_sync(s, priority);
|
||||||
return;
|
return;
|
||||||
@ -711,7 +711,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, size_t n
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
log_debug("Retrying write.");
|
log_debug("Retrying write.");
|
||||||
r = journal_file_append_entry(f, &ts, iovec, n, &s->seqnum, NULL, NULL);
|
r = journal_file_append_entry(f, &ts, NULL, iovec, n, &s->seqnum, NULL, NULL);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_error_errno(r, "Failed to write entry (%zu items, %zu bytes) despite vacuuming, ignoring: %m", n, IOVEC_TOTAL_SIZE(iovec, n));
|
log_error_errno(r, "Failed to write entry (%zu items, %zu bytes) despite vacuuming, ignoring: %m", n, IOVEC_TOTAL_SIZE(iovec, n));
|
||||||
else
|
else
|
||||||
|
@ -66,7 +66,7 @@ static void append_number(JournalFile *f, int n, uint64_t *seqnum) {
|
|||||||
assert_se(asprintf(&p, "NUMBER=%d", n) >= 0);
|
assert_se(asprintf(&p, "NUMBER=%d", n) >= 0);
|
||||||
iovec[0].iov_base = p;
|
iovec[0].iov_base = p;
|
||||||
iovec[0].iov_len = strlen(p);
|
iovec[0].iov_len = strlen(p);
|
||||||
assert_ret(journal_file_append_entry(f, &ts, iovec, 1, seqnum, NULL, NULL));
|
assert_ret(journal_file_append_entry(f, &ts, NULL, iovec, 1, seqnum, NULL, NULL));
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,12 +109,12 @@ int main(int argc, char *argv[]) {
|
|||||||
iovec[1].iov_len = strlen(q);
|
iovec[1].iov_len = strlen(q);
|
||||||
|
|
||||||
if (i % 10 == 0)
|
if (i % 10 == 0)
|
||||||
assert_se(journal_file_append_entry(three, &ts, iovec, 2, NULL, NULL, NULL) == 0);
|
assert_se(journal_file_append_entry(three, &ts, NULL, iovec, 2, NULL, NULL, NULL) == 0);
|
||||||
else {
|
else {
|
||||||
if (i % 3 == 0)
|
if (i % 3 == 0)
|
||||||
assert_se(journal_file_append_entry(two, &ts, iovec, 2, NULL, NULL, NULL) == 0);
|
assert_se(journal_file_append_entry(two, &ts, NULL, iovec, 2, NULL, NULL, NULL) == 0);
|
||||||
|
|
||||||
assert_se(journal_file_append_entry(one, &ts, iovec, 2, NULL, NULL, NULL) == 0);
|
assert_se(journal_file_append_entry(one, &ts, NULL, iovec, 2, NULL, NULL, NULL) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(p);
|
free(p);
|
||||||
|
@ -90,7 +90,7 @@ int main(int argc, char *argv[]) {
|
|||||||
iovec.iov_base = (void*) test;
|
iovec.iov_base = (void*) test;
|
||||||
iovec.iov_len = strlen(test);
|
iovec.iov_len = strlen(test);
|
||||||
|
|
||||||
assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);
|
assert_se(journal_file_append_entry(f, &ts, NULL, &iovec, 1, NULL, NULL, NULL) == 0);
|
||||||
|
|
||||||
free(test);
|
free(test);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ static void test_non_empty(void) {
|
|||||||
static const char test[] = "TEST1=1", test2[] = "TEST2=2";
|
static const char test[] = "TEST1=1", test2[] = "TEST2=2";
|
||||||
Object *o;
|
Object *o;
|
||||||
uint64_t p;
|
uint64_t p;
|
||||||
|
sd_id128_t fake_boot_id;
|
||||||
char t[] = "/tmp/journal-XXXXXX";
|
char t[] = "/tmp/journal-XXXXXX";
|
||||||
|
|
||||||
log_set_max_level(LOG_DEBUG);
|
log_set_max_level(LOG_DEBUG);
|
||||||
@ -32,19 +33,20 @@ static void test_non_empty(void) {
|
|||||||
|
|
||||||
assert_se(journal_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, (uint64_t) -1, true, NULL, NULL, NULL, NULL, &f) == 0);
|
assert_se(journal_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, (uint64_t) -1, true, NULL, NULL, NULL, NULL, &f) == 0);
|
||||||
|
|
||||||
dual_timestamp_get(&ts);
|
assert_se(dual_timestamp_get(&ts));
|
||||||
|
assert_se(sd_id128_randomize(&fake_boot_id) == 0);
|
||||||
|
|
||||||
iovec.iov_base = (void*) test;
|
iovec.iov_base = (void*) test;
|
||||||
iovec.iov_len = strlen(test);
|
iovec.iov_len = strlen(test);
|
||||||
assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);
|
assert_se(journal_file_append_entry(f, &ts, NULL, &iovec, 1, NULL, NULL, NULL) == 0);
|
||||||
|
|
||||||
iovec.iov_base = (void*) test2;
|
iovec.iov_base = (void*) test2;
|
||||||
iovec.iov_len = strlen(test2);
|
iovec.iov_len = strlen(test2);
|
||||||
assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);
|
assert_se(journal_file_append_entry(f, &ts, NULL, &iovec, 1, NULL, NULL, NULL) == 0);
|
||||||
|
|
||||||
iovec.iov_base = (void*) test;
|
iovec.iov_base = (void*) test;
|
||||||
iovec.iov_len = strlen(test);
|
iovec.iov_len = strlen(test);
|
||||||
assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);
|
assert_se(journal_file_append_entry(f, &ts, &fake_boot_id, &iovec, 1, NULL, NULL, NULL) == 0);
|
||||||
|
|
||||||
#if HAVE_GCRYPT
|
#if HAVE_GCRYPT
|
||||||
journal_file_append_tag(f);
|
journal_file_append_tag(f);
|
||||||
@ -59,6 +61,7 @@ static void test_non_empty(void) {
|
|||||||
|
|
||||||
assert_se(journal_file_next_entry(f, p, DIRECTION_DOWN, &o, &p) == 1);
|
assert_se(journal_file_next_entry(f, p, DIRECTION_DOWN, &o, &p) == 1);
|
||||||
assert_se(le64toh(o->entry.seqnum) == 3);
|
assert_se(le64toh(o->entry.seqnum) == 3);
|
||||||
|
assert_se(sd_id128_equal(o->entry.boot_id, fake_boot_id));
|
||||||
|
|
||||||
assert_se(journal_file_next_entry(f, p, DIRECTION_DOWN, &o, &p) == 0);
|
assert_se(journal_file_next_entry(f, p, DIRECTION_DOWN, &o, &p) == 0);
|
||||||
|
|
||||||
@ -177,7 +180,7 @@ static bool check_compressed(uint64_t compress_threshold, uint64_t data_size) {
|
|||||||
|
|
||||||
iovec.iov_base = (void*) data;
|
iovec.iov_base = (void*) data;
|
||||||
iovec.iov_len = data_size;
|
iovec.iov_len = data_size;
|
||||||
assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);
|
assert_se(journal_file_append_entry(f, &ts, NULL, &iovec, 1, NULL, NULL, NULL) == 0);
|
||||||
|
|
||||||
#if HAVE_GCRYPT
|
#if HAVE_GCRYPT
|
||||||
journal_file_append_tag(f);
|
journal_file_append_tag(f);
|
||||||
|
Loading…
Reference in New Issue
Block a user