From 4efd092e07207d18b2f0fdbc6e68e93d5e7c93b0 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Sun, 23 Feb 2020 23:06:58 -0800 Subject: [PATCH v1 2/2] WIP: io_uring: Separate blocking/nonblocking io_issue_sqe cases. Signed-off-by: Andres Freund --- fs/io_uring.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 9a8fda8b28c9..b149ab57c5b4 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -4284,20 +4284,12 @@ static void io_cleanup_req(struct io_kiocb *req) req->flags &= ~REQ_F_NEED_CLEANUP; } -static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe, +static inline int __io_issue_sqe(u8 opcode, struct io_kiocb *req, const struct io_uring_sqe *sqe, struct io_kiocb **nxt, bool force_nonblock) { struct io_ring_ctx *ctx = req->ctx; - /* allow compiler to infer opcode doesn't change */ - u8 opcode = req->opcode; int ret; - if (sqe) { - ret = io_req_prep(opcode, req, sqe, force_nonblock); - if (ret) - return ret; - } - switch (opcode) { case IORING_OP_NOP: ret = io_nop(req); @@ -4405,6 +4397,25 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe, return 0; } +static int io_prep_issue_sqe_nonblock(struct io_kiocb *req, const struct io_uring_sqe *sqe, + struct io_kiocb **nxt) +{ + /* allow compiler to infer opcode doesn't change */ + u8 opcode = req->opcode; + int ret; + + ret = io_req_prep(opcode, req, sqe, true); + if (ret) + return ret; + + return __io_issue_sqe(opcode, req, NULL, nxt, true); +} + +static int io_issue_sqe_block(struct io_kiocb *req, struct io_kiocb **nxt) +{ + return __io_issue_sqe(req->opcode, req, NULL, nxt, false); +} + static void io_wq_submit_work(struct io_wq_work **workptr) { struct io_wq_work *work = *workptr; @@ -4421,7 +4432,7 @@ static void io_wq_submit_work(struct io_wq_work **workptr) if (!ret) { req->in_async = true; do { - ret = io_issue_sqe(req, NULL, &nxt, false); + ret = io_issue_sqe_block(req, &nxt); /* * We can get EAGAIN for polled IO even though we're * forcing a sync submission from here, since we can't @@ -4616,7 +4627,7 @@ static void __io_queue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe) again: linked_timeout = io_prep_linked_timeout(req); - ret = io_issue_sqe(req, sqe, &nxt, true); + ret = io_prep_issue_sqe_nonblock(req, sqe, &nxt); /* * We async punt it if the file wasn't marked NOWAIT, or if the file -- 2.25.0.114.g5b0ca878e0