Skip to content

Commit

Permalink
io_uring: hide iter revert in resubmit_prep
Browse files Browse the repository at this point in the history
Move iov_iter_revert() resetting iterator in case of -EIOCBQUEUED into
io_resubmit_prep(), so we don't do heavy revert in hot path, also saves
a couple of checks.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Pavel Begunkov authored and Jens Axboe committed Apr 11, 2021
1 parent 8c13082 commit ab45443
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -2445,8 +2445,13 @@ static void kiocb_end_write(struct io_kiocb *req)
#ifdef CONFIG_BLOCK
static bool io_resubmit_prep(struct io_kiocb *req)
{
/* either already prepared or successfully done */
return req->async_data || !io_req_prep_async(req);
struct io_async_rw *rw = req->async_data;

if (!rw)
return !io_req_prep_async(req);
/* may have left rw->iter inconsistent on -EIOCBQUEUED */
iov_iter_revert(&rw->iter, req->result - iov_iter_count(&rw->iter));
return true;
}

static bool io_rw_should_reissue(struct io_kiocb *req)
Expand Down Expand Up @@ -2505,14 +2510,8 @@ static void io_complete_rw_iopoll(struct kiocb *kiocb, long res, long res2)
struct io_kiocb *req = container_of(kiocb, struct io_kiocb, rw.kiocb);

#ifdef CONFIG_BLOCK
/* Rewind iter, if we have one. iopoll path resubmits as usual */
if (res == -EAGAIN && io_rw_should_reissue(req)) {
struct io_async_rw *rw = req->async_data;

if (rw)
iov_iter_revert(&rw->iter,
req->result - iov_iter_count(&rw->iter));
else if (!io_resubmit_prep(req))
if (!io_resubmit_prep(req))
req->flags |= REQ_F_DONT_REISSUE;
}
#endif
Expand Down

0 comments on commit ab45443

Please sign in to comment.