summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-12-27 09:04:54 -0700
committerJens Axboe <axboe@kernel.dk>2019-12-27 09:04:54 -0700
commit07b6d913ca185a5005de6ddf842f5e7b7f9620e1 (patch)
tree997213cc6ca8ae654713fd52943d979a004d4d2d
parente421b9ecbef12e7597aff33220d299ff7c31f780 (diff)
downloadliburing-07b6d913ca185a5005de6ddf842f5e7b7f9620e1.tar.gz
liburing-07b6d913ca185a5005de6ddf842f5e7b7f9620e1.tar.bz2
Add io_uring_ring_dontfork()
This marks the mmap'ed ring ranges as not available to a child after a fork() operation. Internally we use madvise(..., MADV_DONTFORK) for this. Since this is a new symbol since 0.3, update micro to 4. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--src/Makefile2
-rw-r--r--src/include/liburing.h1
-rw-r--r--src/liburing.map5
-rw-r--r--src/setup.c32
4 files changed, 39 insertions, 1 deletions
diff --git a/src/Makefile b/src/Makefile
index 88ca597..47e0ba5 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -12,7 +12,7 @@ ENABLE_SHARED ?= 1
soname=liburing.so.1
minor=0
-micro=3
+micro=4
libname=$(soname).$(minor).$(micro)
all_targets += liburing.a
diff --git a/src/include/liburing.h b/src/include/liburing.h
index 7e6ad8f..6f76c99 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -69,6 +69,7 @@ extern int io_uring_queue_init(unsigned entries, struct io_uring *ring,
unsigned flags);
extern int io_uring_queue_mmap(int fd, struct io_uring_params *p,
struct io_uring *ring);
+extern int io_uring_ring_dontfork(struct io_uring *ring);
extern void io_uring_queue_exit(struct io_uring *ring);
unsigned io_uring_peek_batch_cqe(struct io_uring *ring,
struct io_uring_cqe **cqes, unsigned count);
diff --git a/src/liburing.map b/src/liburing.map
index a50b208..e29db68 100644
--- a/src/liburing.map
+++ b/src/liburing.map
@@ -65,3 +65,8 @@ LIBURING_0.3 {
__sys_io_uring_enter;
__sys_io_uring_register;
};
+
+LIBURING_0.4 {
+ global:
+ io_uring_ring_dontfork;
+} LIBURING_0.3;
diff --git a/src/setup.c b/src/setup.c
index 550c0de..c53f234 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -96,6 +96,38 @@ int io_uring_queue_mmap(int fd, struct io_uring_params *p, struct io_uring *ring
return ret;
}
+/*
+ * Ensure that the mmap'ed rings aren't available to a child after a fork(2).
+ * This uses madvise(..., MADV_DONTFORK) on the mmap'ed ranges.
+ */
+int io_uring_ring_dontfork(struct io_uring *ring)
+{
+ size_t len;
+ int ret;
+
+ if (!ring->sq.ring_ptr || !ring->sq.sqes || !ring->cq.ring_ptr)
+ return -EINVAL;
+
+ len = *ring->sq.kring_entries * sizeof(struct io_uring_sqe);
+ ret = madvise(ring->sq.sqes, len, MADV_DONTFORK);
+ if (ret == -1)
+ return -errno;
+
+ len = ring->sq.ring_sz;
+ ret = madvise(ring->sq.ring_ptr, len, MADV_DONTFORK);
+ if (ret == -1)
+ return -errno;
+
+ if (ring->cq.ring_ptr != ring->sq.ring_ptr) {
+ len = ring->cq.ring_sz;
+ ret = madvise(ring->cq.ring_ptr, len, MADV_DONTFORK);
+ if (ret == -1)
+ return -errno;
+ }
+
+ return 0;
+}
+
int io_uring_queue_init_params(unsigned entries, struct io_uring *ring,
struct io_uring_params *p)
{