Skip to content

Commit

Permalink
io_uring: fix an issue when IOSQE_IO_LINK is inserted into defer list
Browse files Browse the repository at this point in the history
This patch may fix two issues:

First, when IOSQE_IO_DRAIN set, the next IOs need to be inserted into
defer list to delay execution, but link io will be actively scheduled to
run by calling io_queue_sqe.

Second, when multiple LINK_IOs are inserted together with defer_list,
the LINK_IO is no longer keep order.

   |-------------|
   |   LINK_IO   |      ----> insert to defer_list  -----------
   |-------------|                                            |
   |   LINK_IO   |      ----> insert to defer_list  ----------|
   |-------------|                                            |
   |   LINK_IO   |      ----> insert to defer_list  ----------|
   |-------------|                                            |
   |   NORMAL_IO |      ----> insert to defer_list  ----------|
   |-------------|                                            |
                                                              |
                              queue_work at same time   <-----|

Fixes: 9e645e1 ("io_uring: add support for sqe links")
Signed-off-by: Jackie Liu <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
JackieLiu1 authored and axboe committed Aug 15, 2019
1 parent 7b6620d commit a982eeb
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,15 @@ static int io_queue_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req,
{
int ret;

ret = io_req_defer(ctx, req, s->sqe);
if (ret) {
if (ret != -EIOCBQUEUED) {
io_free_req(req);
io_cqring_add_event(ctx, s->sqe->user_data, ret);
}
return 0;
}

ret = __io_submit_sqe(ctx, req, s, true);
if (ret == -EAGAIN && !(req->flags & REQ_F_NOWAIT)) {
struct io_uring_sqe *sqe_copy;
Expand Down Expand Up @@ -2095,13 +2104,6 @@ static void io_submit_sqe(struct io_ring_ctx *ctx, struct sqe_submit *s,
return;
}

ret = io_req_defer(ctx, req, s->sqe);
if (ret) {
if (ret != -EIOCBQUEUED)
goto err_req;
return;
}

/*
* If we already have a head request, queue this one for async
* submittal once the head completes. If we don't have a head but
Expand Down

0 comments on commit a982eeb

Please sign in to comment.