Skip to content

Commit fbd1584

Browse files
isilenceaxboe
authored andcommitted
io_uring: restructure io_timeout_cancel()
Add io_timeout_extract() helper, which searches and disarms timeouts, but doesn't complete them. No functional changes. Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent bee749b commit fbd1584

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

fs/io_uring.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5633,24 +5633,10 @@ static enum hrtimer_restart io_timeout_fn(struct hrtimer *timer)
56335633
return HRTIMER_NORESTART;
56345634
}
56355635

5636-
static int __io_timeout_cancel(struct io_kiocb *req)
5637-
{
5638-
struct io_timeout_data *io = req->async_data;
5639-
int ret;
5640-
5641-
ret = hrtimer_try_to_cancel(&io->timer);
5642-
if (ret == -1)
5643-
return -EALREADY;
5644-
list_del_init(&req->timeout.list);
5645-
5646-
req_set_fail_links(req);
5647-
io_cqring_fill_event(req, -ECANCELED);
5648-
io_put_req_deferred(req, 1);
5649-
return 0;
5650-
}
5651-
5652-
static int io_timeout_cancel(struct io_ring_ctx *ctx, __u64 user_data)
5636+
static struct io_kiocb *io_timeout_extract(struct io_ring_ctx *ctx,
5637+
__u64 user_data)
56535638
{
5639+
struct io_timeout_data *io;
56545640
struct io_kiocb *req;
56555641
int ret = -ENOENT;
56565642

@@ -5662,9 +5648,27 @@ static int io_timeout_cancel(struct io_ring_ctx *ctx, __u64 user_data)
56625648
}
56635649

56645650
if (ret == -ENOENT)
5665-
return ret;
5651+
return ERR_PTR(ret);
5652+
5653+
io = req->async_data;
5654+
ret = hrtimer_try_to_cancel(&io->timer);
5655+
if (ret == -1)
5656+
return ERR_PTR(-EALREADY);
5657+
list_del_init(&req->timeout.list);
5658+
return req;
5659+
}
56665660

5667-
return __io_timeout_cancel(req);
5661+
static int io_timeout_cancel(struct io_ring_ctx *ctx, __u64 user_data)
5662+
{
5663+
struct io_kiocb *req = io_timeout_extract(ctx, user_data);
5664+
5665+
if (IS_ERR(req))
5666+
return PTR_ERR(req);
5667+
5668+
req_set_fail_links(req);
5669+
io_cqring_fill_event(req, -ECANCELED);
5670+
io_put_req_deferred(req, 1);
5671+
return 0;
56685672
}
56695673

56705674
static int io_timeout_remove_prep(struct io_kiocb *req,

0 commit comments

Comments
 (0)