Skip to content

Commit ba0ef83

Browse files
committed
liburing, man: make io_uring_sqring_wait() more consistent with API
Make io_uring_sqring_wait() return an amount of free SQ ring entries or -EINVAL if the ring was not setup with IORING_SETUP_SQPOLL, adjust manual page accordingly. Signed-off-by: Dmitry Antipov <[email protected]>
1 parent 5772879 commit ba0ef83

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

man/io_uring_sqring_wait.3

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ This feature can only be used when the ring has been setup with
2626
and hence is using an offloaded approach to request submissions.
2727

2828
.SH RETURN VALUE
29-
On success it returns the free space. If the kernel does not support the
30-
feature, -EINVAL is returned.
29+
On success it returns an amount of free entries in the SQ ring. If the kernel
30+
does not support the feature, or the ring was not setup with
31+
.B IORING_SETUP_SQPOLL,
32+
-EINVAL is returned.
3133
.SH SEE ALSO
3234
.BR io_uring_submit (3),
3335
.BR io_uring_wait_cqe (3),

src/include/liburing.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,20 +1093,29 @@ static inline unsigned io_uring_sq_space_left(const struct io_uring *ring)
10931093
}
10941094

10951095
/*
1096-
* Only applicable when using SQPOLL - allows the caller to wait for space
1097-
* to free up in the SQ ring, which happens when the kernel side thread has
1098-
* consumed one or more entries. If the SQ ring is currently non-full, no
1099-
* action is taken. Note: may return -EINVAL if the kernel doesn't support
1096+
* Only applicable when using SQPOLL - allows the caller to wait for an at
1097+
* least one free entry in the SQ ring, which happens when the kernel side
1098+
* thread has consumed one or more entries. If the SQ ring is currently
1099+
* non-full, no waiting occured and an amout of free entries is returned
1100+
* immediately. Note: may also return -EINVAL if the kernel doesn't support
11001101
* this feature.
11011102
*/
11021103
static inline int io_uring_sqring_wait(struct io_uring *ring)
11031104
{
1105+
int ret;
1106+
11041107
if (!(ring->flags & IORING_SETUP_SQPOLL))
1105-
return 0;
1106-
if (io_uring_sq_space_left(ring))
1107-
return 0;
1108+
return -EINVAL;
11081109

1109-
return __io_uring_sqring_wait(ring);
1110+
do {
1111+
ret = io_uring_sq_space_left(ring);
1112+
if (ret)
1113+
return ret;
1114+
1115+
ret = __io_uring_sqring_wait(ring);
1116+
if (ret < 0)
1117+
return ret;
1118+
} while (ret == 0);
11101119
}
11111120

11121121
/*

0 commit comments

Comments
 (0)