f->offline_state = OFFLINE_JOINED;
- if (mmap_cache_got_sigbus(f->mmap, f->cache_fd))
+ if (mmap_cache_got_sigbus(f->cache_fd))
return -EIO;
return 0;
}
}
- if (mmap_cache_got_sigbus(f->mmap, f->cache_fd))
+ if (mmap_cache_got_sigbus(f->cache_fd))
return -EIO;
switch (f->header->state) {
journal_file_set_offline(f, true);
if (f->mmap && f->cache_fd)
- mmap_cache_free_fd(f->mmap, f->cache_fd);
+ mmap_cache_free_fd(f->cache_fd);
if (f->fd >= 0 && f->defrag_on_close) {
if (size > PAGE_ALIGN_DOWN(UINT64_MAX) - offset)
return -EINVAL;
- if (mmap_cache_got_sigbus(f->mmap, f->cache_fd))
+ if (mmap_cache_got_sigbus(f->cache_fd))
return -EIO;
old_header_size = le64toh(READ_NOW(f->header->header_size));
return -EADDRNOTAVAIL;
}
- return mmap_cache_get(f->mmap, f->cache_fd, type_to_context(type), keep_always, offset, size, &f->last_stat, ret);
+ return mmap_cache_get(f->cache_fd, type_to_context(type), keep_always, offset, size, &f->last_stat, ret);
}
static uint64_t minimum_header_size(Object *o) {
* it is very likely just an effect of a nullified replacement
* mapping page */
- if (mmap_cache_got_sigbus(f->mmap, f->cache_fd))
+ if (mmap_cache_got_sigbus(f->cache_fd))
r = -EIO;
if (f->post_change_timer)
goto fail;
}
- r = mmap_cache_get(f->mmap, f->cache_fd, CONTEXT_HEADER, true, 0, PAGE_ALIGN(sizeof(Header)), &f->last_stat, &h);
+ r = mmap_cache_get(f->cache_fd, CONTEXT_HEADER, true, 0, PAGE_ALIGN(sizeof(Header)), &f->last_stat, &h);
if (r == -EINVAL) {
/* Some file systems (jffs2 or p9fs) don't support mmap() properly (or only read-only
* mmap()), and return EINVAL in that case. Let's propagate that as a more recognizable error
#endif
}
- if (mmap_cache_got_sigbus(f->mmap, f->cache_fd)) {
+ if (mmap_cache_got_sigbus(f->cache_fd)) {
r = -EIO;
goto fail;
}
return 0;
fail:
- if (f->cache_fd && mmap_cache_got_sigbus(f->mmap, f->cache_fd))
+ if (f->cache_fd && mmap_cache_got_sigbus(f->cache_fd))
r = -EIO;
(void) journal_file_close(f);
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->cache_fd))
return -EIO;
return r;
return 0;
}
-static int contains_uint64(MMapCache *m, MMapFileDescriptor *f, uint64_t n, uint64_t p) {
+static int contains_uint64(MMapFileDescriptor *f, uint64_t n, uint64_t p) {
uint64_t a, b;
int r;
- assert(m);
assert(f);
/* Bisection ... */
c = (a + b) / 2;
- r = mmap_cache_get(m, f, 0, false, c * sizeof(uint64_t), sizeof(uint64_t), NULL, (void **) &z);
+ r = mmap_cache_get(f, 0, false, c * sizeof(uint64_t), sizeof(uint64_t), NULL, (void **) &z);
if (r < 0)
return r;
assert(f);
assert(cache_entry_fd);
- if (!contains_uint64(f->mmap, cache_entry_fd, n_entries, entry_p)) {
+ if (!contains_uint64(cache_entry_fd, n_entries, entry_p)) {
error(data_p, "Data object references invalid entry at "OFSfmt, entry_p);
return -EBADMSG;
}
return -EBADMSG;
}
- if (!contains_uint64(f->mmap, cache_entry_array_fd, n_entry_arrays, a)) {
+ if (!contains_uint64(cache_entry_array_fd, n_entry_arrays, a)) {
error(p, "Invalid array offset "OFSfmt, a);
return -EBADMSG;
}
Object *o;
uint64_t next;
- if (!contains_uint64(f->mmap, cache_data_fd, n_data, p)) {
+ if (!contains_uint64(cache_data_fd, n_data, p)) {
error(p, "Invalid data object at hash entry %"PRIu64" of %"PRIu64, i, n);
return -EBADMSG;
}
q = le64toh(o->entry.items[i].object_offset);
h = le64toh(o->entry.items[i].hash);
- if (!contains_uint64(f->mmap, cache_data_fd, n_data, q)) {
+ if (!contains_uint64(cache_data_fd, n_data, q)) {
error(p, "Invalid data object of entry");
return -EBADMSG;
}
return -EBADMSG;
}
- if (!contains_uint64(f->mmap, cache_entry_array_fd, n_entry_arrays, a)) {
+ if (!contains_uint64(cache_entry_array_fd, n_entry_arrays, a)) {
error(a, "Invalid array %"PRIu64" of %"PRIu64, i, n);
return -EBADMSG;
}
}
last = p;
- if (!contains_uint64(f->mmap, cache_entry_fd, n_entries, p)) {
+ if (!contains_uint64(cache_entry_fd, n_entries, p)) {
error(a, "Invalid array entry at %"PRIu64" of %"PRIu64, i, n);
return -EBADMSG;
}
if (show_progress)
flush_progress();
- mmap_cache_free_fd(f->mmap, cache_data_fd);
- mmap_cache_free_fd(f->mmap, cache_entry_fd);
- mmap_cache_free_fd(f->mmap, cache_entry_array_fd);
+ mmap_cache_free_fd(cache_data_fd);
+ mmap_cache_free_fd(cache_entry_fd);
+ mmap_cache_free_fd(cache_entry_array_fd);
if (first_contained)
*first_contained = le64toh(f->header->head_entry_realtime);
100 * p / f->last_stat.st_size);
if (cache_data_fd)
- mmap_cache_free_fd(f->mmap, cache_data_fd);
+ mmap_cache_free_fd(cache_data_fd);
if (cache_entry_fd)
- mmap_cache_free_fd(f->mmap, cache_entry_fd);
+ mmap_cache_free_fd(cache_entry_fd);
if (cache_entry_array_fd)
- mmap_cache_free_fd(f->mmap, cache_entry_array_fd);
+ mmap_cache_free_fd(cache_entry_array_fd);
return r;
}
}
static int try_context(
- MMapCache *m,
MMapFileDescriptor *f,
unsigned context,
bool keep_always,
Context *c;
- assert(m);
- assert(m->n_ref > 0);
assert(f);
+ assert(f->cache);
+ assert(f->cache->n_ref > 0);
assert(size > 0);
assert(ret);
- c = m->contexts[context];
+ c = f->cache->contexts[context];
if (!c)
return 0;
c->window->keep_always = c->window->keep_always || keep_always;
*ret = (uint8_t*) c->window->ptr + (offset - c->window->offset);
+ f->cache->n_context_cache_hit++;
return 1;
}
static int find_mmap(
- MMapCache *m,
MMapFileDescriptor *f,
unsigned context,
bool keep_always,
Window *w;
Context *c;
- assert(m);
- assert(m->n_ref > 0);
assert(f);
+ assert(f->cache);
+ assert(f->cache->n_ref > 0);
assert(size > 0);
if (f->sigbus)
if (!w)
return 0;
- c = context_add(m, context);
+ c = context_add(f->cache, context);
if (!c)
return -ENOMEM;
w->keep_always = w->keep_always || keep_always;
*ret = (uint8_t*) w->ptr + (offset - w->offset);
+ f->cache->n_window_list_hit++;
return 1;
}
-static int mmap_try_harder(MMapCache *m, void *addr, MMapFileDescriptor *f, int flags, uint64_t offset, size_t size, void **res) {
+static int mmap_try_harder(MMapFileDescriptor *f, void *addr, int flags, uint64_t offset, size_t size, void **res) {
void *ptr;
- assert(m);
assert(f);
assert(res);
if (errno != ENOMEM)
return negative_errno();
- r = make_room(m);
+ r = make_room(f->cache);
if (r < 0)
return r;
if (r == 0)
}
static int add_mmap(
- MMapCache *m,
MMapFileDescriptor *f,
unsigned context,
bool keep_always,
void *d;
int r;
- assert(m);
- assert(m->n_ref > 0);
assert(f);
+ assert(f->cache);
+ assert(f->cache->n_ref > 0);
assert(size > 0);
assert(ret);
wsize = PAGE_ALIGN(st->st_size - woffset);
}
- r = mmap_try_harder(m, NULL, f, MAP_SHARED, woffset, wsize, &d);
+ r = mmap_try_harder(f, NULL, MAP_SHARED, woffset, wsize, &d);
if (r < 0)
return r;
- c = context_add(m, context);
+ c = context_add(f->cache, context);
if (!c)
goto outofmem;
- w = window_add(m, f, keep_always, woffset, wsize, d);
+ w = window_add(f->cache, f, keep_always, woffset, wsize, d);
if (!w)
goto outofmem;
}
int mmap_cache_get(
- MMapCache *m,
MMapFileDescriptor *f,
unsigned context,
bool keep_always,
int r;
- assert(m);
- assert(m->n_ref > 0);
assert(f);
+ assert(f->cache);
+ assert(f->cache->n_ref > 0);
assert(size > 0);
assert(ret);
assert(context < MMAP_CACHE_MAX_CONTEXTS);
/* Check whether the current context is the right one already */
- r = try_context(m, f, context, keep_always, offset, size, ret);
- if (r != 0) {
- m->n_context_cache_hit++;
+ r = try_context(f, context, keep_always, offset, size, ret);
+ if (r != 0)
return r;
- }
/* Search for a matching mmap */
- r = find_mmap(m, f, context, keep_always, offset, size, ret);
- if (r != 0) {
- m->n_window_list_hit++;
+ r = find_mmap(f, context, keep_always, offset, size, ret);
+ if (r != 0)
return r;
- }
- m->n_missed++;
+ f->cache->n_missed++;
/* Create a new mmap */
- return add_mmap(m, f, context, keep_always, offset, size, st, ret);
+ return add_mmap(f, context, keep_always, offset, size, st, ret);
}
void mmap_cache_stats_log_debug(MMapCache *m) {
}
}
-bool mmap_cache_got_sigbus(MMapCache *m, MMapFileDescriptor *f) {
- assert(m);
+bool mmap_cache_got_sigbus(MMapFileDescriptor *f) {
assert(f);
- mmap_cache_process_sigbus(m);
+ mmap_cache_process_sigbus(f->cache);
return f->sigbus;
}
return f;
}
-void mmap_cache_free_fd(MMapCache *m, MMapFileDescriptor *f) {
- assert(m);
+void mmap_cache_free_fd(MMapFileDescriptor *f) {
assert(f);
+ assert(f->cache);
/* Make sure that any queued SIGBUS are first dispatched, so
* that we don't end up with a SIGBUS entry we cannot relate
* to any existing memory map */
- mmap_cache_process_sigbus(m);
+ mmap_cache_process_sigbus(f->cache);
while (f->windows)
window_free(f->windows);
MMapCache* mmap_cache_unref(MMapCache *m);
int mmap_cache_get(
- MMapCache *m,
MMapFileDescriptor *f,
unsigned context,
bool keep_always,
struct stat *st,
void **ret);
MMapFileDescriptor * mmap_cache_add_fd(MMapCache *m, int fd, int prot);
-void mmap_cache_free_fd(MMapCache *m, MMapFileDescriptor *f);
+void mmap_cache_free_fd(MMapFileDescriptor *f);
void mmap_cache_stats_log_debug(MMapCache *m);
-bool mmap_cache_got_sigbus(MMapCache *m, MMapFileDescriptor *f);
+bool mmap_cache_got_sigbus(MMapFileDescriptor *f);
assert_se(z >= 0);
unlink(pz);
- r = mmap_cache_get(m, fx, 0, false, 1, 2, NULL, &p);
+ r = mmap_cache_get(fx, 0, false, 1, 2, NULL, &p);
assert_se(r >= 0);
- r = mmap_cache_get(m, fx, 0, false, 2, 2, NULL, &q);
+ r = mmap_cache_get(fx, 0, false, 2, 2, NULL, &q);
assert_se(r >= 0);
assert_se((uint8_t*) p + 1 == (uint8_t*) q);
- r = mmap_cache_get(m, fx, 1, false, 3, 2, NULL, &q);
+ r = mmap_cache_get(fx, 1, false, 3, 2, NULL, &q);
assert_se(r >= 0);
assert_se((uint8_t*) p + 2 == (uint8_t*) q);
- r = mmap_cache_get(m, fx, 0, false, 16ULL*1024ULL*1024ULL, 2, NULL, &p);
+ r = mmap_cache_get(fx, 0, false, 16ULL*1024ULL*1024ULL, 2, NULL, &p);
assert_se(r >= 0);
- r = mmap_cache_get(m, fx, 1, false, 16ULL*1024ULL*1024ULL+1, 2, NULL, &q);
+ r = mmap_cache_get(fx, 1, false, 16ULL*1024ULL*1024ULL+1, 2, NULL, &q);
assert_se(r >= 0);
assert_se((uint8_t*) p + 1 == (uint8_t*) q);
- mmap_cache_free_fd(m, fx);
+ mmap_cache_free_fd(fx);
mmap_cache_unref(m);
safe_close(x);