leverage REQ_F_MULTI_CQES to suppoort IORING_OP_ADD multishot. Signed-off-by: Hao Xu <haoxu@xxxxxxxxxxxxxxxxx> --- fs/io_uring.c | 13 ++++++++++--- include/uapi/linux/io_uring.h | 5 ----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index a7bd223ce2cc..952ad0ddb2db 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -5361,20 +5361,27 @@ static int io_poll_add_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe { struct io_poll_iocb *poll = &req->poll; u32 events, flags; + bool multishot = req->flags & REQ_F_MULTI_CQES; + u32 update_bits = IORING_POLL_UPDATE_EVENTS | + IORING_POLL_UPDATE_USER_DATA; if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) return -EINVAL; if (sqe->ioprio || sqe->buf_index) return -EINVAL; flags = READ_ONCE(sqe->len); - if (flags & ~(IORING_POLL_ADD_MULTI | IORING_POLL_UPDATE_EVENTS | - IORING_POLL_UPDATE_USER_DATA)) + /* + * can't set REQ_F_MULTI_CQES with UPDATE flags, otherwise we count + * IO_POLL_ADD(IORING_POLL_UPDATE_*)'s cqe to ctx->cq_extra, which + * we shouldn't + */ + if ((flags & ~update_bits) || (multishot && (flags & update_bits))) return -EINVAL; events = READ_ONCE(sqe->poll32_events); #ifdef __BIG_ENDIAN events = swahw32(events); #endif - if (!(flags & IORING_POLL_ADD_MULTI)) + if (!multishot) events |= EPOLLONESHOT; poll->update_events = poll->update_user_data = false; if (flags & IORING_POLL_UPDATE_EVENTS) { diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 303ac8005572..a3cd943b228e 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -166,14 +166,9 @@ enum { * POLL_ADD flags. Note that since sqe->poll_events is the flag space, the * command flags for POLL_ADD are stored in sqe->len. * - * IORING_POLL_ADD_MULTI Multishot poll. Sets IORING_CQE_F_MORE if - * the poll handler will continue to report - * CQEs on behalf of the same SQE. - * * IORING_POLL_UPDATE Update existing poll request, matching * sqe->addr as the old user_data field. */ -#define IORING_POLL_ADD_MULTI (1U << 0) #define IORING_POLL_UPDATE_EVENTS (1U << 1) #define IORING_POLL_UPDATE_USER_DATA (1U << 2) -- 1.8.3.1