mirror of
https://kernel.googlesource.com/pub/scm/linux/kernel/git/stable/linux-stable.git
synced 2025-09-14 11:19:08 +10:00
io_uring/cancel: support opcode based lookup and cancelation
Add IORING_ASYNC_CANCEL_OP flag for cancelation, which allows the application to target cancelation based on the opcode of the original request. Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
8165b56604
commit
d7b8b079a8
@ -300,12 +300,14 @@ enum io_uring_op {
|
|||||||
* IORING_ASYNC_CANCEL_ANY Match any request
|
* IORING_ASYNC_CANCEL_ANY Match any request
|
||||||
* IORING_ASYNC_CANCEL_FD_FIXED 'fd' passed in is a fixed descriptor
|
* IORING_ASYNC_CANCEL_FD_FIXED 'fd' passed in is a fixed descriptor
|
||||||
* IORING_ASYNC_CANCEL_USERDATA Match on user_data, default for no other key
|
* IORING_ASYNC_CANCEL_USERDATA Match on user_data, default for no other key
|
||||||
|
* IORING_ASYNC_CANCEL_OP Match request based on opcode
|
||||||
*/
|
*/
|
||||||
#define IORING_ASYNC_CANCEL_ALL (1U << 0)
|
#define IORING_ASYNC_CANCEL_ALL (1U << 0)
|
||||||
#define IORING_ASYNC_CANCEL_FD (1U << 1)
|
#define IORING_ASYNC_CANCEL_FD (1U << 1)
|
||||||
#define IORING_ASYNC_CANCEL_ANY (1U << 2)
|
#define IORING_ASYNC_CANCEL_ANY (1U << 2)
|
||||||
#define IORING_ASYNC_CANCEL_FD_FIXED (1U << 3)
|
#define IORING_ASYNC_CANCEL_FD_FIXED (1U << 3)
|
||||||
#define IORING_ASYNC_CANCEL_USERDATA (1U << 4)
|
#define IORING_ASYNC_CANCEL_USERDATA (1U << 4)
|
||||||
|
#define IORING_ASYNC_CANCEL_OP (1U << 5)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* send/sendmsg and recv/recvmsg flags (sqe->ioprio)
|
* send/sendmsg and recv/recvmsg flags (sqe->ioprio)
|
||||||
|
@ -22,11 +22,12 @@ struct io_cancel {
|
|||||||
u64 addr;
|
u64 addr;
|
||||||
u32 flags;
|
u32 flags;
|
||||||
s32 fd;
|
s32 fd;
|
||||||
|
u8 opcode;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CANCEL_FLAGS (IORING_ASYNC_CANCEL_ALL | IORING_ASYNC_CANCEL_FD | \
|
#define CANCEL_FLAGS (IORING_ASYNC_CANCEL_ALL | IORING_ASYNC_CANCEL_FD | \
|
||||||
IORING_ASYNC_CANCEL_ANY | IORING_ASYNC_CANCEL_FD_FIXED | \
|
IORING_ASYNC_CANCEL_ANY | IORING_ASYNC_CANCEL_FD_FIXED | \
|
||||||
IORING_ASYNC_CANCEL_USERDATA)
|
IORING_ASYNC_CANCEL_USERDATA | IORING_ASYNC_CANCEL_OP)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns true if the request matches the criteria outlined by 'cd'.
|
* Returns true if the request matches the criteria outlined by 'cd'.
|
||||||
@ -38,7 +39,7 @@ bool io_cancel_req_match(struct io_kiocb *req, struct io_cancel_data *cd)
|
|||||||
if (req->ctx != cd->ctx)
|
if (req->ctx != cd->ctx)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(cd->flags & (IORING_ASYNC_CANCEL_FD)))
|
if (!(cd->flags & (IORING_ASYNC_CANCEL_FD | IORING_ASYNC_CANCEL_OP)))
|
||||||
match_user_data = true;
|
match_user_data = true;
|
||||||
|
|
||||||
if (cd->flags & IORING_ASYNC_CANCEL_ANY)
|
if (cd->flags & IORING_ASYNC_CANCEL_ANY)
|
||||||
@ -47,6 +48,10 @@ bool io_cancel_req_match(struct io_kiocb *req, struct io_cancel_data *cd)
|
|||||||
if (req->file != cd->file)
|
if (req->file != cd->file)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (cd->flags & IORING_ASYNC_CANCEL_OP) {
|
||||||
|
if (req->opcode != cd->opcode)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (match_user_data && req->cqe.user_data != cd->data)
|
if (match_user_data && req->cqe.user_data != cd->data)
|
||||||
return false;
|
return false;
|
||||||
if (cd->flags & IORING_ASYNC_CANCEL_ALL) {
|
if (cd->flags & IORING_ASYNC_CANCEL_ALL) {
|
||||||
@ -127,7 +132,7 @@ int io_async_cancel_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
|||||||
|
|
||||||
if (unlikely(req->flags & REQ_F_BUFFER_SELECT))
|
if (unlikely(req->flags & REQ_F_BUFFER_SELECT))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (sqe->off || sqe->len || sqe->splice_fd_in)
|
if (sqe->off || sqe->splice_fd_in)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
cancel->addr = READ_ONCE(sqe->addr);
|
cancel->addr = READ_ONCE(sqe->addr);
|
||||||
@ -139,6 +144,11 @@ int io_async_cancel_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
cancel->fd = READ_ONCE(sqe->fd);
|
cancel->fd = READ_ONCE(sqe->fd);
|
||||||
}
|
}
|
||||||
|
if (cancel->flags & IORING_ASYNC_CANCEL_OP) {
|
||||||
|
if (cancel->flags & IORING_ASYNC_CANCEL_ANY)
|
||||||
|
return -EINVAL;
|
||||||
|
cancel->opcode = READ_ONCE(sqe->len);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -185,6 +195,7 @@ int io_async_cancel(struct io_kiocb *req, unsigned int issue_flags)
|
|||||||
.ctx = req->ctx,
|
.ctx = req->ctx,
|
||||||
.data = cancel->addr,
|
.data = cancel->addr,
|
||||||
.flags = cancel->flags,
|
.flags = cancel->flags,
|
||||||
|
.opcode = cancel->opcode,
|
||||||
.seq = atomic_inc_return(&req->ctx->cancel_seq),
|
.seq = atomic_inc_return(&req->ctx->cancel_seq),
|
||||||
};
|
};
|
||||||
struct io_uring_task *tctx = req->task->io_uring;
|
struct io_uring_task *tctx = req->task->io_uring;
|
||||||
|
@ -8,11 +8,11 @@ struct io_cancel_data {
|
|||||||
u64 data;
|
u64 data;
|
||||||
struct file *file;
|
struct file *file;
|
||||||
};
|
};
|
||||||
|
u8 opcode;
|
||||||
u32 flags;
|
u32 flags;
|
||||||
int seq;
|
int seq;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int io_async_cancel_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
|
int io_async_cancel_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
|
||||||
int io_async_cancel(struct io_kiocb *req, unsigned int issue_flags);
|
int io_async_cancel(struct io_kiocb *req, unsigned int issue_flags);
|
||||||
|
|
||||||
|
@ -851,7 +851,8 @@ static int __io_poll_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd,
|
|||||||
struct io_hash_bucket *bucket;
|
struct io_hash_bucket *bucket;
|
||||||
struct io_kiocb *req;
|
struct io_kiocb *req;
|
||||||
|
|
||||||
if (cd->flags & (IORING_ASYNC_CANCEL_FD|IORING_ASYNC_CANCEL_ANY))
|
if (cd->flags & (IORING_ASYNC_CANCEL_FD | IORING_ASYNC_CANCEL_OP |
|
||||||
|
IORING_ASYNC_CANCEL_ANY))
|
||||||
req = io_poll_file_find(ctx, cd, table, &bucket);
|
req = io_poll_file_find(ctx, cd, table, &bucket);
|
||||||
else
|
else
|
||||||
req = io_poll_find(ctx, false, cd, table, &bucket);
|
req = io_poll_find(ctx, false, cd, table, &bucket);
|
||||||
|
Loading…
Reference in New Issue
Block a user