summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-09-06 13:30:28 -0600
committerJens Axboe <axboe@kernel.dk>2019-09-06 13:30:28 -0600
commit164e9cb455c004c86c2c241c39481fc6b136ca9c (patch)
tree4e77da1bb45d10239522496301a9e829f5232d44
parent46a0646ba0786c2658085ded12e6ff3148ae731a (diff)
downloadliburing-164e9cb455c004c86c2c241c39481fc6b136ca9c.tar.gz
liburing-164e9cb455c004c86c2c241c39481fc6b136ca9c.tar.bz2
src/setup: unify ring munmap()
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--src/setup.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/setup.c b/src/setup.c
index 48c96a0..dda4d1c 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -9,6 +9,13 @@
#include "liburing/io_uring.h"
#include "liburing.h"
+static void io_uring_unmap_rings(struct io_uring_sq *sq, struct io_uring_cq *cq)
+{
+ munmap(sq->ring_ptr, sq->ring_sz);
+ if (cq->ring_ptr && cq->ring_ptr != sq->ring_ptr)
+ munmap(cq->ring_ptr, cq->ring_sz);
+}
+
static int io_uring_mmap(int fd, struct io_uring_params *p,
struct io_uring_sq *sq, struct io_uring_cq *cq)
{
@@ -19,9 +26,8 @@ static int io_uring_mmap(int fd, struct io_uring_params *p,
cq->ring_sz = p->cq_off.cqes + p->cq_entries * sizeof(struct io_uring_cqe);
if (p->features & IORING_FEAT_SINGLE_MMAP) {
- if (cq->ring_sz > sq->ring_sz) {
+ if (cq->ring_sz > sq->ring_sz)
sq->ring_sz = cq->ring_sz;
- }
cq->ring_sz = sq->ring_sz;
}
sq->ring_ptr = mmap(0, sq->ring_sz, PROT_READ | PROT_WRITE,
@@ -35,6 +41,7 @@ static int io_uring_mmap(int fd, struct io_uring_params *p,
cq->ring_ptr = mmap(0, cq->ring_sz, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_CQ_RING);
if (cq->ring_ptr == MAP_FAILED) {
+ cq->ring_ptr = NULL;
ret = -errno;
goto err;
}
@@ -54,11 +61,8 @@ static int io_uring_mmap(int fd, struct io_uring_params *p,
IORING_OFF_SQES);
if (sq->sqes == MAP_FAILED) {
ret = -errno;
- if (cq->ring_ptr != sq->ring_ptr) {
- munmap(cq->ring_ptr, cq->ring_sz);
- }
err:
- munmap(sq->ring_ptr, sq->ring_sz);
+ io_uring_unmap_rings(sq, cq);
return ret;
}
@@ -86,7 +90,7 @@ int io_uring_queue_mmap(int fd, struct io_uring_params *p, struct io_uring *ring
if (!ret) {
ring->flags = p->flags;
ring->ring_fd = fd;
- }
+ }
return ret;
}
@@ -119,9 +123,6 @@ void io_uring_queue_exit(struct io_uring *ring)
struct io_uring_cq *cq = &ring->cq;
munmap(sq->sqes, *sq->kring_entries * sizeof(struct io_uring_sqe));
- munmap(sq->ring_ptr, sq->ring_sz);
- if (cq->ring_ptr != sq->ring_ptr) {
- munmap(cq->ring_ptr, cq->ring_sz);
- }
+ io_uring_unmap_rings(sq, cq);
close(ring->ring_fd);
}