summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiaoguang Wang <xiaoguang.wang@linux.alibaba.com>2020-04-13 15:19:40 +0800
committerJens Axboe <axboe@kernel.dk>2020-04-13 10:50:21 -0600
commitf0c5c54945ae92a00cdbb43bdf3abaeab6bd3a23 (patch)
tree0073cc07bee34fb35068f7b69d60588dd52ababf
parentf2e1f3590f7bed3040bd1691676b50839f7d5c39 (diff)
downloadliburing-0.6.tar.gz
liburing-0.6.tar.bz2
sq_ring_needs_enter: check whether there are sqes when SQPOLL is not enabledliburing-0.6
Indeed I'm not sure this patch is necessary, robust applications should not call io_uring_submit when there are not sqes to submmit. But still try to add this check, I have seen some applications which call io_uring_submit(), but there are not sqes to submit. Signed-off-by: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--src/queue.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/queue.c b/src/queue.c
index e563775..75d707d 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -19,9 +19,10 @@
* or if IORING_SQ_NEED_WAKEUP is set, so submit thread must be explicitly
* awakened. For the latter case, we set the thread wakeup flag.
*/
-static inline bool sq_ring_needs_enter(struct io_uring *ring, unsigned *flags)
+static inline bool sq_ring_needs_enter(struct io_uring *ring,
+ unsigned submitted, unsigned *flags)
{
- if (!(ring->flags & IORING_SETUP_SQPOLL))
+ if (!(ring->flags & IORING_SETUP_SQPOLL) && submitted)
return true;
if (IO_URING_READ_ONCE(*ring->sq.kflags) & IORING_SQ_NEED_WAKEUP) {
*flags |= IORING_ENTER_SQ_WAKEUP;
@@ -51,7 +52,7 @@ int __io_uring_get_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_ptr,
if (wait_nr)
flags = IORING_ENTER_GETEVENTS;
if (submit)
- sq_ring_needs_enter(ring, &flags);
+ sq_ring_needs_enter(ring, submit, &flags);
if (wait_nr || submit)
ret = __sys_io_uring_enter(ring->ring_fd, submit,
wait_nr, flags, sigmask);
@@ -197,7 +198,7 @@ static int __io_uring_submit(struct io_uring *ring, unsigned submitted,
int ret;
flags = 0;
- if (sq_ring_needs_enter(ring, &flags) || wait_nr) {
+ if (sq_ring_needs_enter(ring, submitted, &flags) || wait_nr) {
if (wait_nr || (ring->flags & IORING_SETUP_IOPOLL))
flags |= IORING_ENTER_GETEVENTS;