io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] io_uring: separate the io_free_req and io_free_req_find_next interface
@ 2019-11-09  3:00 Jackie Liu
  2019-11-09  3:00 ` [PATCH] liburing: Add regression test case for link with drain Jackie Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Jackie Liu @ 2019-11-09  3:00 UTC (permalink / raw)
  To: axboe; +Cc: io-uring, liuyun01

Similar to the distinction between io_put_req and io_put_req_find_next,
io_free_req has been modified similarly, with no functional changes.

Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 fs/io_uring.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index d2ec37f..859cf8a 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -919,7 +919,7 @@ static void io_fail_links(struct io_kiocb *req)
 	io_cqring_ev_posted(ctx);
 }
 
-static void io_free_req(struct io_kiocb *req, struct io_kiocb **nxt)
+static void io_free_req_find_next(struct io_kiocb *req, struct io_kiocb **nxt)
 {
 	if (likely(!(req->flags & REQ_F_LINK))) {
 		__io_free_req(req);
@@ -953,6 +953,11 @@ static void io_free_req(struct io_kiocb *req, struct io_kiocb **nxt)
 	__io_free_req(req);
 }
 
+static void io_free_req(struct io_kiocb *req)
+{
+	io_free_req_find_next(req, NULL);
+}
+
 /*
  * Drop reference to request, return next in chain (if there is one) if this
  * was the last reference to this request.
@@ -962,7 +967,7 @@ static void io_put_req_find_next(struct io_kiocb *req, struct io_kiocb **nxtptr)
 	struct io_kiocb *nxt = NULL;
 
 	if (refcount_dec_and_test(&req->refs))
-		io_free_req(req, &nxt);
+		io_free_req_find_next(req, &nxt);
 
 	if (nxt) {
 		if (nxtptr)
@@ -975,7 +980,7 @@ static void io_put_req_find_next(struct io_kiocb *req, struct io_kiocb **nxtptr)
 static void io_put_req(struct io_kiocb *req)
 {
 	if (refcount_dec_and_test(&req->refs))
-		io_free_req(req, NULL);
+		io_free_req(req);
 }
 
 static void io_double_put_req(struct io_kiocb *req)
@@ -1043,7 +1048,7 @@ static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events,
 				if (to_free == ARRAY_SIZE(reqs))
 					io_free_req_many(ctx, reqs, &to_free);
 			} else {
-				io_free_req(req, NULL);
+				io_free_req(req);
 			}
 		}
 	}
-- 
2.7.4




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

* [PATCH] liburing: Add regression test case for link with drain
  2019-11-09  3:00 [PATCH] io_uring: separate the io_free_req and io_free_req_find_next interface Jackie Liu
@ 2019-11-09  3:00 ` Jackie Liu
  2019-11-09  3:10   ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Jackie Liu @ 2019-11-09  3:00 UTC (permalink / raw)
  To: axboe; +Cc: io-uring, liuyun01

Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 test/Makefile     |   5 ++-
 test/link_drain.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 125 insertions(+), 2 deletions(-)
 create mode 100644 test/link_drain.c

diff --git a/test/Makefile b/test/Makefile
index 345e663..f7310cf 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -9,7 +9,7 @@ all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register
 		sq-space_left stdout cq-ready cq-peek-batch file-register \
 		cq-size 8a9973408177-test a0908ae19763-test 232c93d07b74-test \
 		socket-rw accept timeout-overflow defer read-write io-cancel \
-		link-timeout
+		link-timeout link_drain
 
 include ../Makefile.quiet
 
@@ -25,7 +25,8 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \
 	500f9fbadef8-test.c timeout.c sq-space_left.c stdout.c cq-ready.c\
 	cq-peek-batch.c file-register.c cq-size.c 8a9973408177-test.c \
 	a0908ae19763-test.c 232c93d07b74-test.c socket-rw.c accept.c \
-	timeout-overflow.c defer.c read-write.c io-cancel.c link-timeout.c
+	timeout-overflow.c defer.c read-write.c io-cancel.c link-timeout.c \
+	link_drain.c
 
 test_objs := $(patsubst %.c,%.ol,$(test_srcs))
 
