chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
journal: replace contexts hashmap with a plain array
[elogind.git]
/
src
/
journal
/
journal-file.c
diff --git
a/src/journal/journal-file.c
b/src/journal/journal-file.c
index 4632326d4fb1e2e75144c02a1f22d88f25f6cfd5..7cdaf2920b8c13d94892323bc3c98394facc7fc3 100644
(file)
--- a/
src/journal/journal-file.c
+++ b/
src/journal/journal-file.c
@@
-374,12
+374,13
@@
static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size)
return 0;
}
return 0;
}
-static unsigned type_to_context(
int
type) {
+static unsigned type_to_context(
ObjectType
type) {
/* One context for each type, plus one catch-all for the rest */
/* One context for each type, plus one catch-all for the rest */
- return type > 0 && type < _OBJECT_TYPE_MAX ? type : 0;
+ assert_cc(_OBJECT_TYPE_MAX <= MMAP_CACHE_MAX_CONTEXTS);
+ return type > OBJECT_UNUSED && type < _OBJECT_TYPE_MAX ? type : 0;
}
}
-static int journal_file_move_to(JournalFile *f,
int context
, bool keep_always, uint64_t offset, uint64_t size, void **ret) {
+static int journal_file_move_to(JournalFile *f,
ObjectType type
, bool keep_always, uint64_t offset, uint64_t size, void **ret) {
assert(f);
assert(ret);
assert(f);
assert(ret);
@@
-396,7
+397,7
@@
static int journal_file_move_to(JournalFile *f, int context, bool keep_always, u
return -EADDRNOTAVAIL;
}
return -EADDRNOTAVAIL;
}
- return mmap_cache_get(f->mmap, f->fd, f->prot,
context
, keep_always, offset, size, &f->last_stat, ret);
+ return mmap_cache_get(f->mmap, f->fd, f->prot,
type_to_context(type)
, keep_always, offset, size, &f->last_stat, ret);
}
static uint64_t minimum_header_size(Object *o) {
}
static uint64_t minimum_header_size(Object *o) {
@@
-417,7
+418,7
@@
static uint64_t minimum_header_size(Object *o) {
return table[o->object.type];
}
return table[o->object.type];
}
-int journal_file_move_to_object(JournalFile *f,
int
type, uint64_t offset, Object **ret) {
+int journal_file_move_to_object(JournalFile *f,
ObjectType
type, uint64_t offset, Object **ret) {
int r;
void *t;
Object *o;
int r;
void *t;
Object *o;
@@
-430,7
+431,7
@@
int journal_file_move_to_object(JournalFile *f, int type, uint64_t offset, Objec
if (!VALID64(offset))
return -EFAULT;
if (!VALID64(offset))
return -EFAULT;
- r = journal_file_move_to(f, type
_to_context(type)
, false, offset, sizeof(ObjectHeader), &t);
+ r = journal_file_move_to(f, type, false, offset, sizeof(ObjectHeader), &t);
if (r < 0)
return r;
if (r < 0)
return r;
@@
-446,11
+447,11
@@
int journal_file_move_to_object(JournalFile *f, int type, uint64_t offset, Objec
if (s < minimum_header_size(o))
return -EBADMSG;
if (s < minimum_header_size(o))
return -EBADMSG;
- if (type >
0
&& o->object.type != type)
+ if (type >
OBJECT_UNUSED
&& o->object.type != type)
return -EBADMSG;
if (s > sizeof(ObjectHeader)) {
return -EBADMSG;
if (s > sizeof(ObjectHeader)) {
- r = journal_file_move_to(f, type
_to_context(type)
, false, offset, s, &t);
+ r = journal_file_move_to(f, type, false, offset, s, &t);
if (r < 0)
return r;
if (r < 0)
return r;
@@
-487,14
+488,14
@@
static uint64_t journal_file_entry_seqnum(JournalFile *f, uint64_t *seqnum) {
return r;
}
return r;
}
-int journal_file_append_object(JournalFile *f,
int
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 r;
uint64_t p;
Object *tail, *o;
void *t;
assert(f);
int r;
uint64_t p;
Object *tail, *o;
void *t;
assert(f);
- assert(type >
0
&& type < _OBJECT_TYPE_MAX);
+ assert(type >
OBJECT_UNUSED
&& type < _OBJECT_TYPE_MAX);
assert(size >= sizeof(ObjectHeader));
assert(offset);
assert(ret);
assert(size >= sizeof(ObjectHeader));
assert(offset);
assert(ret);
@@
-507,7
+508,7
@@
int journal_file_append_object(JournalFile *f, int type, uint64_t size, Object *
if (p == 0)
p = le64toh(f->header->header_size);
else {
if (p == 0)
p = le64toh(f->header->header_size);
else {
- r = journal_file_move_to_object(f,
-1
, p, &tail);
+ r = journal_file_move_to_object(f,
OBJECT_UNUSED
, p, &tail);
if (r < 0)
return r;
if (r < 0)
return r;
@@
-2294,7
+2295,7
@@
void journal_file_dump(JournalFile *f) {
p = le64toh(f->header->header_size);
while (p != 0) {
p = le64toh(f->header->header_size);
while (p != 0) {
- r = journal_file_move_to_object(f,
-1
, p, &o);
+ r = journal_file_move_to_object(f,
OBJECT_UNUSED
, p, &o);
if (r < 0)
goto fail;
if (r < 0)
goto fail;