diff options
author | Vito Caputo <vito.caputo@coreos.com> | 2016-02-05 03:44:05 -0800 |
---|---|---|
committer | Vito Caputo <vito.caputo@coreos.com> | 2016-02-05 07:43:46 -0800 |
commit | db87967e5b0ca8fac6be77ba926ce785a3277773 (patch) | |
tree | 245fd1dbcd996facbbb1664ed221ce64e0247543 /src/journal/mmap-cache.c | |
parent | 90d222c190fc9d4c91f04a1bf0c90c259dcff6d2 (diff) |
journal: move mmap() ENOMEM loop to function
Introduces mmap_try_harder()
Diffstat (limited to 'src/journal/mmap-cache.c')
-rw-r--r-- | src/journal/mmap-cache.c | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c index 0a10fe36cc..4636e4b395 100644 --- a/src/journal/mmap-cache.c +++ b/src/journal/mmap-cache.c @@ -469,6 +469,33 @@ static int find_mmap( return 1; } +static int mmap_try_harder(MMapCache *m, void *addr, int fd, int prot, int flags, uint64_t offset, size_t size, void **res) { + void *ptr; + + assert(m); + assert(fd >= 0); + assert(res); + + for (;;) { + int r; + + ptr = mmap(addr, size, prot, flags, fd, offset); + if (ptr != MAP_FAILED) + break; + if (errno != ENOMEM) + return -errno; + + r = make_room(m); + if (r < 0) + return r; + if (r == 0) + return -ENOMEM; + } + + *res = ptr; + return 0; +} + static int add_mmap( MMapCache *m, int fd, @@ -522,19 +549,9 @@ static int add_mmap( wsize = PAGE_ALIGN(st->st_size - woffset); } - for (;;) { - d = mmap(NULL, wsize, prot, MAP_SHARED, fd, woffset); - if (d != MAP_FAILED) - break; - if (errno != ENOMEM) - return -errno; - - r = make_room(m); - if (r < 0) - return r; - if (r == 0) - return -ENOMEM; - } + r = mmap_try_harder(m, NULL, fd, prot, MAP_SHARED, woffset, wsize, &d); + if (r < 0) + return r; c = context_add(m, context); if (!c) |