summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
853bd5c)
sd_journal_enumerate_unique will lock its mmap window to prevent it
from being released by calling mmap_cache_get with keep_always=true.
This call may return windows that are wider, but compatible with the
parameters provided to it.
This can result in a mismatch where the window to be released cannot
properly be selected, because we have more than one window matching the
parameters of mmap_cache_release. Therefore, introduce a release_cookie
to be used when releasing the window.
https://bugs.freedesktop.org/show_bug.cgi?id=79380
- 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, context, keep_always, offset, size, &f->last_stat, ret, NULL);
}
static uint64_t minimum_header_size(Object *o) {
}
static uint64_t minimum_header_size(Object *o) {
return type > 0 && type < _OBJECT_TYPE_MAX ? type : 0;
}
return type > 0 && type < _OBJECT_TYPE_MAX ? type : 0;
}
-static inline int journal_file_object_keep(JournalFile *f, Object *o, uint64_t offset) {
+static inline int journal_file_object_keep(JournalFile *f, Object *o, uint64_t offset, void **release_cookie) {
unsigned context = type_to_context(o->object.type);
uint64_t s = le64toh(o->object.size);
return mmap_cache_get(f->mmap, f->fd, f->prot, context, true,
unsigned context = type_to_context(o->object.type);
uint64_t s = le64toh(o->object.size);
return mmap_cache_get(f->mmap, f->fd, f->prot, context, true,
- offset, s, &f->last_stat, NULL);
+ offset, s, &f->last_stat, NULL, release_cookie);
-static inline int journal_file_object_release(JournalFile *f, Object *o, uint64_t offset) {
- unsigned context = type_to_context(o->object.type);
- uint64_t s = le64toh(o->object.size);
-
- return mmap_cache_release(f->mmap, f->fd, f->prot, context, offset, s);
+static inline int journal_file_object_release(JournalFile *f, void *release_cookie) {
+ return mmap_cache_release(f->mmap, f->fd, release_cookie);
- r = mmap_cache_get(m, fd, PROT_READ|PROT_WRITE, 0, false, c * sizeof(uint64_t), sizeof(uint64_t), NULL, (void **) &z);
+ r = mmap_cache_get(m, fd, PROT_READ|PROT_WRITE, 0, false, c * sizeof(uint64_t), sizeof(uint64_t), NULL, (void **) &z, NULL);
bool keep_always,
uint64_t offset,
size_t size,
bool keep_always,
uint64_t offset,
size_t size,
+ void **ret,
+ void **release_cookie) {
if (ret)
*ret = (uint8_t*) c->window->ptr + (offset - c->window->offset);
if (ret)
*ret = (uint8_t*) c->window->ptr + (offset - c->window->offset);
+ if (keep_always && release_cookie)
+ *release_cookie = c->window;
bool keep_always,
uint64_t offset,
size_t size,
bool keep_always,
uint64_t offset,
size_t size,
+ void **ret,
+ void **release_cookie) {
FileDescriptor *f;
Window *w;
FileDescriptor *f;
Window *w;
if (ret)
*ret = (uint8_t*) w->ptr + (offset - w->offset);
if (ret)
*ret = (uint8_t*) w->ptr + (offset - w->offset);
+ if (keep_always && release_cookie)
+ *release_cookie = c->window;
uint64_t offset,
size_t size,
struct stat *st,
uint64_t offset,
size_t size,
struct stat *st,
+ void **ret,
+ void **release_cookie) {
uint64_t woffset, wsize;
Context *c;
uint64_t woffset, wsize;
Context *c;
if (ret)
*ret = (uint8_t*) w->ptr + (offset - w->offset);
if (ret)
*ret = (uint8_t*) w->ptr + (offset - w->offset);
+ if (keep_always && release_cookie)
+ *release_cookie = c->window;
uint64_t offset,
size_t size,
struct stat *st,
uint64_t offset,
size_t size,
struct stat *st,
+ void **ret,
+ void **release_cookie) {
assert(size > 0);
/* Check whether the current context is the right one already */
assert(size > 0);
/* Check whether the current context is the right one already */
- r = try_context(m, fd, prot, context, keep_always, offset, size, ret);
+ r = try_context(m, fd, prot, context, keep_always, offset, size, ret, release_cookie);
if (r != 0) {
m->n_hit ++;
return r;
}
/* Search for a matching mmap */
if (r != 0) {
m->n_hit ++;
return r;
}
/* Search for a matching mmap */
- r = find_mmap(m, fd, prot, context, keep_always, offset, size, ret);
+ r = find_mmap(m, fd, prot, context, keep_always, offset, size, ret, release_cookie);
if (r != 0) {
m->n_hit ++;
return r;
if (r != 0) {
m->n_hit ++;
return r;
m->n_missed++;
/* Create a new mmap */
m->n_missed++;
/* Create a new mmap */
- return add_mmap(m, fd, prot, context, keep_always, offset, size, st, ret);
+ return add_mmap(m, fd, prot, context, keep_always, offset, size, st, ret, release_cookie);
}
int mmap_cache_release(
MMapCache *m,
int fd,
}
int mmap_cache_release(
MMapCache *m,
int fd,
- int prot,
- unsigned context,
- uint64_t offset,
- size_t size) {
+ void *release_cookie) {
FileDescriptor *f;
Window *w;
FileDescriptor *f;
Window *w;
assert(m);
assert(m->n_ref > 0);
assert(fd >= 0);
assert(m);
assert(m->n_ref > 0);
assert(fd >= 0);
f = hashmap_get(m->fds, INT_TO_PTR(fd + 1));
if (!f)
f = hashmap_get(m->fds, INT_TO_PTR(fd + 1));
if (!f)
assert(f->fd == fd);
LIST_FOREACH(by_fd, w, f->windows)
assert(f->fd == fd);
LIST_FOREACH(by_fd, w, f->windows)
- if (window_matches(w, fd, prot, offset, size))
+ if (w == release_cookie)
uint64_t offset,
size_t size,
struct stat *st,
uint64_t offset,
size_t size,
struct stat *st,
+ void **ret,
+ void **release_cookie);
int mmap_cache_release(
MMapCache *m,
int fd,
int mmap_cache_release(
MMapCache *m,
int fd,
- int prot,
- unsigned context,
- uint64_t offset,
- size_t size);
void mmap_cache_close_fd(MMapCache *m, int fd);
void mmap_cache_close_context(MMapCache *m, unsigned context);
void mmap_cache_close_fd(MMapCache *m, int fd);
void mmap_cache_close_context(MMapCache *m, unsigned context);
size_t ol;
bool found;
int r;
size_t ol;
bool found;
int r;
/* Proceed to next data object in the field's linked list */
if (j->unique_offset == 0) {
/* Proceed to next data object in the field's linked list */
if (j->unique_offset == 0) {
- r = journal_file_object_keep(j->unique_file, o, j->unique_offset);
+ r = journal_file_object_keep(j->unique_file, o, j->unique_offset, &release_cookie);
- if (found)
- continue;
-
- r = journal_file_object_release(j->unique_file, o, j->unique_offset);
+ r = journal_file_object_release(j->unique_file, release_cookie);
+ if (found)
+ continue;
+
r = return_data(j, j->unique_file, o, data, l);
if (r < 0)
return r;
r = return_data(j, j->unique_file, o, data, l);
if (r < 0)
return r;
assert(z >= 0);
unlink(pz);
assert(z >= 0);
unlink(pz);
- r = mmap_cache_get(m, x, PROT_READ, 0, false, 1, 2, NULL, &p);
+ r = mmap_cache_get(m, x, PROT_READ, 0, false, 1, 2, NULL, &p, NULL);
- r = mmap_cache_get(m, x, PROT_READ, 0, false, 2, 2, NULL, &q);
+ r = mmap_cache_get(m, x, PROT_READ, 0, false, 2, 2, NULL, &q, NULL);
assert(r >= 0);
assert((uint8_t*) p + 1 == (uint8_t*) q);
assert(r >= 0);
assert((uint8_t*) p + 1 == (uint8_t*) q);
- r = mmap_cache_get(m, x, PROT_READ, 1, false, 3, 2, NULL, &q);
+ r = mmap_cache_get(m, x, PROT_READ, 1, false, 3, 2, NULL, &q, NULL);
assert(r >= 0);
assert((uint8_t*) p + 2 == (uint8_t*) q);
assert(r >= 0);
assert((uint8_t*) p + 2 == (uint8_t*) q);
- r = mmap_cache_get(m, x, PROT_READ, 0, false, 16ULL*1024ULL*1024ULL, 2, NULL, &p);
+ r = mmap_cache_get(m, x, PROT_READ, 0, false, 16ULL*1024ULL*1024ULL, 2, NULL, &p, NULL);
- r = mmap_cache_get(m, x, PROT_READ, 1, false, 16ULL*1024ULL*1024ULL+1, 2, NULL, &q);
+ r = mmap_cache_get(m, x, PROT_READ, 1, false, 16ULL*1024ULL*1024ULL+1, 2, NULL, &q, NULL);
assert(r >= 0);
assert((uint8_t*) p + 1 == (uint8_t*) q);
assert(r >= 0);
assert((uint8_t*) p + 1 == (uint8_t*) q);