add io_uring_queue_mmap

io_uring_queue_init does not allow the caller to specify sq_thread_cpu
or sq_thread_idle.  Users that want to specify those parameters need to
call io_uring_setup(2) themselves.  Add a helper so that they don't also
have to hand-craft the code to map the submission and completion queues,
and setup the sqe ring.  This allows those applications to still make
use of io_uring_submit and get/wait_completion.

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Jeff Moyer
2019-02-08 14:54:02 -05:00
committed by Jens Axboe
parent bd7ad347f9
commit 996b5a65a5
2 changed files with 21 additions and 6 deletions

View File

@@ -56,6 +56,8 @@ extern int io_uring_register(int fd, unsigned int opcode, void *arg,
*/
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 void io_uring_queue_exit(struct io_uring *ring);
extern int io_uring_get_completion(struct io_uring *ring,
struct io_uring_cqe **cqe_ptr);

View File

@@ -57,6 +57,23 @@ err:
return 0;
}
/*
* For users that want to specify sq_thread_cpu or sq_thread_idle, this
* interface is a convenient helper for mmap()ing the rings.
* Returns -1 on error, or zero on success. On success, 'ring'
* contains the necessary information to read/write to the rings.
*/
int io_uring_queue_mmap(int fd, struct io_uring_params *p, struct io_uring *ring)
{
int ret;
memset(ring, 0, sizeof(*ring));
ret = io_uring_mmap(fd, p, &ring->sq, &ring->cq);
if (!ret)
ring->ring_fd = fd;
return ret;
}
/*
* Returns -1 on error, or zero on success. On success, 'ring'
* contains the necessary information to read/write to the rings.
@@ -64,7 +81,7 @@ err:
int io_uring_queue_init(unsigned entries, struct io_uring *ring, unsigned flags)
{
struct io_uring_params p;
int fd, ret;
int fd;
memset(&p, 0, sizeof(p));
p.flags = flags;
@@ -73,11 +90,7 @@ int io_uring_queue_init(unsigned entries, struct io_uring *ring, unsigned flags)
if (fd < 0)
return fd;
memset(ring, 0, sizeof(*ring));
ret = io_uring_mmap(fd, &p, &ring->sq, &ring->cq);
if (!ret)
ring->ring_fd = fd;
return ret;
return io_uring_queue_mmap(fd, &p, ring);
}
void io_uring_queue_exit(struct io_uring *ring)