| From 085bb14a950baa4a2dc77e675ab4122f0cd085e8 Mon Sep 17 00:00:00 2001 |
| From: Sasha Levin <sashal@kernel.org> |
| Date: Fri, 23 Jun 2023 09:00:24 -0600 |
| Subject: io_uring/cancel: abstract out request match helper |
| |
| From: Jens Axboe <axboe@kernel.dk> |
| |
| [ Upstream commit aa5cd116f3c25c05e4724d7b5e24dc9ed9020a12 ] |
| |
| 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: 22dbb0987bd1 ("io_uring/cancel: de-unionize file and user_data in struct io_cancel_data") |
| Signed-off-by: Sasha Levin <sashal@kernel.org> |
| --- |
| io_uring/cancel.c | 17 +++++++++++++---- |
| io_uring/cancel.h | 1 + |
| 2 files changed, 14 insertions(+), 4 deletions(-) |
| |
| diff --git a/io_uring/cancel.c b/io_uring/cancel.c |
| index b4f5dfacc0c31..88586911b516b 100644 |
| --- a/io_uring/cancel.c |
| +++ b/io_uring/cancel.c |
| @@ -27,11 +27,11 @@ struct io_cancel { |
| #define CANCEL_FLAGS (IORING_ASYNC_CANCEL_ALL | IORING_ASYNC_CANCEL_FD | \ |
| IORING_ASYNC_CANCEL_ANY | IORING_ASYNC_CANCEL_FD_FIXED) |
| |
| -static bool io_cancel_cb(struct io_wq_work *work, void *data) |
| +/* |
| + * Returns true if the request matches the criteria outlined by 'cd'. |
| + */ |
| +bool io_cancel_req_match(struct io_kiocb *req, struct io_cancel_data *cd) |
| { |
| - struct io_kiocb *req = container_of(work, struct io_kiocb, work); |
| - struct io_cancel_data *cd = data; |
| - |
| if (req->ctx != cd->ctx) |
| return false; |
| if (cd->flags & IORING_ASYNC_CANCEL_ANY) { |
| @@ -48,9 +48,18 @@ static bool io_cancel_cb(struct io_wq_work *work, void *data) |
| return false; |
| req->work.cancel_seq = cd->seq; |
| } |
| + |
| return true; |
| } |
| |
| +static bool io_cancel_cb(struct io_wq_work *work, void *data) |
| +{ |
| + struct io_kiocb *req = container_of(work, struct io_kiocb, work); |
| + struct io_cancel_data *cd = data; |
| + |
| + return io_cancel_req_match(req, cd); |
| +} |
| + |
| static int io_async_cancel_one(struct io_uring_task *tctx, |
| struct io_cancel_data *cd) |
| { |
| diff --git a/io_uring/cancel.h b/io_uring/cancel.h |
| index 6a59ee484d0cc..496ce4dac78ed 100644 |
| --- a/io_uring/cancel.h |
| +++ b/io_uring/cancel.h |
| @@ -21,3 +21,4 @@ int io_try_cancel(struct io_uring_task *tctx, struct io_cancel_data *cd, |
| void init_hash_table(struct io_hash_table *table, unsigned size); |
| |
| 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); |
| -- |
| 2.51.0 |
| |