Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Pavel Begunkov and committed by
Jens Axboe
16215188 5be5726e

+28 -17
+27 -17
io_uring/poll.c
··· 669 669 return apoll; 670 670 } 671 671 672 - int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags) 672 + int io_arm_apoll(struct io_kiocb *req, unsigned issue_flags, __poll_t mask) 673 673 { 674 - const struct io_issue_def *def = &io_issue_defs[req->opcode]; 675 674 struct async_poll *apoll; 676 675 struct io_poll_table ipt; 677 - __poll_t mask = POLLPRI | POLLERR | EPOLLET; 678 676 int ret; 679 677 680 - if (!def->pollin && !def->pollout) 681 - return IO_APOLL_ABORTED; 678 + mask |= EPOLLET; 682 679 if (!io_file_can_poll(req)) 683 680 return IO_APOLL_ABORTED; 684 681 if (!(req->flags & REQ_F_APOLL_MULTISHOT)) 685 682 mask |= EPOLLONESHOT; 686 - 687 - if (def->pollin) { 688 - mask |= EPOLLIN | EPOLLRDNORM; 689 - 690 - /* If reading from MSG_ERRQUEUE using recvmsg, ignore POLLIN */ 691 - if (req->flags & REQ_F_CLEAR_POLLIN) 692 - mask &= ~EPOLLIN; 693 - } else { 694 - mask |= EPOLLOUT | EPOLLWRNORM; 695 - } 696 - if (def->poll_exclusive) 697 - mask |= EPOLLEXCLUSIVE; 698 683 699 684 apoll = io_req_alloc_apoll(req, issue_flags); 700 685 if (!apoll) ··· 695 710 return ret > 0 ? IO_APOLL_READY : IO_APOLL_ABORTED; 696 711 trace_io_uring_poll_arm(req, mask, apoll->poll.events); 697 712 return IO_APOLL_OK; 713 + } 714 + 715 + int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags) 716 + { 717 + const struct io_issue_def *def = &io_issue_defs[req->opcode]; 718 + __poll_t mask = POLLPRI | POLLERR; 719 + 720 + if (!def->pollin && !def->pollout) 721 + return IO_APOLL_ABORTED; 722 + if (!io_file_can_poll(req)) 723 + return IO_APOLL_ABORTED; 724 + 725 + if (def->pollin) { 726 + mask |= EPOLLIN | EPOLLRDNORM; 727 + 728 + /* If reading from MSG_ERRQUEUE using recvmsg, ignore POLLIN */ 729 + if (req->flags & REQ_F_CLEAR_POLLIN) 730 + mask &= ~EPOLLIN; 731 + } else { 732 + mask |= EPOLLOUT | EPOLLWRNORM; 733 + } 734 + if (def->poll_exclusive) 735 + mask |= EPOLLEXCLUSIVE; 736 + 737 + return io_arm_apoll(req, issue_flags, mask); 698 738 } 699 739 700 740 /*
+1
io_uring/poll.h
··· 41 41 struct io_cancel_data; 42 42 int io_poll_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd, 43 43 unsigned issue_flags); 44 + int io_arm_apoll(struct io_kiocb *req, unsigned issue_flags, __poll_t mask); 44 45 int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags); 45 46 bool io_poll_remove_all(struct io_ring_ctx *ctx, struct io_uring_task *tctx, 46 47 bool cancel_all);