diff --git a/test/link_drain.c b/test/link_drain.c
new file mode 100644
index 0000000..aafd139
--- /dev/null
+++ b/test/link_drain.c
@@ -0,0 +1,122 @@
+/*
+ * Description: test io_uring link io with drain io
+ *
+ */
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "liburing.h"
+
+char expect[6][5] = {
+	{ 0, 1, 2, 3, 4 },
+	{ 0, 1, 2, 4, 3 },
+	{ 0, 1, 4, 2, 3 }
+};
+
+static int test_link_drain(struct io_uring *ring)
+{
+	struct io_uring_cqe *cqe;
+	struct io_uring_sqe *sqe[5];
+	struct iovec iovecs;
+	int i, fd, ret;
+	off_t off = 0;
+	char data[5] = {0};
+
+	fd = open("testfile", O_WRONLY | O_CREAT, 0644);
+	if (fd < 0) {
+		perror("open");
+		return 1;
+	}
+
+	iovecs.iov_base = malloc(4096);
+	iovecs.iov_len = 4096;
+
+	for (i = 0; i < 5; i++) {
+		sqe[i] = io_uring_get_sqe(ring);
+		if (!sqe[i]) {
+			printf("get sqe failed\n");
+			goto err;
+		}
+	}
+
+	/* normal heavy io */
+	io_uring_prep_writev(sqe[0], fd, &iovecs, 1, off);
+	sqe[0]->user_data = 0;
+
+	/* link io */
+	io_uring_prep_nop(sqe[1]);
+	sqe[1]->flags |= IOSQE_IO_LINK;
+	sqe[1]->user_data = 1;
+
+	/* link drain io */
+	io_uring_prep_nop(sqe[2]);
+	sqe[2]->flags |= (IOSQE_IO_LINK | IOSQE_IO_DRAIN);
+	sqe[2]->user_data = 2;
+
+	/* link io */
+	io_uring_prep_nop(sqe[3]);
+	sqe[3]->user_data = 3;
+
+	/* normal nop io */
+	io_uring_prep_nop(sqe[4]);
+	sqe[4]->user_data = 4;
+
+	ret = io_uring_submit(ring);
+	if (ret < 5) {
+		printf("Submitted only %d\n", ret);
+		goto err;
+	} else if (ret < 0) {
+		printf("sqe submit failed\n");
+		goto err;
+	}
+
+	for (i = 0; i < 5; i++) {
+		ret = io_uring_wait_cqe(ring, &cqe);
+		if (ret < 0) {
+			printf("child: wait completion %d\n", ret);
+			goto err;
+		}
+
+		data[i] = cqe->user_data;
+		io_uring_cqe_seen(ring, cqe);
+	}
+
+	free(iovecs.iov_base);
+
+	for (i = 0; i < 6; i++) {
+		if (memcmp(data, expect[i], 5) == 0)
+			break;
+	}
+	if (i == 6)
+		goto err;
+
+	unlink("testfile");
+	return 0;
+err:
+	unlink("testfile");
+	return 1;
+}
+
+int main(int argc, char *argv[])
+{
+	struct io_uring ring;
+	int i, ret;
+
+	ret = io_uring_queue_init(5, &ring, 0);
+	if (ret) {
+		printf("ring setup failed\n");
+		return 1;
+	}
+
+	for (i = 0; i < 1000; i++)
+		ret |= test_link_drain(&ring);
+
+	if (ret)
+		return ret;
+
+	return 0;
+}
-- 
2.7.4




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

* Re: [PATCH] liburing: Add regression test case for link with drain
  2019-11-09  3:00 ` [PATCH] liburing: Add regression test case for link with drain Jackie Liu
@ 2019-11-09  3:10   ` Jens Axboe
  0 siblings, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2019-11-09  3:10 UTC (permalink / raw)
  To: Jackie Liu; +Cc: io-uring

On 11/8/19 8:00 PM, Jackie Liu wrote:
> Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
> ---
>   test/Makefile     |   5 ++-
>   test/link_drain.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>   2 files changed, 125 insertions(+), 2 deletions(-)
>   create mode 100644 test/link_drain.c

Great to have this! Thanks.

I really like how the regressions tests keep on growing, and generally of
high quality. We would not be able to move as fast on features or changes
on io_uring as we do now, if it wasn't for the test suite.

-- 
Jens Axboe


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

end of thread, other threads:[~2019-11-09  3:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-09  3:00 [PATCH] io_uring: separate the io_free_req and io_free_req_find_next interface Jackie Liu
2019-11-09  3:00 ` [PATCH] liburing: Add regression test case for link with drain Jackie Liu
2019-11-09  3:10   ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).