mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
sd-journal: several coding style updates
- rename `ret` -> `ret_object`, - add missing assertions, - add FIXME comments, - wrap function arguments, etc., etc..
This commit is contained in:
parent
8a77f21d29
commit
cc938e4a0a
@ -395,6 +395,9 @@ static bool warn_wrong_flags(const JournalFile *f, bool compatible) {
|
||||
const char *type = compatible ? "compatible" : "incompatible";
|
||||
uint32_t flags;
|
||||
|
||||
assert(f);
|
||||
assert(f->header);
|
||||
|
||||
flags = le32toh(compatible ? f->header->compatible_flags : f->header->incompatible_flags);
|
||||
|
||||
if (flags & ~supported) {
|
||||
@ -724,6 +727,7 @@ static int check_object_header(JournalFile *f, Object *o, ObjectType type, uint6
|
||||
/* Lightweight object checks. We want this to be fast, so that we won't
|
||||
* slowdown every journal_file_move_to_object() call too much. */
|
||||
static int check_object(JournalFile *f, Object *o, uint64_t offset) {
|
||||
assert(f);
|
||||
assert(o);
|
||||
|
||||
switch (o->object.type) {
|
||||
@ -996,7 +1000,7 @@ int journal_file_append_object(
|
||||
JournalFile *f,
|
||||
ObjectType type,
|
||||
uint64_t size,
|
||||
Object **ret,
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
int r;
|
||||
@ -1032,8 +1036,8 @@ int journal_file_append_object(
|
||||
f->header->tail_object_offset = htole64(p);
|
||||
f->header->n_objects = htole64(le64toh(f->header->n_objects) + 1);
|
||||
|
||||
if (ret)
|
||||
*ret = o;
|
||||
if (ret_object)
|
||||
*ret_object = o;
|
||||
|
||||
if (ret_offset)
|
||||
*ret_offset = p;
|
||||
@ -1261,6 +1265,11 @@ static int get_next_hash_offset(
|
||||
|
||||
uint64_t nextp;
|
||||
|
||||
assert(f);
|
||||
assert(p);
|
||||
assert(next_hash_offset);
|
||||
assert(depth);
|
||||
|
||||
nextp = le64toh(READ_NOW(*next_hash_offset));
|
||||
if (nextp > 0) {
|
||||
if (nextp <= *p) /* Refuse going in loops */
|
||||
@ -1280,15 +1289,19 @@ static int get_next_hash_offset(
|
||||
|
||||
int journal_file_find_field_object_with_hash(
|
||||
JournalFile *f,
|
||||
const void *field, uint64_t size, uint64_t hash,
|
||||
Object **ret, uint64_t *ret_offset) {
|
||||
const void *field,
|
||||
uint64_t size,
|
||||
uint64_t hash,
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
uint64_t p, osize, h, m, depth = 0;
|
||||
int r;
|
||||
|
||||
assert(f);
|
||||
assert(f->header);
|
||||
assert(field && size > 0);
|
||||
assert(field);
|
||||
assert(size > 0);
|
||||
|
||||
/* If the field hash table is empty, we can't find anything */
|
||||
if (le64toh(f->header->field_hash_table_size) <= 0)
|
||||
@ -1318,8 +1331,8 @@ int journal_file_find_field_object_with_hash(
|
||||
le64toh(o->object.size) == osize &&
|
||||
memcmp(o->field.payload, field, size) == 0) {
|
||||
|
||||
if (ret)
|
||||
*ret = o;
|
||||
if (ret_object)
|
||||
*ret_object = o;
|
||||
if (ret_offset)
|
||||
*ret_offset = p;
|
||||
|
||||
@ -1345,6 +1358,7 @@ uint64_t journal_file_hash_data(
|
||||
size_t sz) {
|
||||
|
||||
assert(f);
|
||||
assert(f->header);
|
||||
assert(data || sz == 0);
|
||||
|
||||
/* We try to unify our codebase on siphash, hence new-styled journal files utilizing the keyed hash
|
||||
@ -1358,23 +1372,29 @@ uint64_t journal_file_hash_data(
|
||||
|
||||
int journal_file_find_field_object(
|
||||
JournalFile *f,
|
||||
const void *field, uint64_t size,
|
||||
Object **ret, uint64_t *ret_offset) {
|
||||
const void *field,
|
||||
uint64_t size,
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
assert(f);
|
||||
assert(field && size > 0);
|
||||
assert(field);
|
||||
assert(size > 0);
|
||||
|
||||
return journal_file_find_field_object_with_hash(
|
||||
f,
|
||||
field, size,
|
||||
journal_file_hash_data(f, field, size),
|
||||
ret, ret_offset);
|
||||
ret_object, ret_offset);
|
||||
}
|
||||
|
||||
int journal_file_find_data_object_with_hash(
|
||||
JournalFile *f,
|
||||
const void *data, uint64_t size, uint64_t hash,
|
||||
Object **ret, uint64_t *ret_offset) {
|
||||
const void *data,
|
||||
uint64_t size,
|
||||
uint64_t hash,
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
uint64_t p, h, m, depth = 0;
|
||||
int r;
|
||||
@ -1417,8 +1437,8 @@ int journal_file_find_data_object_with_hash(
|
||||
assert(r > 0); /* journal_file_data_payload() always returns > 0 if no field is provided. */
|
||||
|
||||
if (memcmp_nn(data, size, d, rsize) == 0) {
|
||||
if (ret)
|
||||
*ret = o;
|
||||
if (ret_object)
|
||||
*ret_object = o;
|
||||
|
||||
if (ret_offset)
|
||||
*ret_offset = p;
|
||||
@ -1442,8 +1462,10 @@ int journal_file_find_data_object_with_hash(
|
||||
|
||||
int journal_file_find_data_object(
|
||||
JournalFile *f,
|
||||
const void *data, uint64_t size,
|
||||
Object **ret, uint64_t *ret_offset) {
|
||||
const void *data,
|
||||
uint64_t size,
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
assert(f);
|
||||
assert(data || size == 0);
|
||||
@ -1452,7 +1474,7 @@ int journal_file_find_data_object(
|
||||
f,
|
||||
data, size,
|
||||
journal_file_hash_data(f, data, size),
|
||||
ret, ret_offset);
|
||||
ret_object, ret_offset);
|
||||
}
|
||||
|
||||
bool journal_field_valid(const char *p, size_t l, bool allow_protected) {
|
||||
@ -1462,6 +1484,8 @@ bool journal_field_valid(const char *p, size_t l, bool allow_protected) {
|
||||
|
||||
http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html */
|
||||
|
||||
assert(p);
|
||||
|
||||
if (l == SIZE_MAX)
|
||||
l = strlen(p);
|
||||
|
||||
@ -1493,8 +1517,10 @@ bool journal_field_valid(const char *p, size_t l, bool allow_protected) {
|
||||
|
||||
static int journal_file_append_field(
|
||||
JournalFile *f,
|
||||
const void *field, uint64_t size,
|
||||
Object **ret, uint64_t *ret_offset) {
|
||||
const void *field,
|
||||
uint64_t size,
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
uint64_t hash, p;
|
||||
uint64_t osize;
|
||||
@ -1502,14 +1528,15 @@ static int journal_file_append_field(
|
||||
int r;
|
||||
|
||||
assert(f);
|
||||
assert(field && size > 0);
|
||||
assert(field);
|
||||
assert(size > 0);
|
||||
|
||||
if (!journal_field_valid(field, size, true))
|
||||
return -EBADMSG;
|
||||
|
||||
hash = journal_file_hash_data(f, field, size);
|
||||
|
||||
r = journal_file_find_field_object_with_hash(f, field, size, hash, ret, ret_offset);
|
||||
r = journal_file_find_field_object_with_hash(f, field, size, hash, ret_object, ret_offset);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r > 0)
|
||||
@ -1536,8 +1563,8 @@ static int journal_file_append_field(
|
||||
return r;
|
||||
#endif
|
||||
|
||||
if (ret) {
|
||||
r = journal_file_move_to_object(f, OBJECT_FIELD, p, ret);
|
||||
if (ret_object) {
|
||||
r = journal_file_move_to_object(f, OBJECT_FIELD, p, ret_object);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -1551,13 +1578,16 @@ static int journal_file_append_field(
|
||||
static Compression maybe_compress_payload(JournalFile *f, uint8_t *dst, const uint8_t *src, uint64_t size, size_t *rsize) {
|
||||
Compression compression = COMPRESSION_NONE;
|
||||
|
||||
assert(f);
|
||||
assert(f->header);
|
||||
|
||||
#if HAVE_COMPRESSION
|
||||
if (JOURNAL_FILE_COMPRESS(f) && size >= f->compress_threshold_bytes) {
|
||||
compression = compress_blob(src, size, dst, size - 1, rsize);
|
||||
if (compression > 0) {
|
||||
if (compression > 0)
|
||||
log_debug("Compressed data object %"PRIu64" -> %zu using %s",
|
||||
size, *rsize, compression_to_string(compression));
|
||||
} else
|
||||
else
|
||||
/* Compression didn't work, we don't really care why, let's continue without compression */
|
||||
compression = COMPRESSION_NONE;
|
||||
}
|
||||
@ -1568,8 +1598,10 @@ static Compression maybe_compress_payload(JournalFile *f, uint8_t *dst, const ui
|
||||
|
||||
static int journal_file_append_data(
|
||||
JournalFile *f,
|
||||
const void *data, uint64_t size,
|
||||
Object **ret, uint64_t *ret_offset) {
|
||||
const void *data,
|
||||
uint64_t size,
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
uint64_t hash, p, osize;
|
||||
Object *o, *fo;
|
||||
@ -1585,7 +1617,7 @@ static int journal_file_append_data(
|
||||
|
||||
hash = journal_file_hash_data(f, data, size);
|
||||
|
||||
r = journal_file_find_data_object_with_hash(f, data, size, hash, ret, ret_offset);
|
||||
r = journal_file_find_data_object_with_hash(f, data, size, hash, ret_object, ret_offset);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r > 0)
|
||||
@ -1634,8 +1666,8 @@ static int journal_file_append_data(
|
||||
o->data.next_field_offset = fo->field.head_data_offset;
|
||||
fo->field.head_data_offset = le64toh(p);
|
||||
|
||||
if (ret)
|
||||
*ret = o;
|
||||
if (ret_object)
|
||||
*ret_object = o;
|
||||
|
||||
if (ret_offset)
|
||||
*ret_offset = p;
|
||||
@ -1654,6 +1686,8 @@ static int maybe_decompress_payload(
|
||||
void **ret_data,
|
||||
size_t *ret_size) {
|
||||
|
||||
assert(f);
|
||||
|
||||
/* We can't read objects larger than 4G on a 32bit machine */
|
||||
if ((uint64_t) (size_t) size != size)
|
||||
return -E2BIG;
|
||||
@ -1672,8 +1706,10 @@ static int maybe_decompress_payload(
|
||||
compression_to_string(compression),
|
||||
size);
|
||||
if (r == 0) {
|
||||
*ret_data = NULL;
|
||||
*ret_size = 0;
|
||||
if (ret_data)
|
||||
*ret_data = NULL;
|
||||
if (ret_size)
|
||||
*ret_size = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -1691,8 +1727,10 @@ static int maybe_decompress_payload(
|
||||
#endif
|
||||
} else {
|
||||
if (field && (size < field_length + 1 || memcmp(payload, field, field_length) != 0 || payload[field_length] != '=')) {
|
||||
*ret_data = NULL;
|
||||
*ret_size = 0;
|
||||
if (ret_data)
|
||||
*ret_data = NULL;
|
||||
if (ret_size)
|
||||
*ret_size = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1719,9 +1757,8 @@ int journal_file_data_payload(
|
||||
Compression c;
|
||||
int r;
|
||||
|
||||
assert(f);
|
||||
assert(!field == (field_length == 0)); /* These must be specified together. */
|
||||
assert(ret_data);
|
||||
assert(ret_size);
|
||||
|
||||
if (!o) {
|
||||
r = journal_file_move_to_object(f, OBJECT_DATA, offset, &o);
|
||||
@ -1762,6 +1799,7 @@ uint64_t journal_file_entry_n_items(JournalFile *f, Object *o) {
|
||||
uint64_t journal_file_entry_array_n_items(JournalFile *f, Object *o) {
|
||||
uint64_t sz;
|
||||
|
||||
assert(f);
|
||||
assert(o);
|
||||
|
||||
if (o->object.type != OBJECT_ENTRY_ARRAY)
|
||||
@ -1800,15 +1838,17 @@ static void write_entry_array_item(JournalFile *f, Object *o, uint64_t i, uint64
|
||||
o->entry_array.items.regular[i] = htole64(p);
|
||||
}
|
||||
|
||||
static int link_entry_into_array(JournalFile *f,
|
||||
le64_t *first,
|
||||
le64_t *idx,
|
||||
le32_t *tail,
|
||||
le32_t *tidx,
|
||||
uint64_t p) {
|
||||
int r;
|
||||
static int link_entry_into_array(
|
||||
JournalFile *f,
|
||||
le64_t *first,
|
||||
le64_t *idx,
|
||||
le32_t *tail,
|
||||
le32_t *tidx,
|
||||
uint64_t p) {
|
||||
|
||||
uint64_t n = 0, ap = 0, q, i, a, hidx;
|
||||
Object *o;
|
||||
int r;
|
||||
|
||||
assert(f);
|
||||
assert(f->header);
|
||||
@ -1819,8 +1859,8 @@ static int link_entry_into_array(JournalFile *f,
|
||||
a = tail ? le32toh(*tail) : le64toh(*first);
|
||||
hidx = le64toh(READ_NOW(*idx));
|
||||
i = tidx ? le32toh(READ_NOW(*tidx)) : hidx;
|
||||
while (a > 0) {
|
||||
|
||||
while (a > 0) {
|
||||
r = journal_file_move_to_object(f, OBJECT_ENTRY_ARRAY, a, &o);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@ -1884,13 +1924,14 @@ static int link_entry_into_array(JournalFile *f,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int link_entry_into_array_plus_one(JournalFile *f,
|
||||
le64_t *extra,
|
||||
le64_t *first,
|
||||
le64_t *idx,
|
||||
le32_t *tail,
|
||||
le32_t *tidx,
|
||||
uint64_t p) {
|
||||
static int link_entry_into_array_plus_one(
|
||||
JournalFile *f,
|
||||
le64_t *extra,
|
||||
le64_t *first,
|
||||
le64_t *idx,
|
||||
le32_t *tail,
|
||||
le32_t *tidx,
|
||||
uint64_t p) {
|
||||
|
||||
uint64_t hidx;
|
||||
int r;
|
||||
@ -2013,9 +2054,12 @@ static int journal_file_append_entry_internal(
|
||||
const dual_timestamp *ts,
|
||||
const sd_id128_t *boot_id,
|
||||
uint64_t xor_hash,
|
||||
const EntryItem items[], size_t n_items,
|
||||
const EntryItem items[],
|
||||
size_t n_items,
|
||||
uint64_t *seqnum,
|
||||
Object **ret, uint64_t *ret_offset) {
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
uint64_t np;
|
||||
uint64_t osize;
|
||||
Object *o;
|
||||
@ -2023,8 +2067,8 @@ static int journal_file_append_entry_internal(
|
||||
|
||||
assert(f);
|
||||
assert(f->header);
|
||||
assert(items || n_items == 0);
|
||||
assert(ts);
|
||||
assert(items || n_items == 0);
|
||||
|
||||
osize = offsetof(Object, entry.items) + (n_items * journal_file_entry_item_size(f));
|
||||
|
||||
@ -2053,8 +2097,8 @@ static int journal_file_append_entry_internal(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (ret)
|
||||
*ret = o;
|
||||
if (ret_object)
|
||||
*ret_object = o;
|
||||
|
||||
if (ret_offset)
|
||||
*ret_offset = np;
|
||||
@ -2152,12 +2196,14 @@ int journal_file_enable_post_change_timer(JournalFile *f, sd_event *e, usec_t t)
|
||||
}
|
||||
|
||||
static int entry_item_cmp(const EntryItem *a, const EntryItem *b) {
|
||||
return CMP(a->object_offset, b->object_offset);
|
||||
return CMP(ASSERT_PTR(a)->object_offset, ASSERT_PTR(b)->object_offset);
|
||||
}
|
||||
|
||||
static size_t remove_duplicate_entry_items(EntryItem items[], size_t n) {
|
||||
size_t j = 1;
|
||||
|
||||
assert(items || n == 0);
|
||||
|
||||
if (n <= 1)
|
||||
return n;
|
||||
|
||||
@ -2172,9 +2218,11 @@ int journal_file_append_entry(
|
||||
JournalFile *f,
|
||||
const dual_timestamp *ts,
|
||||
const sd_id128_t *boot_id,
|
||||
const struct iovec iovec[], unsigned n_iovec,
|
||||
const struct iovec iovec[],
|
||||
unsigned n_iovec,
|
||||
uint64_t *seqnum,
|
||||
Object **ret, uint64_t *ret_offset) {
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
EntryItem *items;
|
||||
int r;
|
||||
@ -2183,7 +2231,8 @@ int journal_file_append_entry(
|
||||
|
||||
assert(f);
|
||||
assert(f->header);
|
||||
assert(iovec && n_iovec > 0);
|
||||
assert(iovec);
|
||||
assert(n_iovec > 0);
|
||||
|
||||
if (ts) {
|
||||
if (!VALID_REALTIME(ts->realtime))
|
||||
@ -2240,7 +2289,7 @@ int journal_file_append_entry(
|
||||
typesafe_qsort(items, n_iovec, entry_item_cmp);
|
||||
n_iovec = remove_duplicate_entry_items(items, n_iovec);
|
||||
|
||||
r = journal_file_append_entry_internal(f, ts, boot_id, xor_hash, items, n_iovec, seqnum, ret, ret_offset);
|
||||
r = journal_file_append_entry_internal(f, ts, boot_id, xor_hash, items, n_iovec, seqnum, ret_object, ret_offset);
|
||||
|
||||
/* If the memory mapping triggered a SIGBUS then we return an
|
||||
* IO error and ignore the error code passed down to us, since
|
||||
@ -2275,6 +2324,8 @@ static void chain_cache_put(
|
||||
uint64_t total,
|
||||
uint64_t last_index) {
|
||||
|
||||
assert(h);
|
||||
|
||||
if (!ci) {
|
||||
/* If the chain item to cache for this chain is the
|
||||
* first one it's not worth caching anything */
|
||||
@ -2325,7 +2376,14 @@ static int bump_array_index(uint64_t *i, direction_t direction, uint64_t n) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int bump_entry_array(JournalFile *f, Object *o, uint64_t offset, uint64_t first, direction_t direction, uint64_t *ret) {
|
||||
static int bump_entry_array(
|
||||
JournalFile *f,
|
||||
Object *o,
|
||||
uint64_t offset,
|
||||
uint64_t first,
|
||||
direction_t direction,
|
||||
uint64_t *ret) {
|
||||
|
||||
uint64_t p, q = 0;
|
||||
int r;
|
||||
|
||||
@ -2333,8 +2391,10 @@ static int bump_entry_array(JournalFile *f, Object *o, uint64_t offset, uint64_t
|
||||
assert(offset);
|
||||
assert(ret);
|
||||
|
||||
if (direction == DIRECTION_DOWN)
|
||||
if (direction == DIRECTION_DOWN) {
|
||||
assert(o);
|
||||
return le64toh(o->entry_array.next_entry_array_offset);
|
||||
}
|
||||
|
||||
/* Entry array chains are a singly linked list, so to find the previous array in the chain, we have
|
||||
* to start iterating from the top. */
|
||||
@ -2365,15 +2425,18 @@ static int generic_array_get(
|
||||
uint64_t first,
|
||||
uint64_t i,
|
||||
direction_t direction,
|
||||
Object **ret, uint64_t *ret_offset) {
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
Object *o;
|
||||
uint64_t p = 0, a, t = 0, k;
|
||||
int r;
|
||||
ChainCacheItem *ci;
|
||||
Object *o;
|
||||
int r;
|
||||
|
||||
assert(f);
|
||||
|
||||
/* FIXME: fix return value assignment on success. */
|
||||
|
||||
a = first;
|
||||
|
||||
/* Try the chain cache first */
|
||||
@ -2437,7 +2500,7 @@ static int generic_array_get(
|
||||
do {
|
||||
p = journal_file_entry_array_item(f, o, i);
|
||||
|
||||
r = journal_file_move_to_object(f, OBJECT_ENTRY, p, ret);
|
||||
r = journal_file_move_to_object(f, OBJECT_ENTRY, p, ret_object);
|
||||
if (r >= 0) {
|
||||
/* Let's cache this item for the next invocation */
|
||||
chain_cache_put(f->chain_cache, ci, first, a, journal_file_entry_array_item(f, o, 0), t, i);
|
||||
@ -2472,16 +2535,19 @@ static int generic_array_get_plus_one(
|
||||
uint64_t first,
|
||||
uint64_t i,
|
||||
direction_t direction,
|
||||
Object **ret, uint64_t *ret_offset) {
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
int r;
|
||||
|
||||
assert(f);
|
||||
|
||||
/* FIXME: fix return value assignment on success. */
|
||||
|
||||
if (i == 0) {
|
||||
r = journal_file_move_to_object(f, OBJECT_ENTRY, extra, ret);
|
||||
r = journal_file_move_to_object(f, OBJECT_ENTRY, extra, ret_object);
|
||||
if (IN_SET(r, -EADDRNOTAVAIL, -EBADMSG))
|
||||
return generic_array_get(f, first, 0, direction, ret, ret_offset);
|
||||
return generic_array_get(f, first, 0, direction, ret_object, ret_offset);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -2491,7 +2557,7 @@ static int generic_array_get_plus_one(
|
||||
return 1;
|
||||
}
|
||||
|
||||
return generic_array_get(f, first, i - 1, direction, ret, ret_offset);
|
||||
return generic_array_get(f, first, i - 1, direction, ret_object, ret_offset);
|
||||
}
|
||||
|
||||
enum {
|
||||
@ -2507,7 +2573,7 @@ static int generic_array_bisect(
|
||||
uint64_t needle,
|
||||
int (*test_object)(JournalFile *f, uint64_t p, uint64_t needle),
|
||||
direction_t direction,
|
||||
Object **ret,
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset,
|
||||
uint64_t *ret_idx) {
|
||||
|
||||
@ -2527,8 +2593,8 @@ static int generic_array_bisect(
|
||||
uint64_t a, p, t = 0, i = 0, last_p = 0, last_index = UINT64_MAX;
|
||||
bool subtract_one = false;
|
||||
Object *array = NULL;
|
||||
int r;
|
||||
ChainCacheItem *ci;
|
||||
int r;
|
||||
|
||||
assert(f);
|
||||
assert(test_object);
|
||||
@ -2714,8 +2780,8 @@ found:
|
||||
else
|
||||
p = journal_file_entry_array_item(f, array, i);
|
||||
|
||||
if (ret) {
|
||||
r = journal_file_move_to_object(f, OBJECT_ENTRY, p, ret);
|
||||
if (ret_object) {
|
||||
r = journal_file_move_to_object(f, OBJECT_ENTRY, p, ret_object);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -2737,7 +2803,7 @@ static int generic_array_bisect_plus_one(
|
||||
uint64_t needle,
|
||||
int (*test_object)(JournalFile *f, uint64_t p, uint64_t needle),
|
||||
direction_t direction,
|
||||
Object **ret,
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset,
|
||||
uint64_t *ret_idx) {
|
||||
|
||||
@ -2774,7 +2840,7 @@ static int generic_array_bisect_plus_one(
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = generic_array_bisect(f, first, n-1, needle, test_object, direction, ret, ret_offset, ret_idx);
|
||||
r = generic_array_bisect(f, first, n-1, needle, test_object, direction, ret_object, ret_offset, ret_idx);
|
||||
|
||||
if (r == 0 && step_back)
|
||||
goto found;
|
||||
@ -2785,8 +2851,8 @@ static int generic_array_bisect_plus_one(
|
||||
return r;
|
||||
|
||||
found:
|
||||
if (ret) {
|
||||
r = journal_file_move_to_object(f, OBJECT_ENTRY, extra, ret);
|
||||
if (ret_object) {
|
||||
r = journal_file_move_to_object(f, OBJECT_ENTRY, extra, ret_object);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -2816,7 +2882,7 @@ int journal_file_move_to_entry_by_offset(
|
||||
JournalFile *f,
|
||||
uint64_t p,
|
||||
direction_t direction,
|
||||
Object **ret,
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
assert(f);
|
||||
@ -2829,7 +2895,7 @@ int journal_file_move_to_entry_by_offset(
|
||||
p,
|
||||
test_object_offset,
|
||||
direction,
|
||||
ret, ret_offset, NULL);
|
||||
ret_object, ret_offset, NULL);
|
||||
}
|
||||
|
||||
static int test_object_seqnum(JournalFile *f, uint64_t p, uint64_t needle) {
|
||||
@ -2857,8 +2923,9 @@ int journal_file_move_to_entry_by_seqnum(
|
||||
JournalFile *f,
|
||||
uint64_t seqnum,
|
||||
direction_t direction,
|
||||
Object **ret,
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
assert(f);
|
||||
assert(f->header);
|
||||
|
||||
@ -2869,7 +2936,7 @@ int journal_file_move_to_entry_by_seqnum(
|
||||
seqnum,
|
||||
test_object_seqnum,
|
||||
direction,
|
||||
ret, ret_offset, NULL);
|
||||
ret_object, ret_offset, NULL);
|
||||
}
|
||||
|
||||
static int test_object_realtime(JournalFile *f, uint64_t p, uint64_t needle) {
|
||||
@ -2897,8 +2964,9 @@ int journal_file_move_to_entry_by_realtime(
|
||||
JournalFile *f,
|
||||
uint64_t realtime,
|
||||
direction_t direction,
|
||||
Object **ret,
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
assert(f);
|
||||
assert(f->header);
|
||||
|
||||
@ -2909,7 +2977,7 @@ int journal_file_move_to_entry_by_realtime(
|
||||
realtime,
|
||||
test_object_realtime,
|
||||
direction,
|
||||
ret, ret_offset, NULL);
|
||||
ret_object, ret_offset, NULL);
|
||||
}
|
||||
|
||||
static int test_object_monotonic(JournalFile *f, uint64_t p, uint64_t needle) {
|
||||
@ -2936,13 +3004,15 @@ static int test_object_monotonic(JournalFile *f, uint64_t p, uint64_t needle) {
|
||||
static int find_data_object_by_boot_id(
|
||||
JournalFile *f,
|
||||
sd_id128_t boot_id,
|
||||
Object **o,
|
||||
uint64_t *b) {
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
char t[STRLEN("_BOOT_ID=") + 32 + 1] = "_BOOT_ID=";
|
||||
|
||||
assert(f);
|
||||
|
||||
sd_id128_to_string(boot_id, t + 9);
|
||||
return journal_file_find_data_object(f, t, sizeof(t) - 1, o, b);
|
||||
return journal_file_find_data_object(f, t, sizeof(t) - 1, ret_object, ret_offset);
|
||||
}
|
||||
|
||||
int journal_file_move_to_entry_by_monotonic(
|
||||
@ -2950,7 +3020,7 @@ int journal_file_move_to_entry_by_monotonic(
|
||||
sd_id128_t boot_id,
|
||||
uint64_t monotonic,
|
||||
direction_t direction,
|
||||
Object **ret,
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
Object *o;
|
||||
@ -2972,10 +3042,12 @@ int journal_file_move_to_entry_by_monotonic(
|
||||
monotonic,
|
||||
test_object_monotonic,
|
||||
direction,
|
||||
ret, ret_offset, NULL);
|
||||
ret_object, ret_offset, NULL);
|
||||
}
|
||||
|
||||
void journal_file_reset_location(JournalFile *f) {
|
||||
assert(f);
|
||||
|
||||
f->location_type = LOCATION_HEAD;
|
||||
f->current_offset = 0;
|
||||
f->current_seqnum = 0;
|
||||
@ -2986,6 +3058,9 @@ void journal_file_reset_location(JournalFile *f) {
|
||||
}
|
||||
|
||||
void journal_file_save_location(JournalFile *f, Object *o, uint64_t offset) {
|
||||
assert(f);
|
||||
assert(o);
|
||||
|
||||
f->location_type = LOCATION_SEEK;
|
||||
f->current_offset = offset;
|
||||
f->current_seqnum = le64toh(o->entry.seqnum);
|
||||
@ -3061,7 +3136,8 @@ int journal_file_next_entry(
|
||||
JournalFile *f,
|
||||
uint64_t p,
|
||||
direction_t direction,
|
||||
Object **ret, uint64_t *ret_offset) {
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
uint64_t i, n, ofs;
|
||||
int r;
|
||||
@ -3069,6 +3145,8 @@ int journal_file_next_entry(
|
||||
assert(f);
|
||||
assert(f->header);
|
||||
|
||||
/* FIXME: fix return value assignment. */
|
||||
|
||||
n = le64toh(READ_NOW(f->header->n_entries));
|
||||
if (n <= 0)
|
||||
return 0;
|
||||
@ -3093,7 +3171,7 @@ int journal_file_next_entry(
|
||||
}
|
||||
|
||||
/* And jump to it */
|
||||
r = generic_array_get(f, le64toh(f->header->entry_array_offset), i, direction, ret, &ofs);
|
||||
r = generic_array_get(f, le64toh(f->header->entry_array_offset), i, direction, ret_object, &ofs);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
@ -3113,7 +3191,8 @@ int journal_file_next_entry_for_data(
|
||||
JournalFile *f,
|
||||
Object *d,
|
||||
direction_t direction,
|
||||
Object **ret, uint64_t *ret_offset) {
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
uint64_t i, n, ofs;
|
||||
int r;
|
||||
@ -3122,6 +3201,8 @@ int journal_file_next_entry_for_data(
|
||||
assert(d);
|
||||
assert(d->object.type == OBJECT_DATA);
|
||||
|
||||
/* FIXME: fix return value assignment. */
|
||||
|
||||
n = le64toh(READ_NOW(d->data.n_entries));
|
||||
if (n <= 0)
|
||||
return n;
|
||||
@ -3133,7 +3214,7 @@ int journal_file_next_entry_for_data(
|
||||
le64toh(d->data.entry_array_offset),
|
||||
i,
|
||||
direction,
|
||||
ret, &ofs);
|
||||
ret_object, &ofs);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
@ -3171,11 +3252,12 @@ int journal_file_move_to_entry_by_monotonic_for_data(
|
||||
sd_id128_t boot_id,
|
||||
uint64_t monotonic,
|
||||
direction_t direction,
|
||||
Object **ret, uint64_t *ret_offset) {
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
uint64_t b, z, entry_offset, entry_array_offset, n_entries;
|
||||
Object *o;
|
||||
int r;
|
||||
uint64_t b, z, entry_offset, entry_array_offset, n_entries;
|
||||
|
||||
assert(f);
|
||||
assert(d);
|
||||
@ -3238,8 +3320,8 @@ int journal_file_move_to_entry_by_monotonic_for_data(
|
||||
return r;
|
||||
|
||||
if (p == q) {
|
||||
if (ret) {
|
||||
r = journal_file_move_to_object(f, OBJECT_ENTRY, q, ret);
|
||||
if (ret_object) {
|
||||
r = journal_file_move_to_object(f, OBJECT_ENTRY, q, ret_object);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -3259,7 +3341,8 @@ int journal_file_move_to_entry_by_seqnum_for_data(
|
||||
Object *d,
|
||||
uint64_t seqnum,
|
||||
direction_t direction,
|
||||
Object **ret, uint64_t *ret_offset) {
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset) {
|
||||
|
||||
assert(f);
|
||||
assert(d);
|
||||
@ -3273,7 +3356,7 @@ int journal_file_move_to_entry_by_seqnum_for_data(
|
||||
seqnum,
|
||||
test_object_seqnum,
|
||||
direction,
|
||||
ret, ret_offset, NULL);
|
||||
ret_object, ret_offset, NULL);
|
||||
}
|
||||
|
||||
int journal_file_move_to_entry_by_realtime_for_data(
|
||||
@ -3300,8 +3383,8 @@ int journal_file_move_to_entry_by_realtime_for_data(
|
||||
|
||||
void journal_file_dump(JournalFile *f) {
|
||||
Object *o;
|
||||
int r;
|
||||
uint64_t p;
|
||||
int r;
|
||||
|
||||
assert(f);
|
||||
assert(f->header);
|
||||
@ -3587,9 +3670,9 @@ int journal_file_open(
|
||||
void *h;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
assert(fd >= 0 || fname);
|
||||
assert(mmap_cache);
|
||||
assert(ret);
|
||||
|
||||
if (!IN_SET((open_flags & O_ACCMODE), O_RDONLY, O_RDWR))
|
||||
return -EINVAL;
|
||||
@ -3893,7 +3976,7 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6
|
||||
assert(from);
|
||||
assert(to);
|
||||
assert(o);
|
||||
assert(p);
|
||||
assert(p > 0);
|
||||
|
||||
if (!journal_file_writable(to))
|
||||
return -EPERM;
|
||||
@ -3964,35 +4047,37 @@ void journal_reset_metrics(JournalMetrics *m) {
|
||||
};
|
||||
}
|
||||
|
||||
int journal_file_get_cutoff_realtime_usec(JournalFile *f, usec_t *from, usec_t *to) {
|
||||
int journal_file_get_cutoff_realtime_usec(JournalFile *f, usec_t *ret_from, usec_t *ret_to) {
|
||||
assert(f);
|
||||
assert(f->header);
|
||||
assert(from || to);
|
||||
assert(ret_from || ret_to);
|
||||
|
||||
if (from) {
|
||||
if (ret_from) {
|
||||
if (f->header->head_entry_realtime == 0)
|
||||
return -ENOENT;
|
||||
|
||||
*from = le64toh(f->header->head_entry_realtime);
|
||||
*ret_from = le64toh(f->header->head_entry_realtime);
|
||||
}
|
||||
|
||||
if (to) {
|
||||
if (ret_to) {
|
||||
if (f->header->tail_entry_realtime == 0)
|
||||
return -ENOENT;
|
||||
|
||||
*to = le64toh(f->header->tail_entry_realtime);
|
||||
*ret_to = le64toh(f->header->tail_entry_realtime);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int journal_file_get_cutoff_monotonic_usec(JournalFile *f, sd_id128_t boot_id, usec_t *from, usec_t *to) {
|
||||
int journal_file_get_cutoff_monotonic_usec(JournalFile *f, sd_id128_t boot_id, usec_t *ret_from, usec_t *ret_to) {
|
||||
Object *o;
|
||||
uint64_t p;
|
||||
int r;
|
||||
|
||||
assert(f);
|
||||
assert(from || to);
|
||||
assert(ret_from || ret_to);
|
||||
|
||||
/* FIXME: fix return value assignment on success with 0. */
|
||||
|
||||
r = find_data_object_by_boot_id(f, boot_id, &o, &p);
|
||||
if (r <= 0)
|
||||
@ -4001,15 +4086,15 @@ int journal_file_get_cutoff_monotonic_usec(JournalFile *f, sd_id128_t boot_id, u
|
||||
if (le64toh(o->data.n_entries) <= 0)
|
||||
return 0;
|
||||
|
||||
if (from) {
|
||||
if (ret_from) {
|
||||
r = journal_file_move_to_object(f, OBJECT_ENTRY, le64toh(o->data.entry_offset), &o);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
*from = le64toh(o->entry.monotonic);
|
||||
*ret_from = le64toh(o->entry.monotonic);
|
||||
}
|
||||
|
||||
if (to) {
|
||||
if (ret_to) {
|
||||
r = journal_file_move_to_object(f, OBJECT_DATA, p, &o);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@ -4023,7 +4108,7 @@ int journal_file_get_cutoff_monotonic_usec(JournalFile *f, sd_id128_t boot_id, u
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
*to = le64toh(o->entry.monotonic);
|
||||
*ret_to = le64toh(o->entry.monotonic);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -249,38 +249,38 @@ static inline size_t journal_file_entry_array_item_size(JournalFile *f) {
|
||||
|
||||
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 *ret_offset);
|
||||
int journal_file_append_object(JournalFile *f, ObjectType type, uint64_t size, Object **ret_object, uint64_t *ret_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,
|
||||
Object **ret_object,
|
||||
uint64_t *ret_offset);
|
||||
|
||||
int journal_file_find_data_object(JournalFile *f, const void *data, uint64_t size, Object **ret, uint64_t *ret_offset);
|
||||
int journal_file_find_data_object_with_hash(JournalFile *f, const void *data, uint64_t size, uint64_t hash, Object **ret, uint64_t *ret_offset);
|
||||
int journal_file_find_data_object(JournalFile *f, const void *data, uint64_t size, Object **ret_object, uint64_t *ret_offset);
|
||||
int journal_file_find_data_object_with_hash(JournalFile *f, const void *data, uint64_t size, uint64_t hash, Object **ret_object, uint64_t *ret_offset);
|
||||
|
||||
int journal_file_find_field_object(JournalFile *f, const void *field, uint64_t size, Object **ret, uint64_t *ret_offset);
|
||||
int journal_file_find_field_object_with_hash(JournalFile *f, const void *field, uint64_t size, uint64_t hash, Object **ret, uint64_t *ret_offset);
|
||||
int journal_file_find_field_object(JournalFile *f, const void *field, uint64_t size, Object **ret_object, uint64_t *ret_offset);
|
||||
int journal_file_find_field_object_with_hash(JournalFile *f, const void *field, uint64_t size, uint64_t hash, Object **ret_object, uint64_t *ret_offset);
|
||||
|
||||
void journal_file_reset_location(JournalFile *f);
|
||||
void journal_file_save_location(JournalFile *f, Object *o, uint64_t offset);
|
||||
int journal_file_compare_locations(JournalFile *af, JournalFile *bf);
|
||||
int journal_file_next_entry(JournalFile *f, uint64_t p, direction_t direction, Object **ret, uint64_t *ret_offset);
|
||||
int journal_file_next_entry(JournalFile *f, uint64_t p, direction_t direction, Object **ret_object, uint64_t *ret_offset);
|
||||
|
||||
int journal_file_next_entry_for_data(JournalFile *f, Object *d, direction_t direction, Object **ret, uint64_t *ret_offset);
|
||||
int journal_file_next_entry_for_data(JournalFile *f, Object *d, direction_t direction, Object **ret_object, uint64_t *ret_offset);
|
||||
|
||||
int journal_file_move_to_entry_by_offset(JournalFile *f, uint64_t p, direction_t direction, Object **ret, uint64_t *ret_offset);
|
||||
int journal_file_move_to_entry_by_seqnum(JournalFile *f, uint64_t seqnum, direction_t direction, Object **ret, uint64_t *ret_offset);
|
||||
int journal_file_move_to_entry_by_realtime(JournalFile *f, uint64_t realtime, direction_t direction, Object **ret, uint64_t *ret_offset);
|
||||
int journal_file_move_to_entry_by_monotonic(JournalFile *f, sd_id128_t boot_id, uint64_t monotonic, direction_t direction, Object **ret, uint64_t *ret_offset);
|
||||
int journal_file_move_to_entry_by_offset(JournalFile *f, uint64_t p, direction_t direction, Object **ret_object, uint64_t *ret_offset);
|
||||
int journal_file_move_to_entry_by_seqnum(JournalFile *f, uint64_t seqnum, direction_t direction, Object **ret_object, uint64_t *ret_offset);
|
||||
int journal_file_move_to_entry_by_realtime(JournalFile *f, uint64_t realtime, direction_t direction, Object **ret_object, uint64_t *ret_offset);
|
||||
int journal_file_move_to_entry_by_monotonic(JournalFile *f, sd_id128_t boot_id, uint64_t monotonic, direction_t direction, Object **ret_object, uint64_t *ret_offset);
|
||||
|
||||
int journal_file_move_to_entry_by_offset_for_data(JournalFile *f, Object *d, uint64_t p, direction_t direction, Object **ret, uint64_t *ret_offset);
|
||||
int journal_file_move_to_entry_by_seqnum_for_data(JournalFile *f, Object *d, uint64_t seqnum, direction_t direction, Object **ret, uint64_t *ret_offset);
|
||||
int journal_file_move_to_entry_by_realtime_for_data(JournalFile *f, Object *d, uint64_t realtime, direction_t direction, Object **ret, uint64_t *ret_offset);
|
||||
int journal_file_move_to_entry_by_monotonic_for_data(JournalFile *f, Object *d, sd_id128_t boot_id, uint64_t monotonic, direction_t direction, Object **ret, uint64_t *ret_offset);
|
||||
int journal_file_move_to_entry_by_offset_for_data(JournalFile *f, Object *d, uint64_t p, direction_t direction, Object **ret_object, uint64_t *ret_offset);
|
||||
int journal_file_move_to_entry_by_seqnum_for_data(JournalFile *f, Object *d, uint64_t seqnum, direction_t direction, Object **ret_object, uint64_t *ret_offset);
|
||||
int journal_file_move_to_entry_by_realtime_for_data(JournalFile *f, Object *d, uint64_t realtime, direction_t direction, Object **ret_object, uint64_t *ret_offset);
|
||||
int journal_file_move_to_entry_by_monotonic_for_data(JournalFile *f, Object *d, sd_id128_t boot_id, uint64_t monotonic, direction_t direction, Object **ret_object, uint64_t *ret_offset);
|
||||
|
||||
int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint64_t p);
|
||||
|
||||
@ -297,8 +297,8 @@ int journal_file_enable_post_change_timer(JournalFile *f, sd_event *e, usec_t t)
|
||||
|
||||
void journal_reset_metrics(JournalMetrics *m);
|
||||
|
||||
int journal_file_get_cutoff_realtime_usec(JournalFile *f, usec_t *from, usec_t *to);
|
||||
int journal_file_get_cutoff_monotonic_usec(JournalFile *f, sd_id128_t boot, usec_t *from, usec_t *to);
|
||||
int journal_file_get_cutoff_realtime_usec(JournalFile *f, usec_t *ret_from, usec_t *ret_to);
|
||||
int journal_file_get_cutoff_monotonic_usec(JournalFile *f, sd_id128_t boot, usec_t *ret_from, usec_t *ret_to);
|
||||
|
||||
bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec, int log_level);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user