Skip to content
/ linux Public

Commit 2417f44

Browse files
axboeSasha Levin
authored andcommitted
io_uring/cancel: abstract out request match helper
[ Upstream commit aa5cd11 ] We have different match code in a variety of spots. Start the cleanup of this by abstracting out a helper that can be used to check if a given request matches the cancelation criteria outlined in io_cancel_data. Signed-off-by: Jens Axboe <axboe@kernel.dk> Stable-dep-of: 22dbb09 ("io_uring/cancel: de-unionize file and user_data in struct io_cancel_data") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 4f11665 commit 2417f44

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

io_uring/cancel.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ struct io_cancel {
2727
#define CANCEL_FLAGS (IORING_ASYNC_CANCEL_ALL | IORING_ASYNC_CANCEL_FD | \
2828
IORING_ASYNC_CANCEL_ANY | IORING_ASYNC_CANCEL_FD_FIXED)
2929

30-
static bool io_cancel_cb(struct io_wq_work *work, void *data)
30+
/*
31+
* Returns true if the request matches the criteria outlined by 'cd'.
32+
*/
33+
bool io_cancel_req_match(struct io_kiocb *req, struct io_cancel_data *cd)
3134
{
32-
struct io_kiocb *req = container_of(work, struct io_kiocb, work);
33-
struct io_cancel_data *cd = data;
34-
3535
if (req->ctx != cd->ctx)
3636
return false;
3737
if (cd->flags & IORING_ASYNC_CANCEL_ANY) {
@@ -48,9 +48,18 @@ static bool io_cancel_cb(struct io_wq_work *work, void *data)
4848
return false;
4949
req->work.cancel_seq = cd->seq;
5050
}
51+
5152
return true;
5253
}
5354

55+
static bool io_cancel_cb(struct io_wq_work *work, void *data)
56+
{
57+
struct io_kiocb *req = container_of(work, struct io_kiocb, work);
58+
struct io_cancel_data *cd = data;
59+
60+
return io_cancel_req_match(req, cd);
61+
}
62+
5463
static int io_async_cancel_one(struct io_uring_task *tctx,
5564
struct io_cancel_data *cd)
5665
{

io_uring/cancel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ int io_try_cancel(struct io_uring_task *tctx, struct io_cancel_data *cd,
2121
void init_hash_table(struct io_hash_table *table, unsigned size);
2222

2323
int io_sync_cancel(struct io_ring_ctx *ctx, void __user *arg);
24+
bool io_cancel_req_match(struct io_kiocb *req, struct io_cancel_data *cd);

0 commit comments

Comments
 (0)