io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* SQPOLL behaviour with openat
@ 2020-01-04 16:22 wdauchy
  2020-01-04 16:28 ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: wdauchy @ 2020-01-04 16:22 UTC (permalink / raw)
  To: io-uring

Hello,

I am trying to understand SQPOLL behaviour using liburing. I modified the
test in liburing (see below). The test is failing when we use `openat` 
with SQPOLL:

cqe res -9
test_io failed 0/0/1/0/0

Is `openat` supported with SQPOLL? If not I would expect -EINVAL as a
return value, but maybe I'm missing something.
note: I also tested without io_uring_register_files call.

-- 
William

---
 test/read-write.c | 47 ++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 44 insertions(+), 3 deletions(-)

diff --git a/test/read-write.c b/test/read-write.c
index d150f44..05baf0f 100644
--- a/test/read-write.c
+++ b/test/read-write.c
@@ -58,7 +58,7 @@ static int test_io(const char *file, int write, int buffered, int sqthread,
 	struct io_uring_cqe *cqe;
 	struct io_uring ring;
 	int open_flags, ring_flags;
-	int i, fd, ret;
+	int i, dirfd, fd, use_fd, ret;
 
 #ifdef VERBOSE
 	fprintf(stdout, "%s: start %d/%d/%d/%d/%d: ", __FUNCTION__, write,
@@ -79,7 +79,7 @@ static int test_io(const char *file, int write, int buffered, int sqthread,
 	if (!buffered)
 		open_flags |= O_DIRECT;
 
-	fd = open(file, open_flags);
+	dirfd = open(".", O_RDONLY);
 	if (fd < 0) {
 		perror("file open");
 		goto err;
@@ -95,6 +95,46 @@ static int test_io(const char *file, int write, int buffered, int sqthread,
 		goto err;
 	}
 
+	use_fd = dirfd;
+	if (sqthread) {
+		ret = io_uring_register_files(&ring, &dirfd, 1);
+		if (ret) {
+			fprintf(stderr, "file reg failed: %d\n", ret);
+			goto err;
+		}
+		use_fd = 0;
+	}
+	sqe = io_uring_get_sqe(&ring);
+	if (!sqe) {
+		fprintf(stderr, "sqe get failed\n");
+		goto err;
+	}
+	io_uring_prep_openat(sqe, use_fd, file, open_flags, 0);
+	ret = io_uring_submit(&ring);
+	if (ret != 1) {
+		fprintf(stderr, "submit got %d\n", ret);
+		goto err;
+	}
+	ret = io_uring_wait_cqe(&ring, &cqe);
+	if (ret) {
+		fprintf(stderr, "wait_cqe=%d\n", ret);
+		goto err;
+	}
+	if (cqe->res < 0) {
+		fprintf(stderr, "cqe res %d\n", cqe->res);
+		goto err;
+	}
+	fd = cqe->res;
+	io_uring_cqe_seen(&ring, cqe);
+
+	if (sqthread) {
+		ret = io_uring_unregister_files(&ring);
+		if (ret) {
+			fprintf(stderr, "file unreg failed: %d\n", ret);
+			goto err;
+		}
+	}
+
 	if (fixed) {
 		ret = io_uring_register_buffers(&ring, vecs, BUFFERS);
 		if (ret) {
@@ -121,7 +161,7 @@ static int test_io(const char *file, int write, int buffered, int sqthread,
 		offset = BS * (rand() % BUFFERS);
 		if (write) {
 			int do_fixed = fixed;
-			int use_fd = fd;
+			use_fd = fd;
 
 			if (sqthread)
 				use_fd = 0;
@@ -193,6 +233,7 @@ static int test_io(const char *file, int write, int buffered, int sqthread,
 
 	io_uring_queue_exit(&ring);
 	close(fd);
+	close(dirfd);
 #ifdef VERBOSE
 	printf("PASS\n");
 #endif
-- 
2.24.1


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

end of thread, other threads:[~2020-01-04 17:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-04 16:22 SQPOLL behaviour with openat wdauchy
2020-01-04 16:28 ` Jens Axboe
2020-01-04 16:41   ` William Dauchy
2020-01-04 17:41     ` 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).