Skip to content

Commit 581f981

Browse files
Bijan Mottahedehaxboe
authored andcommitted
io_uring: process requests completed with -EAGAIN on poll list
A request that completes with an -EAGAIN result after it has been added to the poll list, will not be removed from that list in io_do_iopoll() because the f_op->iopoll() will not succeed for that request. Maintain a retryable local list similar to the done list, and explicity reissue requests with an -EAGAIN result. Signed-off-by: Bijan Mottahedeh <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent c336e99 commit 581f981

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

fs/io_uring.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,11 +1744,24 @@ static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events,
17441744
io_free_req_many(ctx, &rb);
17451745
}
17461746

1747+
static void io_iopoll_queue(struct list_head *again)
1748+
{
1749+
struct io_kiocb *req;
1750+
1751+
do {
1752+
req = list_first_entry(again, struct io_kiocb, list);
1753+
list_del(&req->list);
1754+
refcount_inc(&req->refs);
1755+
io_queue_async_work(req);
1756+
} while (!list_empty(again));
1757+
}
1758+
17471759
static int io_do_iopoll(struct io_ring_ctx *ctx, unsigned int *nr_events,
17481760
long min)
17491761
{
17501762
struct io_kiocb *req, *tmp;
17511763
LIST_HEAD(done);
1764+
LIST_HEAD(again);
17521765
bool spin;
17531766
int ret;
17541767

@@ -1763,9 +1776,9 @@ static int io_do_iopoll(struct io_ring_ctx *ctx, unsigned int *nr_events,
17631776
struct kiocb *kiocb = &req->rw.kiocb;
17641777

17651778
/*
1766-
* Move completed entries to our local list. If we find a
1767-
* request that requires polling, break out and complete
1768-
* the done list first, if we have entries there.
1779+
* Move completed and retryable entries to our local lists.
1780+
* If we find a request that requires polling, break out
1781+
* and complete those lists first, if we have entries there.
17691782
*/
17701783
if (req->flags & REQ_F_IOPOLL_COMPLETED) {
17711784
list_move_tail(&req->list, &done);
@@ -1774,6 +1787,13 @@ static int io_do_iopoll(struct io_ring_ctx *ctx, unsigned int *nr_events,
17741787
if (!list_empty(&done))
17751788
break;
17761789

1790+
if (req->result == -EAGAIN) {
1791+
list_move_tail(&req->list, &again);
1792+
continue;
1793+
}
1794+
if (!list_empty(&again))
1795+
break;
1796+
17771797
ret = kiocb->ki_filp->f_op->iopoll(kiocb, spin);
17781798
if (ret < 0)
17791799
break;
@@ -1786,6 +1806,9 @@ static int io_do_iopoll(struct io_ring_ctx *ctx, unsigned int *nr_events,
17861806
if (!list_empty(&done))
17871807
io_iopoll_complete(ctx, nr_events, &done);
17881808

1809+
if (!list_empty(&again))
1810+
io_iopoll_queue(&again);
1811+
17891812
return ret;
17901813
}
17911814

0 commit comments

Comments
 (0)