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 2/2] tests: use helpers for direct open/accept
Date: Tue, 31 Aug 2021 17:30:13 +0100	[thread overview]
Message-ID: <d720255e0861688541efb812318f9423ee01e2a3.1630427247.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

For the test to be less confusing, use helpers in tests that place new
files right into the fixed file table.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/accept.c  |  7 ++++---
 test/openat2.c | 27 +++++++++++++++------------
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/test/accept.c b/test/accept.c
index 21db14f..0c69b98 100644
--- a/test/accept.c
+++ b/test/accept.c
@@ -65,9 +65,10 @@ static int accept_conn(struct io_uring *ring, int fd, bool fixed)
 	int ret, fixed_idx = 0;
 
 	sqe = io_uring_get_sqe(ring);
-	io_uring_prep_accept(sqe, fd, NULL, NULL, 0);
-	if (fixed)
-		sqe->file_index = fixed_idx + 1;
+	if (!fixed)
+		io_uring_prep_accept(sqe, fd, NULL, NULL, 0);
+	else
+		io_uring_prep_accept_direct(sqe, fd, NULL, NULL, 0, fixed_idx);
 
 	ret = io_uring_submit(ring);
 	assert(ret != -1);
diff --git a/test/openat2.c b/test/openat2.c
index afc30a0..7838c05 100644
--- a/test/openat2.c
+++ b/test/openat2.c
@@ -14,7 +14,7 @@
 #include "liburing.h"
 
 static int test_openat2(struct io_uring *ring, const char *path, int dfd,
-			int fixed_slot)
+			bool direct, int fixed_index)
 {
 	struct io_uring_cqe *cqe;
 	struct io_uring_sqe *sqe;
@@ -28,8 +28,11 @@ static int test_openat2(struct io_uring *ring, const char *path, int dfd,
 	}
 	memset(&how, 0, sizeof(how));
 	how.flags = O_RDWR;
-	io_uring_prep_openat2(sqe, dfd, path, &how);
-	sqe->file_index = fixed_slot;
+
+	if (!direct)
+		io_uring_prep_openat2(sqe, dfd, path, &how);
+	else
+		io_uring_prep_openat2_direct(sqe, dfd, path, &how, fixed_index);
 
 	ret = io_uring_submit(ring);
 	if (ret <= 0) {
@@ -45,7 +48,7 @@ static int test_openat2(struct io_uring *ring, const char *path, int dfd,
 	ret = cqe->res;
 	io_uring_cqe_seen(ring, cqe);
 
-	if (fixed_slot && ret > 0) {
+	if (direct && ret > 0) {
 		close(ret);
 		return -EINVAL;
 	}
@@ -72,7 +75,7 @@ static int test_open_fixed(const char *path, int dfd)
 		return -1;
 	}
 
-	ret = test_openat2(&ring, path, dfd, 1);
+	ret = test_openat2(&ring, path, dfd, true, 0);
 	if (ret == -EINVAL) {
 		printf("fixed open isn't supported\n");
 		return 1;
@@ -114,7 +117,7 @@ static int test_open_fixed(const char *path, int dfd)
 		return -1;
 	}
 
-	ret = test_openat2(&ring, path, dfd, 1);
+	ret = test_openat2(&ring, path, dfd, true, 0);
 	if (ret != -EBADF) {
 		fprintf(stderr, "bogus double register %d\n", ret);
 		return -1;
@@ -134,7 +137,7 @@ static int test_open_fixed_fail(const char *path, int dfd)
 		return -1;
 	}
 
-	ret = test_openat2(&ring, path, dfd, 1);
+	ret = test_openat2(&ring, path, dfd, true, 0);
 	if (ret != -ENXIO) {
 		fprintf(stderr, "install into not existing table, %i\n", ret);
 		return 1;
@@ -146,19 +149,19 @@ static int test_open_fixed_fail(const char *path, int dfd)
 		return -1;
 	}
 
-	ret = test_openat2(&ring, path, dfd, 2);
+	ret = test_openat2(&ring, path, dfd, true, 1);
 	if (ret != -EINVAL) {
 		fprintf(stderr, "install out of bounds, %i\n", ret);
 		return 1;
 	}
 
-	ret = test_openat2(&ring, path, dfd, (1u << 16));
+	ret = test_openat2(&ring, path, dfd, true, (1u << 16));
 	if (ret != -EINVAL) {
 		fprintf(stderr, "install out of bounds or u16 overflow, %i\n", ret);
 		return 1;
 	}
 
-	ret = test_openat2(&ring, path, dfd, (1u << 16) + 1);
+	ret = test_openat2(&ring, path, dfd, true, (1u << 16) + 1);
 	if (ret != -EINVAL) {
 		fprintf(stderr, "install out of bounds or u16 overflow, %i\n", ret);
 		return 1;
@@ -196,7 +199,7 @@ int main(int argc, char *argv[])
 	if (do_unlink)
 		t_create_file(path_rel, 4096);
 
-	ret = test_openat2(&ring, path, -1, 0);
+	ret = test_openat2(&ring, path, -1, false, 0);
 	if (ret < 0) {
 		if (ret == -EINVAL) {
 			fprintf(stdout, "openat2 not supported, skipping\n");
@@ -206,7 +209,7 @@ int main(int argc, char *argv[])
 		goto err;
 	}
 
-	ret = test_openat2(&ring, path_rel, AT_FDCWD, 0);
+	ret = test_openat2(&ring, path_rel, AT_FDCWD, false, 0);
 	if (ret < 0) {
 		fprintf(stderr, "test_openat2 relative failed: %d\n", ret);
 		goto err;
-- 
2.33.0


  parent reply	other threads:[~2021-08-31 16:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-31 16:30 [PATCH liburing 0/2] add direct open/accept helpers Pavel Begunkov
2021-08-31 16:30 ` [PATCH liburing 1/2] liburing: add helpers for direct open/accept Pavel Begunkov
2021-08-31 16:30 ` Pavel Begunkov [this message]
2021-08-31 17:00 ` [PATCH liburing 0/2] add direct open/accept helpers 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=d720255e0861688541efb812318f9423ee01e2a3.1630427247.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