diff options
Diffstat (limited to 'src/journal/mmap-cache.c')
-rw-r--r-- | src/journal/mmap-cache.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c index 2d268fc332..b7db6f1da5 100644 --- a/src/journal/mmap-cache.c +++ b/src/journal/mmap-cache.c @@ -352,7 +352,8 @@ static int try_context( bool keep_always, uint64_t offset, size_t size, - void **ret) { + void **ret, + void **release_cookie) { Context *c; @@ -381,6 +382,8 @@ static int try_context( if (ret) *ret = (uint8_t*) c->window->ptr + (offset - c->window->offset); + if (keep_always && release_cookie) + *release_cookie = c->window; return 1; } @@ -392,7 +395,8 @@ static int find_mmap( bool keep_always, uint64_t offset, size_t size, - void **ret) { + void **ret, + void **release_cookie) { FileDescriptor *f; Window *w; @@ -425,6 +429,8 @@ static int find_mmap( if (ret) *ret = (uint8_t*) w->ptr + (offset - w->offset); + if (keep_always && release_cookie) + *release_cookie = c->window; return 1; } @@ -437,7 +443,8 @@ static int add_mmap( uint64_t offset, size_t size, struct stat *st, - void **ret) { + void **ret, + void **release_cookie) { uint64_t woffset, wsize; Context *c; @@ -521,6 +528,8 @@ static int add_mmap( if (ret) *ret = (uint8_t*) w->ptr + (offset - w->offset); + if (keep_always && release_cookie) + *release_cookie = c->window; return 1; outofmem: @@ -537,7 +546,8 @@ int mmap_cache_get( uint64_t offset, size_t size, struct stat *st, - void **ret) { + void **ret, + void **release_cookie) { int r; @@ -547,14 +557,14 @@ int mmap_cache_get( 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 */ - 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; @@ -563,16 +573,13 @@ int mmap_cache_get( 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 prot, - unsigned context, - uint64_t offset, - size_t size) { + void *release_cookie) { FileDescriptor *f; Window *w; @@ -580,7 +587,6 @@ int mmap_cache_release( assert(m); assert(m->n_ref > 0); assert(fd >= 0); - assert(size > 0); f = hashmap_get(m->fds, INT_TO_PTR(fd + 1)); if (!f) @@ -589,7 +595,7 @@ int mmap_cache_release( assert(f->fd == fd); LIST_FOREACH(by_fd, w, f->windows) - if (window_matches(w, fd, prot, offset, size)) + if (w == release_cookie) break; if (!w) |