Skip to content

Commit 74f3e87

Browse files
isilenceaxboe
authored andcommitted
io_uring/rw: move ki_complete init into prep
Initialise ki_complete during request prep stage, we'll depend on it not being reset during issue in the following patch. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/817624086bd5f0448b08c80623399919fda82f34.1739919038.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 4e43133 commit 74f3e87

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

io_uring/rw.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include "poll.h"
2424
#include "rw.h"
2525

26+
static void io_complete_rw(struct kiocb *kiocb, long res);
27+
static void io_complete_rw_iopoll(struct kiocb *kiocb, long res);
28+
2629
struct io_rw {
2730
/* NOTE: kiocb has the file as the first member, so don't do it here */
2831
struct kiocb kiocb;
@@ -289,6 +292,11 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
289292
rw->kiocb.dio_complete = NULL;
290293
rw->kiocb.ki_flags = 0;
291294

295+
if (req->ctx->flags & IORING_SETUP_IOPOLL)
296+
rw->kiocb.ki_complete = io_complete_rw_iopoll;
297+
else
298+
rw->kiocb.ki_complete = io_complete_rw;
299+
292300
rw->addr = READ_ONCE(sqe->addr);
293301
rw->len = READ_ONCE(sqe->len);
294302
rw->flags = READ_ONCE(sqe->rw_flags);
@@ -817,10 +825,8 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type)
817825
if (ctx->flags & IORING_SETUP_IOPOLL) {
818826
if (!(kiocb->ki_flags & IOCB_DIRECT) || !file->f_op->iopoll)
819827
return -EOPNOTSUPP;
820-
821828
kiocb->private = NULL;
822829
kiocb->ki_flags |= IOCB_HIPRI;
823-
kiocb->ki_complete = io_complete_rw_iopoll;
824830
req->iopoll_completed = 0;
825831
if (ctx->flags & IORING_SETUP_HYBRID_IOPOLL) {
826832
/* make sure every req only blocks once*/
@@ -830,7 +836,6 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type)
830836
} else {
831837
if (kiocb->ki_flags & IOCB_HIPRI)
832838
return -EINVAL;
833-
kiocb->ki_complete = io_complete_rw;
834839
}
835840

836841
if (req->flags & REQ_F_HAS_METADATA) {

0 commit comments

Comments
 (0)