Skip to content

Commit b2d9c3d

Browse files
isilenceaxboe
authored andcommitted
io_uring: refactor io_arm_poll_handler()
gcc 11 goes a weird path and duplicates most of io_arm_poll_handler() for READ and WRITE cases. Help it and move all pollin vs pollout specific bits under a single if-else, so there is no temptation for this kind of unfolding. before vs after: text data bss dec hex filename 85362 12650 8 98020 17ee4 ./fs/io_uring.o 85186 12650 8 97844 17e34 ./fs/io_uring.o Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/1deea0037293a922a0358e2958384b2e42437885.1624739600.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 59b735a commit b2d9c3d

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

fs/io_uring.c

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5172,19 +5172,29 @@ static int io_arm_poll_handler(struct io_kiocb *req)
51725172
struct io_ring_ctx *ctx = req->ctx;
51735173
struct async_poll *apoll;
51745174
struct io_poll_table ipt;
5175-
__poll_t mask, ret;
5175+
__poll_t ret, mask = EPOLLONESHOT | POLLERR | POLLPRI;
51765176
int rw;
51775177

51785178
if (!req->file || !file_can_poll(req->file))
51795179
return IO_APOLL_ABORTED;
51805180
if (req->flags & REQ_F_POLLED)
51815181
return IO_APOLL_ABORTED;
5182-
if (def->pollin)
5182+
if (!def->pollin && !def->pollout)
5183+
return IO_APOLL_ABORTED;
5184+
5185+
if (def->pollin) {
51835186
rw = READ;
5184-
else if (def->pollout)
5187+
mask |= POLLIN | POLLRDNORM;
5188+
5189+
/* If reading from MSG_ERRQUEUE using recvmsg, ignore POLLIN */
5190+
if ((req->opcode == IORING_OP_RECVMSG) &&
5191+
(req->sr_msg.msg_flags & MSG_ERRQUEUE))
5192+
mask &= ~POLLIN;
5193+
} else {
51855194
rw = WRITE;
5186-
else
5187-
return IO_APOLL_ABORTED;
5195+
mask |= POLLOUT | POLLWRNORM;
5196+
}
5197+
51885198
/* if we can't nonblock try, then no point in arming a poll handler */
51895199
if (!io_file_supports_async(req, rw))
51905200
return IO_APOLL_ABORTED;
@@ -5193,23 +5203,8 @@ static int io_arm_poll_handler(struct io_kiocb *req)
51935203
if (unlikely(!apoll))
51945204
return IO_APOLL_ABORTED;
51955205
apoll->double_poll = NULL;
5196-
5197-
req->flags |= REQ_F_POLLED;
51985206
req->apoll = apoll;
5199-
5200-
mask = EPOLLONESHOT;
5201-
if (def->pollin)
5202-
mask |= POLLIN | POLLRDNORM;
5203-
if (def->pollout)
5204-
mask |= POLLOUT | POLLWRNORM;
5205-
5206-
/* If reading from MSG_ERRQUEUE using recvmsg, ignore POLLIN */
5207-
if ((req->opcode == IORING_OP_RECVMSG) &&
5208-
(req->sr_msg.msg_flags & MSG_ERRQUEUE))
5209-
mask &= ~POLLIN;
5210-
5211-
mask |= POLLERR | POLLPRI;
5212-
5207+
req->flags |= REQ_F_POLLED;
52135208
ipt.pt._qproc = io_async_queue_proc;
52145209

52155210
ret = __io_arm_poll_handler(req, &apoll->poll, &ipt, mask,

0 commit comments

Comments
 (0)