public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH liburing 1/2] io_uring: test IORING_TIMEOUT_ETIME_SUCCESS
Date: Sun,  3 Oct 2021 12:10:59 +0100	[thread overview]
Message-ID: <d1a5b6bdbcfa1ec6b5ca014248e12b3b1edb4e5d.1633259449.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

Make sure we don't fail links on ETIME when IORING_TIMEOUT_ETIME_SUCCESS
is set.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 src/include/liburing/io_uring.h |  1 +
 test/timeout.c                  | 67 +++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)

diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h
index 7aa43fc..61683bd 100644
--- a/src/include/liburing/io_uring.h
+++ b/src/include/liburing/io_uring.h
@@ -162,6 +162,7 @@ enum {
 #define IORING_TIMEOUT_BOOTTIME		(1U << 2)
 #define IORING_TIMEOUT_REALTIME		(1U << 3)
 #define IORING_LINK_TIMEOUT_UPDATE	(1U << 4)
+#define IORING_TIMEOUT_ETIME_SUCCESS	(1U << 5)
 #define IORING_TIMEOUT_CLOCK_MASK	(IORING_TIMEOUT_BOOTTIME | IORING_TIMEOUT_REALTIME)
 #define IORING_TIMEOUT_UPDATE_MASK	(IORING_TIMEOUT_UPDATE | IORING_LINK_TIMEOUT_UPDATE)
 /*
diff --git a/test/timeout.c b/test/timeout.c
index 775063f..f8ba973 100644
--- a/test/timeout.c
+++ b/test/timeout.c
@@ -1267,6 +1267,67 @@ static int test_timeout_link_cancel(void)
 	return 0;
 }
 
+
+static int test_not_failing_links(void)
+{
+	struct io_uring ring;
+	struct io_uring_sqe *sqe;
+	struct io_uring_cqe *cqe;
+	struct __kernel_timespec ts;
+	int ret;
+
+	ret = io_uring_queue_init(8, &ring, 0);
+	if (ret) {
+		fprintf(stderr, "ring create failed: %d\n", ret);
+		return 1;
+	}
+
+	msec_to_ts(&ts, 1);
+	sqe = io_uring_get_sqe(&ring);
+	io_uring_prep_timeout(sqe, &ts, 0, IORING_TIMEOUT_ETIME_SUCCESS);
+	sqe->user_data = 1;
+	sqe->flags |= IOSQE_IO_LINK;
+
+	sqe = io_uring_get_sqe(&ring);
+	io_uring_prep_nop(sqe);
+	sqe->user_data = 2;
+
+	ret = io_uring_submit(&ring);
+	if (ret != 2) {
+		fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
+		return 1;
+	}
+
+	ret = io_uring_wait_cqe(&ring, &cqe);
+	if (ret < 0) {
+		fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
+		return 1;
+	} else if (cqe->user_data == 1 && cqe->res == -EINVAL) {
+		fprintf(stderr, "ETIME_SUCCESS is not supported, skip\n");
+		goto done;
+	} else if (cqe->res != -ETIME || cqe->user_data != 1) {
+		fprintf(stderr, "timeout failed %i %i\n", cqe->res,
+				(int)cqe->user_data);
+		return 1;
+	}
+	io_uring_cqe_seen(&ring, cqe);
+
+	ret = io_uring_wait_cqe(&ring, &cqe);
+	if (ret < 0) {
+		fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
+		return 1;
+	} else if (cqe->res || cqe->user_data != 2) {
+		fprintf(stderr, "nop failed %i %i\n", cqe->res,
+				(int)cqe->user_data);
+		return 1;
+	}
+done:
+	io_uring_cqe_seen(&ring, cqe);
+	io_uring_queue_exit(&ring);
+	return 0;
+}
+
+
 int main(int argc, char *argv[])
 {
 	struct io_uring ring, sqpoll_ring;
@@ -1450,6 +1511,12 @@ int main(int argc, char *argv[])
 		return ret;
 	}
 
+	ret = test_not_failing_links();
+	if (ret) {
+		fprintf(stderr, "test_not_failing_links failed\n");
+		return ret;
+	}
+
 	if (sqpoll)
 		io_uring_queue_exit(&sqpoll_ring);
 	return 0;
-- 
2.33.0


  reply	other threads:[~2021-10-03 11:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-03 11:10 [PATCH liburing 0/2] timeout tests Pavel Begunkov
2021-10-03 11:10 ` Pavel Begunkov [this message]
2021-10-03 11:11 ` [PATCH liburing 2/2] io_uring: fix SQPOLL timeout-new test Pavel Begunkov
2021-10-03 13:07 ` [PATCH liburing 0/2] timeout tests Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d1a5b6bdbcfa1ec6b5ca014248e12b3b1edb4e5d.1633259449.git.asml.silence@gmail.com \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox