mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-09-04 20:19:47 +08:00
io_uring/poll: introduce io_arm_apoll()
In preparation to allowing commands to do file polling, add a helper that takes the desired poll event mask and arms it for polling. We won't be able to use io_arm_poll_handler() with IORING_OP_URING_CMD as it tries to infer the mask from the opcode data, and we can't unify it across all commands. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/7ee5633f2dc45fd15243f1a60965f7e30e1c48e8.1750065793.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
5be5726e1a
commit
1621518892
@ -669,33 +669,18 @@ static struct async_poll *io_req_alloc_apoll(struct io_kiocb *req,
|
||||
return apoll;
|
||||
}
|
||||
|
||||
int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags)
|
||||
int io_arm_apoll(struct io_kiocb *req, unsigned issue_flags, __poll_t mask)
|
||||
{
|
||||
const struct io_issue_def *def = &io_issue_defs[req->opcode];
|
||||
struct async_poll *apoll;
|
||||
struct io_poll_table ipt;
|
||||
__poll_t mask = POLLPRI | POLLERR | EPOLLET;
|
||||
int ret;
|
||||
|
||||
if (!def->pollin && !def->pollout)
|
||||
return IO_APOLL_ABORTED;
|
||||
mask |= EPOLLET;
|
||||
if (!io_file_can_poll(req))
|
||||
return IO_APOLL_ABORTED;
|
||||
if (!(req->flags & REQ_F_APOLL_MULTISHOT))
|
||||
mask |= EPOLLONESHOT;
|
||||
|
||||
if (def->pollin) {
|
||||
mask |= EPOLLIN | EPOLLRDNORM;
|
||||
|
||||
/* If reading from MSG_ERRQUEUE using recvmsg, ignore POLLIN */
|
||||
if (req->flags & REQ_F_CLEAR_POLLIN)
|
||||
mask &= ~EPOLLIN;
|
||||
} else {
|
||||
mask |= EPOLLOUT | EPOLLWRNORM;
|
||||
}
|
||||
if (def->poll_exclusive)
|
||||
mask |= EPOLLEXCLUSIVE;
|
||||
|
||||
apoll = io_req_alloc_apoll(req, issue_flags);
|
||||
if (!apoll)
|
||||
return IO_APOLL_ABORTED;
|
||||
@ -712,6 +697,31 @@ int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags)
|
||||
return IO_APOLL_OK;
|
||||
}
|
||||
|
||||
int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags)
|
||||
{
|
||||
const struct io_issue_def *def = &io_issue_defs[req->opcode];
|
||||
__poll_t mask = POLLPRI | POLLERR;
|
||||
|
||||
if (!def->pollin && !def->pollout)
|
||||
return IO_APOLL_ABORTED;
|
||||
if (!io_file_can_poll(req))
|
||||
return IO_APOLL_ABORTED;
|
||||
|
||||
if (def->pollin) {
|
||||
mask |= EPOLLIN | EPOLLRDNORM;
|
||||
|
||||
/* If reading from MSG_ERRQUEUE using recvmsg, ignore POLLIN */
|
||||
if (req->flags & REQ_F_CLEAR_POLLIN)
|
||||
mask &= ~EPOLLIN;
|
||||
} else {
|
||||
mask |= EPOLLOUT | EPOLLWRNORM;
|
||||
}
|
||||
if (def->poll_exclusive)
|
||||
mask |= EPOLLEXCLUSIVE;
|
||||
|
||||
return io_arm_apoll(req, issue_flags, mask);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns true if we found and killed one or more poll requests
|
||||
*/
|
||||
|
@ -41,6 +41,7 @@ int io_poll_remove(struct io_kiocb *req, unsigned int issue_flags);
|
||||
struct io_cancel_data;
|
||||
int io_poll_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd,
|
||||
unsigned issue_flags);
|
||||
int io_arm_apoll(struct io_kiocb *req, unsigned issue_flags, __poll_t mask);
|
||||
int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags);
|
||||
bool io_poll_remove_all(struct io_ring_ctx *ctx, struct io_uring_task *tctx,
|
||||
bool cancel_all);
|
||||
|
Loading…
Reference in New Issue
Block a user