]> Gentwo Git Trees - linux/.git/commitdiff
io_uring/cancel: move request/task cancelation logic into cancel.c
authorJens Axboe <axboe@kernel.dk>
Mon, 3 Nov 2025 18:21:39 +0000 (11:21 -0700)
committerJens Axboe <axboe@kernel.dk>
Tue, 4 Nov 2025 16:32:08 +0000 (09:32 -0700)
Move io_match_task_safe() and helpers into cancel.c, where it belongs.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/cancel.c
io_uring/cancel.h
io_uring/io_uring.c
io_uring/io_uring.h

index 64b51e82baa245512f11d5cdc51b9e6a1a51bcca..2754ea80e2882c60f33f20b0d54a2ea96170d2f1 100644 (file)
@@ -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;
+}
index 43e9bb74e9d19aae64ea1d9270121bf3c5c97637..6d5208e9d7a6a11895fa0da93e76725b5cab63e5 100644 (file)
@@ -23,6 +23,8 @@ int io_try_cancel(struct io_uring_task *tctx, struct io_cancel_data *cd,
 
 int io_sync_cancel(struct io_ring_ctx *ctx, void __user *arg);
 bool io_cancel_req_match(struct io_kiocb *req, struct io_cancel_data *cd);
+bool io_match_task_safe(struct io_kiocb *head, struct io_uring_task *tctx,
+                       bool cancel_all);
 
 bool io_cancel_remove_all(struct io_ring_ctx *ctx, struct io_uring_task *tctx,
                          struct hlist_head *list, bool cancel_all,
index 01631b6ff4424c91e21b1c27e265e0453b3710a0..75bd049a1efd428c2d43b6df744ab5e65d01d102 100644 (file)
@@ -207,44 +207,6 @@ static inline unsigned int __io_cqring_events_user(struct io_ring_ctx *ctx)
        return READ_ONCE(ctx->rings->cq.tail) - READ_ONCE(ctx->rings->cq.head);
 }
 
-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;
-}
-
 static inline void req_fail_link_node(struct io_kiocb *req, int res)
 {
        req_set_fail(req);
index f97356ce29d0db61def76b56c9a3cc7b16a4ffea..2f4d43e69648b6414446185372434badd887e9b1 100644 (file)
@@ -174,9 +174,6 @@ void io_queue_next(struct io_kiocb *req);
 void io_task_refs_refill(struct io_uring_task *tctx);
 bool __io_alloc_req_refill(struct io_ring_ctx *ctx);
 
-bool io_match_task_safe(struct io_kiocb *head, struct io_uring_task *tctx,
-                       bool cancel_all);
-
 void io_activate_pollwq(struct io_ring_ctx *ctx);
 
 static inline void io_lockdep_assert_cq_locked(struct io_ring_ctx *ctx)