Skip to content

Commit 230d50d

Browse files
committed
io_uring: move reissue into regular IO path
It's non-obvious how retry is done for block backed files, when it happens off the kiocb done path. It also makes it tricky to deal with the iov_iter handling. Just mark the req as needing a reissue, and handling it from the submission path instead. This makes it directly obvious that we're not re-importing the iovec from userspace past the submit point, and it means that we can just reuse our usual -EAGAIN retry path from the read/write handling. At some point in the future, we'll gain the ability to always reliably return -EAGAIN through the stack. A previous attempt on the block side didn't pan out and got reverted, hence the need to check for this information out-of-band right now. Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 07204f2 commit 230d50d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

fs/io_uring.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ enum {
697697
REQ_F_NO_FILE_TABLE_BIT,
698698
REQ_F_LTIMEOUT_ACTIVE_BIT,
699699
REQ_F_COMPLETE_INLINE_BIT,
700+
REQ_F_REISSUE_BIT,
700701

701702
/* not a real bit, just to check we're not overflowing the space */
702703
__REQ_F_LAST_BIT,
@@ -740,6 +741,8 @@ enum {
740741
REQ_F_LTIMEOUT_ACTIVE = BIT(REQ_F_LTIMEOUT_ACTIVE_BIT),
741742
/* completion is deferred through io_comp_state */
742743
REQ_F_COMPLETE_INLINE = BIT(REQ_F_COMPLETE_INLINE_BIT),
744+
/* caller should reissue async */
745+
REQ_F_REISSUE = BIT(REQ_F_REISSUE_BIT),
743746
};
744747

745748
struct async_poll {
@@ -2503,8 +2506,10 @@ static void __io_complete_rw(struct io_kiocb *req, long res, long res2,
25032506

25042507
if (req->rw.kiocb.ki_flags & IOCB_WRITE)
25052508
kiocb_end_write(req);
2506-
if ((res == -EAGAIN || res == -EOPNOTSUPP) && io_rw_reissue(req))
2509+
if ((res == -EAGAIN || res == -EOPNOTSUPP) && io_rw_should_reissue(req)) {
2510+
req->flags |= REQ_F_REISSUE;
25072511
return;
2512+
}
25082513
if (res != req->result)
25092514
req_set_fail_links(req);
25102515
if (req->flags & REQ_F_BUFFER_SELECTED)
@@ -3283,9 +3288,7 @@ static int io_read(struct io_kiocb *req, unsigned int issue_flags)
32833288

32843289
ret = io_iter_do_read(req, iter);
32853290

3286-
if (ret == -EIOCBQUEUED) {
3287-
goto out_free;
3288-
} else if (ret == -EAGAIN) {
3291+
if (ret == -EAGAIN || (req->flags & REQ_F_REISSUE)) {
32893292
/* IOPOLL retry should happen for io-wq threads */
32903293
if (!force_nonblock && !(req->ctx->flags & IORING_SETUP_IOPOLL))
32913294
goto done;
@@ -3295,6 +3298,8 @@ static int io_read(struct io_kiocb *req, unsigned int issue_flags)
32953298
/* some cases will consume bytes even on error returns */
32963299
iov_iter_revert(iter, io_size - iov_iter_count(iter));
32973300
ret = 0;
3301+
} else if (ret == -EIOCBQUEUED) {
3302+
goto out_free;
32983303
} else if (ret <= 0 || ret == io_size || !force_nonblock ||
32993304
(req->flags & REQ_F_NOWAIT) || !(req->flags & REQ_F_ISREG)) {
33003305
/* read all, failed, already did sync or don't want to retry */
@@ -3407,6 +3412,9 @@ static int io_write(struct io_kiocb *req, unsigned int issue_flags)
34073412
else
34083413
ret2 = -EINVAL;
34093414

3415+
if (req->flags & REQ_F_REISSUE)
3416+
ret2 = -EAGAIN;
3417+
34103418
/*
34113419
* Raw bdev writes will return -EOPNOTSUPP for IOCB_NOWAIT. Just
34123420
* retry them without IOCB_NOWAIT.
@@ -6160,6 +6168,7 @@ static void io_wq_submit_work(struct io_wq_work *work)
61606168
ret = -ECANCELED;
61616169

61626170
if (!ret) {
6171+
req->flags &= ~REQ_F_REISSUE;
61636172
do {
61646173
ret = io_issue_sqe(req, 0);
61656174
/*

0 commit comments

Comments
 (0)