summaryrefslogtreecommitdiff
path: root/src/journal/mmap-cache.c
diff options
context:
space:
mode:
authorJan Janssen <medhefgo@web.de>2014-09-06 10:36:34 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-10-09 23:16:36 -0400
commit06cc69d44c8ff2b652527357f28acd4cbe77c814 (patch)
treee660b1e180df8ac90be013a0fae8a5e148e8ad9e /src/journal/mmap-cache.c
parent853bd5cc72a0d4cbdd07cc3cabc65bef333a0c71 (diff)
sd-journal: fix sd_journal_enumerate_unique skipping values
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
Diffstat (limited to 'src/journal/mmap-cache.c')
-rw-r--r--src/journal/mmap-cache.c32
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)