All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH liburing] test: test ring exit cancels SQPOLL's iowq
@ 2021-04-25 22:38 Pavel Begunkov
  2021-04-29 21:42 ` Pavel Begunkov
  2021-04-29 21:53 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Pavel Begunkov @ 2021-04-25 22:38 UTC (permalink / raw)
  To: Jens Axboe, io-uring

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 <asml.silence@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH liburing] test: test ring exit cancels SQPOLL's iowq
  2021-04-25 22:38 [PATCH liburing] test: test ring exit cancels SQPOLL's iowq Pavel Begunkov
@ 2021-04-29 21:42 ` Pavel Begunkov
  2021-04-29 21:53 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Pavel Begunkov @ 2021-04-29 21:42 UTC (permalink / raw)
  To: Jens Axboe, io-uring

On 4/25/21 11:38 PM, Pavel Begunkov wrote:
> 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.

up

> 
> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
> ---
>  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);
> 

-- 
Pavel Begunkov

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH liburing] test: test ring exit cancels SQPOLL's iowq
  2021-04-25 22:38 [PATCH liburing] test: test ring exit cancels SQPOLL's iowq Pavel Begunkov
  2021-04-29 21:42 ` Pavel Begunkov
@ 2021-04-29 21:53 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2021-04-29 21:53 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring

On 4/25/21 4:38 PM, Pavel Begunkov wrote:
> 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.

Thanks, applied.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-29 21:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-25 22:38 [PATCH liburing] test: test ring exit cancels SQPOLL's iowq Pavel Begunkov
2021-04-29 21:42 ` Pavel Begunkov
2021-04-29 21:53 ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.