public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH liburing] test: test ring exit cancels SQPOLL's iowq
Date: Sun, 25 Apr 2021 23:38:09 +0100	[thread overview]
Message-ID: <5ff453f83e0202fcdb48c27b6597aa615cd17f01.1619390260.git.asml.silence@gmail.com> (raw)

Another SQPOLL cancellation test making sure that io_uring_queue_exit()
does cancel all requests and free the ring, in particular for SQPOLL
requests gone to iowq.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/io-cancel.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/test/io-cancel.c b/test/io-cancel.c
index c08b7e5..c2a39b5 100644
--- a/test/io-cancel.c
+++ b/test/io-cancel.c
@@ -438,6 +438,48 @@ static int test_cancel_inflight_exit(void)
 	return 0;
 }
 
+static int test_sqpoll_cancel_iowq_requests(void)
+{
+	struct io_uring ring;
+	struct io_uring_sqe *sqe;
+	int ret, fds[2];
+	char buffer[16];
+
+	ret = io_uring_queue_init(8, &ring, IORING_SETUP_SQPOLL);
+	if (ret) {
+		fprintf(stderr, "ring create failed: %d\n", ret);
+		return 1;
+	}
+	if (pipe(fds)) {
+		perror("pipe");
+		return 1;
+	}
+	/* pin both pipe ends via io-wq */
+	sqe = io_uring_get_sqe(&ring);
+	io_uring_prep_read(sqe, fds[0], buffer, 10, 0);
+	sqe->flags |= IOSQE_ASYNC | IOSQE_IO_LINK;
+	sqe->user_data = 1;
+
+	sqe = io_uring_get_sqe(&ring);
+	io_uring_prep_write(sqe, fds[1], buffer, 10, 0);
+	sqe->flags |= IOSQE_ASYNC;
+	sqe->user_data = 2;
+	ret = io_uring_submit(&ring);
+	if (ret != 2) {
+		fprintf(stderr, "%s: got %d, wanted 1\n", __FUNCTION__, ret);
+		return 1;
+	}
+
+	/* wait for sqpoll to kick in and submit before exit */
+	sleep(1);
+	io_uring_queue_exit(&ring);
+
+	/* close the write end, so if ring is cancelled properly read() fails*/
+	close(fds[1]);
+	read(fds[0], buffer, 10);
+	close(fds[0]);
+	return 0;
+}
 
 int main(int argc, char *argv[])
 {
@@ -461,6 +503,11 @@ int main(int argc, char *argv[])
 		return 1;
 	}
 
+	if (test_sqpoll_cancel_iowq_requests()) {
+		fprintf(stderr, "test_sqpoll_cancel_iowq_requests() failed\n");
+		return 1;
+	}
+
 	t_create_file(".basic-rw", FILE_SIZE);
 
 	vecs = t_create_buffers(BUFFERS, BS);
-- 
2.31.1


             reply	other threads:[~2021-04-25 22:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-25 22:38 Pavel Begunkov [this message]
2021-04-29 21:42 ` [PATCH liburing] test: test ring exit cancels SQPOLL's iowq Pavel Begunkov
2021-04-29 21:53 ` 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=5ff453f83e0202fcdb48c27b6597aa615cd17f01.1619390260.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