diff options
| author | Jens Axboe <axboe@kernel.dk> | 2025-11-03 11:21:39 -0700 |
|---|---|---|
| committer | Jens Axboe <axboe@kernel.dk> | 2025-11-04 09:32:08 -0700 |
| commit | 0d677936d67774f1b4ebfb3b26f207320f0fe3c6 (patch) | |
| tree | e320e557cb5c79183ef29b190482246b97bc87da /io_uring/cancel.c | |
| parent | bc82b02218204d89f26fd1fde5aed265f40453d3 (diff) | |
io_uring/cancel: move request/task cancelation logic into cancel.c
Move io_match_task_safe() and helpers into cancel.c, where it belongs.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'io_uring/cancel.c')
| -rw-r--r-- | io_uring/cancel.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/io_uring/cancel.c b/io_uring/cancel.c index 64b51e82baa2..2754ea80e288 100644 --- a/io_uring/cancel.c +++ b/io_uring/cancel.c @@ -384,3 +384,41 @@ int io_cancel_remove(struct io_ring_ctx *ctx, struct io_cancel_data *cd, io_ring_submit_unlock(ctx, issue_flags); return nr ?: -ENOENT; } + +static bool io_match_linked(struct io_kiocb *head) +{ + struct io_kiocb *req; + + io_for_each_link(req, head) { + if (req->flags & REQ_F_INFLIGHT) + return true; + } + return false; +} + +/* + * As io_match_task() but protected against racing with linked timeouts. + * User must not hold timeout_lock. + */ +bool io_match_task_safe(struct io_kiocb *head, struct io_uring_task *tctx, + bool cancel_all) +{ + bool matched; + + if (tctx && head->tctx != tctx) + return false; + if (cancel_all) + return true; + + if (head->flags & REQ_F_LINK_TIMEOUT) { + struct io_ring_ctx *ctx = head->ctx; + + /* protect against races with linked timeouts */ + raw_spin_lock_irq(&ctx->timeout_lock); + matched = io_match_linked(head); + raw_spin_unlock_irq(&ctx->timeout_lock); + } else { + matched = io_match_linked(head); + } + return matched; +} |