Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma
[linux-block.git] / io_uring / uring_cmd.c
index 9a1dee5718724a109461560b39fc789132d6a13b..5113c9a48583bfa43a4698a988724d081f5349e7 100644 (file)
 #include "rsrc.h"
 #include "uring_cmd.h"
 
-static void io_uring_cmd_work(struct io_kiocb *req, bool *locked)
+static void io_uring_cmd_work(struct io_kiocb *req, struct io_tw_state *ts)
 {
        struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
-       unsigned issue_flags = *locked ? 0 : IO_URING_F_UNLOCKED;
+       unsigned issue_flags = ts->locked ? 0 : IO_URING_F_UNLOCKED;
 
        ioucmd->task_work_cb(ioucmd, issue_flags);
 }
@@ -54,11 +54,15 @@ void io_uring_cmd_done(struct io_uring_cmd *ioucmd, ssize_t ret, ssize_t res2,
        io_req_set_res(req, ret, 0);
        if (req->ctx->flags & IORING_SETUP_CQE32)
                io_req_set_cqe32_extra(req, res2, 0);
-       if (req->ctx->flags & IORING_SETUP_IOPOLL)
+       if (req->ctx->flags & IORING_SETUP_IOPOLL) {
                /* order with io_iopoll_req_issued() checking ->iopoll_complete */
                smp_store_release(&req->iopoll_completed, 1);
-       else
-               io_req_complete_post(req, issue_flags);
+       } else {
+               struct io_tw_state ts = {
+                       .locked = !(issue_flags & IO_URING_F_UNLOCKED),
+               };
+               io_req_task_complete(req, &ts);
+       }
 }
 EXPORT_SYMBOL_GPL(io_uring_cmd_done);
 
@@ -73,6 +77,7 @@ int io_uring_cmd_prep_async(struct io_kiocb *req)
        cmd_size = uring_cmd_pdu_size(req->ctx->flags & IORING_SETUP_SQE128);
 
        memcpy(req->async_data, ioucmd->cmd, cmd_size);
+       ioucmd->cmd = req->async_data;
        return 0;
 }
 
@@ -129,9 +134,6 @@ int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags)
                WRITE_ONCE(ioucmd->cookie, NULL);
        }
 
-       if (req_has_async_data(req))
-               ioucmd->cmd = req->async_data;
-
        ret = file->f_op->uring_cmd(ioucmd, issue_flags);
        if (ret == -EAGAIN) {
                if (!req_has_async_data(req)) {