Skip to content

Commit 8fa374f

Browse files
committed
io_uring/cancel: add generic cancel helper
Any opcode that is cancelable ends up defining its own cancel helper for finding and canceling a specific request. Add a generic helper that can be used for this purpose. Signed-off-by: Jens Axboe <[email protected]>
1 parent 7d9944f commit 8fa374f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

io_uring/cancel.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,24 @@ bool io_cancel_remove_all(struct io_ring_ctx *ctx, struct io_uring_task *tctx,
362362

363363
return found;
364364
}
365+
366+
int io_cancel_remove(struct io_ring_ctx *ctx, struct io_cancel_data *cd,
367+
unsigned int issue_flags, struct hlist_head *list,
368+
bool (*cancel)(struct io_kiocb *))
369+
{
370+
struct hlist_node *tmp;
371+
struct io_kiocb *req;
372+
int nr = 0;
373+
374+
io_ring_submit_lock(ctx, issue_flags);
375+
hlist_for_each_entry_safe(req, tmp, list, hash_node) {
376+
if (!io_cancel_req_match(req, cd))
377+
continue;
378+
if (cancel(req))
379+
nr++;
380+
if (!(cd->flags & IORING_ASYNC_CANCEL_ALL))
381+
break;
382+
}
383+
io_ring_submit_unlock(ctx, issue_flags);
384+
return nr ?: -ENOENT;
385+
}

io_uring/cancel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ bool io_cancel_remove_all(struct io_ring_ctx *ctx, struct io_uring_task *tctx,
2828
struct hlist_head *list, bool cancel_all,
2929
bool (*cancel)(struct io_kiocb *));
3030

31+
int io_cancel_remove(struct io_ring_ctx *ctx, struct io_cancel_data *cd,
32+
unsigned int issue_flags, struct hlist_head *list,
33+
bool (*cancel)(struct io_kiocb *));
34+
3135
static inline bool io_cancel_match_sequence(struct io_kiocb *req, int sequence)
3236
{
3337
if (req->cancel_seq_set && sequence == req->work.cancel_seq)

0 commit comments

Comments
 (0)