public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH liburing] test/read-write: add test for CQE res when removing buffers
@ 2023-04-01 19:52 Wojciech Lukowicz
  2023-04-01 23:20 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Wojciech Lukowicz @ 2023-04-01 19:52 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring, Wojciech Lukowicz

When removing provided buffers, CQE res should contain the number of
removed buffers. However, in certain kernel versions, if SQE requests
removal of more buffers than available, then res will contain the number
of removed buffers + 1.

Signed-off-by: Wojciech Lukowicz <[email protected]>
---
This is a failing test, needs the patch I sent earlier.

 test/read-write.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/test/read-write.c b/test/read-write.c
index 3764f6aef47e..6f24ec919de3 100644
--- a/test/read-write.c
+++ b/test/read-write.c
@@ -637,6 +637,53 @@ static int test_rem_buf(int batch, int sqe_flags)
 	return ret;
 }
 
+static int test_rem_buf_single(int to_rem)
+{
+	struct io_uring_sqe *sqe;
+	struct io_uring_cqe *cqe;
+	struct io_uring ring;
+	int ret, expected;
+	int bgid = 1;
+
+	if (no_buf_select)
+		return 0;
+
+	ret = io_uring_queue_init(64, &ring, 0);
+	if (ret) {
+		fprintf(stderr, "ring create failed: %d\n", ret);
+		return 1;
+	}
+
+	ret = provide_buffers_iovec(&ring, bgid);
+	if (ret)
+		return ret;
+
+	expected = (to_rem > BUFFERS) ? BUFFERS : to_rem;
+
+	sqe = io_uring_get_sqe(&ring);
+	io_uring_prep_remove_buffers(sqe, to_rem, bgid);
+
+	ret = io_uring_submit(&ring);
+	if (ret != 1) {
+		fprintf(stderr, "submit: %d\n", ret);
+		return -1;
+	}
+
+	ret = io_uring_wait_cqe(&ring, &cqe);
+	if (ret) {
+		fprintf(stderr, "wait_cqe=%d\n", ret);
+		return 1;
+	}
+	if (cqe->res != expected) {
+		fprintf(stderr, "cqe->res=%d, expected=%d\n", cqe->res, expected);
+		return 1;
+	}
+	io_uring_cqe_seen(&ring, cqe);
+
+	io_uring_queue_exit(&ring);
+	return ret;
+}
+
 static int test_io_link(const char *file)
 {
 	const int nr_links = 100;
@@ -950,6 +997,12 @@ int main(int argc, char *argv[])
 		}
 	}
 
+	ret = test_rem_buf_single(BUFFERS + 1);
+	if (ret) {
+		fprintf(stderr, "test_rem_buf_single(BUFFERS + 1) failed\n");
+		goto err;
+	}
+
 	if (fname != argv[1])
 		unlink(fname);
 	return 0;
-- 
2.30.2


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

* Re: [PATCH liburing] test/read-write: add test for CQE res when removing buffers
  2023-04-01 19:52 [PATCH liburing] test/read-write: add test for CQE res when removing buffers Wojciech Lukowicz
@ 2023-04-01 23:20 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2023-04-01 23:20 UTC (permalink / raw)
  To: Wojciech Lukowicz; +Cc: io-uring


On Sat, 01 Apr 2023 20:52:59 +0100, Wojciech Lukowicz wrote:
> When removing provided buffers, CQE res should contain the number of
> removed buffers. However, in certain kernel versions, if SQE requests
> removal of more buffers than available, then res will contain the number
> of removed buffers + 1.
> 
> 

Applied, thanks!

[1/1] test/read-write: add test for CQE res when removing buffers
      commit: ce9ef761e8d29399a079710a78cc84665466a754

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2023-04-01 23:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-01 19:52 [PATCH liburing] test/read-write: add test for CQE res when removing buffers Wojciech Lukowicz
2023-04-01 23:20 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox