Skip to content

Commit efc0728

Browse files
isilenceXiaoguang Wang
authored andcommitted
io_uring: don't arm a timeout through work.func
to #28736503 commit d4c81f3 upstream Remove io_link_work_cb() -- the last custom work.func. Not the prettiest thing, but works. Instead of queueing a linked timeout in io_link_work_cb() mark a request with REQ_F_QUEUE_TIMEOUT and do enqueueing based on the flag in io_wq_submit_work(). Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com> Acked-by: Joseph Qi <joseph.qi@linux.alibaba.com>
1 parent 7e2014f commit efc0728

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

fs/io_uring.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ enum {
531531
REQ_F_POLLED_BIT,
532532
REQ_F_BUFFER_SELECTED_BIT,
533533
REQ_F_NO_FILE_TABLE_BIT,
534+
REQ_F_QUEUE_TIMEOUT_BIT,
534535

535536
/* not a real bit, just to check we're not overflowing the space */
536537
__REQ_F_LAST_BIT,
@@ -586,6 +587,8 @@ enum {
586587
REQ_F_BUFFER_SELECTED = BIT(REQ_F_BUFFER_SELECTED_BIT),
587588
/* doesn't need file table for this request */
588589
REQ_F_NO_FILE_TABLE = BIT(REQ_F_NO_FILE_TABLE_BIT),
590+
/* needs to queue linked timeout */
591+
REQ_F_QUEUE_TIMEOUT = BIT(REQ_F_QUEUE_TIMEOUT_BIT),
589592
};
590593

591594
struct async_poll {
@@ -1571,16 +1574,6 @@ static void io_free_req(struct io_kiocb *req)
15711574
io_queue_async_work(nxt);
15721575
}
15731576

1574-
static void io_link_work_cb(struct io_wq_work **workptr)
1575-
{
1576-
struct io_kiocb *req = container_of(*workptr, struct io_kiocb, work);
1577-
struct io_kiocb *link;
1578-
1579-
link = list_first_entry(&req->link_list, struct io_kiocb, link_list);
1580-
io_queue_linked_timeout(link);
1581-
io_wq_submit_work(workptr);
1582-
}
1583-
15841577
static void io_wq_assign_next(struct io_wq_work **workptr, struct io_kiocb *nxt)
15851578
{
15861579
struct io_kiocb *link;
@@ -1592,7 +1585,7 @@ static void io_wq_assign_next(struct io_wq_work **workptr, struct io_kiocb *nxt)
15921585
*workptr = &nxt->work;
15931586
link = io_prep_linked_timeout(nxt);
15941587
if (link)
1595-
nxt->work.func = io_link_work_cb;
1588+
nxt->flags |= REQ_F_QUEUE_TIMEOUT;
15961589
}
15971590

15981591
/*
@@ -5210,12 +5203,26 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
52105203
return 0;
52115204
}
52125205

5206+
static void io_arm_async_linked_timeout(struct io_kiocb *req)
5207+
{
5208+
struct io_kiocb *link;
5209+
5210+
/* link head's timeout is queued in io_queue_async_work() */
5211+
if (!(req->flags & REQ_F_QUEUE_TIMEOUT))
5212+
return;
5213+
5214+
link = list_first_entry(&req->link_list, struct io_kiocb, link_list);
5215+
io_queue_linked_timeout(link);
5216+
}
5217+
52135218
static void io_wq_submit_work(struct io_wq_work **workptr)
52145219
{
52155220
struct io_wq_work *work = *workptr;
52165221
struct io_kiocb *req = container_of(work, struct io_kiocb, work);
52175222
int ret = 0;
52185223

5224+
io_arm_async_linked_timeout(req);
5225+
52195226
/* if NO_CANCEL is set, we must still run the work */
52205227
if ((work->flags & (IO_WQ_WORK_CANCEL|IO_WQ_WORK_NO_CANCEL)) ==
52215228
IO_WQ_WORK_CANCEL) {

0 commit comments

Comments
 (0)