* [PATCH liburing] Test wait after under-consuming
@ 2019-12-13 8:06 Pavel Begunkov
2019-12-13 8:41 ` Pavel Begunkov
2019-12-13 17:11 ` [PATCH v2 " Pavel Begunkov
0 siblings, 2 replies; 4+ messages in thread
From: Pavel Begunkov @ 2019-12-13 8:06 UTC (permalink / raw)
To: Jens Axboe, io-uring, linux-kernel
In case of an error submission won't consume all sqes. This tests that
it will get back to the userspace even if (to_submit == to_wait)
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/link.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 55 insertions(+), 1 deletion(-)
diff --git a/test/link.c b/test/link.c
index 8ec1649..93653f3 100644
--- a/test/link.c
+++ b/test/link.c
@@ -384,6 +384,55 @@ err:
return 1;
}
+static int test_early_fail_and_wait(struct io_uring *ring)
+{
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ int ret, submitted, i;
+ const int invalid_fd = 42;
+ struct iovec iov = { .iov_base = NULL, .iov_len = 0 };
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ io_uring_prep_readv(sqe, invalid_fd, &iov, 1, 0);
+ sqe->user_data = 1;
+ sqe->flags |= IOSQE_IO_LINK;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ io_uring_prep_nop(sqe);
+ sqe->user_data = 2;
+
+ submitted = io_uring_submit_and_wait(ring, 2);
+ if (submitted == -EAGAIN)
+ return 0;
+ if (submitted <= 0) {
+ printf("sqe submit failed: %d\n", submitted);
+ goto err;
+ }
+
+ for (i = 0; i < 2; i++) {
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret < 0) {
+ printf("wait completion %d\n", ret);
+ goto err;
+ }
+ io_uring_cqe_seen(ring, cqe);
+ }
+
+ return 0;
+err:
+ return 1;
+}
+
int main(int argc, char *argv[])
{
struct io_uring ring, poll_ring;
@@ -400,7 +449,6 @@ int main(int argc, char *argv[])
if (ret) {
printf("poll_ring setup failed\n");
return 1;
-
}
ret = test_single_link(&ring);
@@ -439,5 +487,11 @@ int main(int argc, char *argv[])
return ret;
}
+ ret = test_early_fail_and_wait(&ring);
+ if (ret) {
+ fprintf(stderr, "test_early_fail_and_wait\n");
+ return ret;
+ }
+
return 0;
}
--
2.24.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH liburing] Test wait after under-consuming
2019-12-13 8:06 [PATCH liburing] Test wait after under-consuming Pavel Begunkov
@ 2019-12-13 8:41 ` Pavel Begunkov
2019-12-13 17:11 ` [PATCH v2 " Pavel Begunkov
1 sibling, 0 replies; 4+ messages in thread
From: Pavel Begunkov @ 2019-12-13 8:41 UTC (permalink / raw)
To: Jens Axboe, io-uring, linux-kernel
On 12/13/2019 11:06 AM, Pavel Begunkov wrote:
> In case of an error submission won't consume all sqes. This tests that
> it will get back to the userspace even if (to_submit == to_wait)
>
> Signed-off-by: Pavel Begunkov <[email protected]>
> ---
> test/link.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 55 insertions(+), 1 deletion(-)
>
> diff --git a/test/link.c b/test/link.c
> index 8ec1649..93653f3 100644
> --- a/test/link.c
> +++ b/test/link.c
> @@ -384,6 +384,55 @@ err:
> return 1;
> }
>
> +static int test_early_fail_and_wait(struct io_uring *ring)
> +{
> + struct io_uring_cqe *cqe;
> + struct io_uring_sqe *sqe;
> + int ret, submitted, i;
> + const int invalid_fd = 42;
> + struct iovec iov = { .iov_base = NULL, .iov_len = 0 };
> +
> + sqe = io_uring_get_sqe(ring);
> + if (!sqe) {
> + printf("get sqe failed\n");
> + goto err;
> + }
> +
> + io_uring_prep_readv(sqe, invalid_fd, &iov, 1, 0);
> + sqe->user_data = 1;
> + sqe->flags |= IOSQE_IO_LINK;
> +
> + sqe = io_uring_get_sqe(ring);
> + if (!sqe) {
> + printf("get sqe failed\n");
> + goto err;
> + }
> +
> + io_uring_prep_nop(sqe);
> + sqe->user_data = 2;
> +
> + submitted = io_uring_submit_and_wait(ring, 2);
> + if (submitted == -EAGAIN)
> + return 0;
As io_uring isn't recreated for each test case, I need to complete all
cqes in any case. I'll resend
> + if (submitted <= 0) {
> + printf("sqe submit failed: %d\n", submitted);
> + goto err;
> + }
> +
> + for (i = 0; i < 2; i++) {
> + ret = io_uring_wait_cqe(ring, &cqe);
> + if (ret < 0) {
> + printf("wait completion %d\n", ret);
> + goto err;
> + }
> + io_uring_cqe_seen(ring, cqe);
> + }
> +
> + return 0;
> +err:
> + return 1;
> +}
> +
> int main(int argc, char *argv[])
> {
> struct io_uring ring, poll_ring;
> @@ -400,7 +449,6 @@ int main(int argc, char *argv[])
> if (ret) {
> printf("poll_ring setup failed\n");
> return 1;
> -
> }
>
> ret = test_single_link(&ring);
> @@ -439,5 +487,11 @@ int main(int argc, char *argv[])
> return ret;
> }
>
> + ret = test_early_fail_and_wait(&ring);
> + if (ret) {
> + fprintf(stderr, "test_early_fail_and_wait\n");
> + return ret;
> + }
> +
> return 0;
> }
>
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 liburing] Test wait after under-consuming
2019-12-13 8:06 [PATCH liburing] Test wait after under-consuming Pavel Begunkov
2019-12-13 8:41 ` Pavel Begunkov
@ 2019-12-13 17:11 ` Pavel Begunkov
2019-12-13 18:41 ` Jens Axboe
1 sibling, 1 reply; 4+ messages in thread
From: Pavel Begunkov @ 2019-12-13 17:11 UTC (permalink / raw)
To: Jens Axboe, io-uring, linux-kernel
In case of an error submission won't consume all sqes. This tests that
it will get back to the userspace even if (to_submit == to_wait)
Signed-off-by: Pavel Begunkov <[email protected]>
---
since v1: don't leave ring dirty, as it will fail following tests
test/link.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 50 insertions(+), 1 deletion(-)
diff --git a/test/link.c b/test/link.c
index 8ec1649..6c8ae09 100644
--- a/test/link.c
+++ b/test/link.c
@@ -384,6 +384,50 @@ err:
return 1;
}
+static int test_early_fail_and_wait(void)
+{
+ struct io_uring ring;
+ struct io_uring_sqe *sqe;
+ int ret, invalid_fd = 42;
+ struct iovec iov = { .iov_base = NULL, .iov_len = 0 };
+
+ /* create a new ring as it leaves it dirty */
+ ret = io_uring_queue_init(8, &ring, 0);
+ if (ret) {
+ printf("ring setup failed\n");
+ return 1;
+ }
+
+ sqe = io_uring_get_sqe(&ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ io_uring_prep_readv(sqe, invalid_fd, &iov, 1, 0);
+ sqe->flags |= IOSQE_IO_LINK;
+
+ sqe = io_uring_get_sqe(&ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ io_uring_prep_nop(sqe);
+
+ ret = io_uring_submit_and_wait(&ring, 2);
+ if (ret <= 0 && ret != -EAGAIN) {
+ printf("sqe submit failed: %d\n", ret);
+ goto err;
+ }
+
+ io_uring_queue_exit(&ring);
+ return 0;
+err:
+ io_uring_queue_exit(&ring);
+ return 1;
+}
+
int main(int argc, char *argv[])
{
struct io_uring ring, poll_ring;
@@ -400,7 +444,6 @@ int main(int argc, char *argv[])
if (ret) {
printf("poll_ring setup failed\n");
return 1;
-
}
ret = test_single_link(&ring);
@@ -439,5 +482,11 @@ int main(int argc, char *argv[])
return ret;
}
+ ret = test_early_fail_and_wait();
+ if (ret) {
+ fprintf(stderr, "test_early_fail_and_wait\n");
+ return ret;
+ }
+
return 0;
}
--
2.24.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-12-13 20:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-13 8:06 [PATCH liburing] Test wait after under-consuming Pavel Begunkov
2019-12-13 8:41 ` Pavel Begunkov
2019-12-13 17:11 ` [PATCH v2 " Pavel Begunkov
2019-12-13 18:41 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox