diff options
author | Jens Axboe <axboe@kernel.dk> | 2025-02-05 12:48:56 -0700 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2025-02-17 05:34:45 -0700 |
commit | 1533376b131f5d76f8739e89efc78c4687d96bd3 (patch) | |
tree | 2106075391dced301b531b4d34377a35ac941da5 /io_uring/cancel.c | |
parent | 5d3e51240d89678b87b5dc6987ea572048a0f0eb (diff) |
io_uring/cancel: add generic remove_all helper
Any opcode that is cancelable ends up defining its own remove all
helper, which iterates the pending list and cancels matches. Add a
generic helper for it, which can be used by them.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'io_uring/cancel.c')
-rw-r--r-- | io_uring/cancel.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/io_uring/cancel.c b/io_uring/cancel.c index 484193567839..4feacc57be63 100644 --- a/io_uring/cancel.c +++ b/io_uring/cancel.c @@ -341,3 +341,24 @@ out: fput(file); return ret; } + +bool io_cancel_remove_all(struct io_ring_ctx *ctx, struct io_uring_task *tctx, + struct hlist_head *list, bool cancel_all, + bool (*cancel)(struct io_kiocb *)) +{ + struct hlist_node *tmp; + struct io_kiocb *req; + bool found = false; + + lockdep_assert_held(&ctx->uring_lock); + + hlist_for_each_entry_safe(req, tmp, list, hash_node) { + if (!io_match_task_safe(req, tctx, cancel_all)) + continue; + hlist_del_init(&req->hash_node); + if (cancel(req)) + found = true; + } + + return found; +} |