io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH liburing for-next 0/2] fd msg-ring slot allocation tests
@ 2023-03-16 13:09 Pavel Begunkov
  2023-03-16 13:09 ` [PATCH liburing 1/2] Add io_uring_prep_msg_ring_fd_alloc() helper Pavel Begunkov
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Pavel Begunkov @ 2023-03-16 13:09 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe, asml.silence

Add a helper for fd msg-ring passing a file and auto allocating the
target index, and test it.

Pavel Begunkov (2):
  Add io_uring_prep_msg_ring_fd_alloc() helper
  test: test fd msg-ring allocating indexes

 src/include/liburing.h |  9 +++++++++
 test/fd-pass.c         | 37 ++++++++++++++++++++++++++++++++++---
 2 files changed, 43 insertions(+), 3 deletions(-)

-- 
2.39.1


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

* [PATCH liburing 1/2] Add io_uring_prep_msg_ring_fd_alloc() helper
  2023-03-16 13:09 [PATCH liburing for-next 0/2] fd msg-ring slot allocation tests Pavel Begunkov
@ 2023-03-16 13:09 ` Pavel Begunkov
  2023-03-16 15:01   ` Jens Axboe
  2023-03-16 13:09 ` [PATCH liburing 2/2] test: test fd msg-ring allocating indexes Pavel Begunkov
  2023-03-16 15:02 ` [PATCH liburing for-next 0/2] fd msg-ring slot allocation tests Jens Axboe
  2 siblings, 1 reply; 5+ messages in thread
From: Pavel Begunkov @ 2023-03-16 13:09 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe, asml.silence

Add a helper initialising msg-ring requests transferring files and
allocating a target file index.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 src/include/liburing.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/include/liburing.h b/src/include/liburing.h
index bf48141..0848cf0 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -1015,6 +1015,15 @@ IOURINGINLINE void io_uring_prep_msg_ring_fd(struct io_uring_sqe *sqe, int fd,
 	sqe->msg_ring_flags = flags;
 }
 
+IOURINGINLINE void io_uring_prep_msg_ring_fd_alloc(struct io_uring_sqe *sqe,
+						   int fd, int source_fd,
+						   __u64 data, unsigned int flags)
+{
+	io_uring_prep_msg_ring_fd(sqe, fd, source_fd,
+				  IORING_FILE_INDEX_ALLOC - 1,
+				  data, flags);
+}
+
 IOURINGINLINE void io_uring_prep_getxattr(struct io_uring_sqe *sqe,
 					  const char *name, char *value,
 					  const char *path, unsigned int len)
-- 
2.39.1


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

* [PATCH liburing 2/2] test: test fd msg-ring allocating indexes
  2023-03-16 13:09 [PATCH liburing for-next 0/2] fd msg-ring slot allocation tests Pavel Begunkov
  2023-03-16 13:09 ` [PATCH liburing 1/2] Add io_uring_prep_msg_ring_fd_alloc() helper Pavel Begunkov
@ 2023-03-16 13:09 ` Pavel Begunkov
  2023-03-16 15:02 ` [PATCH liburing for-next 0/2] fd msg-ring slot allocation tests Jens Axboe
  2 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2023-03-16 13:09 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe, asml.silence

fd msg-ring requests supports IORING_FILE_INDEX_ALLOC, add a test for
that.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 test/fd-pass.c | 37 ++++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/test/fd-pass.c b/test/fd-pass.c
index f3ede77..0c981fb 100644
--- a/test/fd-pass.c
+++ b/test/fd-pass.c
@@ -80,6 +80,14 @@ static int test(const char *filename, int source_fd, int target_fd)
 		fprintf(stderr, "register files failed %d\n", ret);
 		return T_EXIT_FAIL;
 	}
+	if (target_fd == IORING_FILE_INDEX_ALLOC) {
+		/* we want to test installing into a non-zero slot */
+		ret = io_uring_register_file_alloc_range(&dring, 1, 1);
+		if (ret) {
+			fprintf(stderr, "io_uring_register_file_alloc_range %d\n", ret);
+			return T_EXIT_FAIL;
+		}
+	}
 
 	/* open direct descriptor */
 	sqe = io_uring_get_sqe(&sring);
@@ -102,8 +110,14 @@ static int test(const char *filename, int source_fd, int target_fd)
 
 	/* send direct descriptor to destination ring */
 	sqe = io_uring_get_sqe(&sring);
-	io_uring_prep_msg_ring_fd(sqe, dring.ring_fd, source_fd, target_fd,
-					USER_DATA, 0);
+	if (target_fd == IORING_FILE_INDEX_ALLOC) {
+		io_uring_prep_msg_ring_fd_alloc(sqe, dring.ring_fd, source_fd,
+						USER_DATA, 0);
+	} else {
+
+		io_uring_prep_msg_ring_fd(sqe, dring.ring_fd, source_fd,
+					  target_fd, USER_DATA, 0);
+	}
 	io_uring_submit(&sring);
 
 	ret = io_uring_wait_cqe(&sring, &cqe);
@@ -111,7 +125,7 @@ static int test(const char *filename, int source_fd, int target_fd)
 		fprintf(stderr, "wait cqe failed %d\n", ret);
 		return T_EXIT_FAIL;
 	}
-	if (cqe->res) {
+	if (cqe->res < 0) {
 		if (cqe->res == -EINVAL && !no_fd_pass) {
 			no_fd_pass = 1;
 			return T_EXIT_SKIP;
@@ -131,6 +145,17 @@ static int test(const char *filename, int source_fd, int target_fd)
 		fprintf(stderr, "bad user_data %ld\n", (long) cqe->res);
 		return T_EXIT_FAIL;
 	}
+	if (cqe->res < 0) {
+		fprintf(stderr, "bad result %i\n", cqe->res);
+		return T_EXIT_FAIL;
+	}
+	if (target_fd == IORING_FILE_INDEX_ALLOC) {
+		if (cqe->res != 1) {
+			fprintf(stderr, "invalid allocated index %i\n", cqe->res);
+			return T_EXIT_FAIL;
+		}
+		target_fd = cqe->res;
+	}
 	io_uring_cqe_seen(&dring, cqe);
 
 	/* now verify we can read the sane data from the destination ring */
@@ -201,6 +226,12 @@ int main(int argc, char *argv[])
 		ret = T_EXIT_FAIL;
 	}
 
+	ret = test(fname, 1, IORING_FILE_INDEX_ALLOC);
+	if (ret == T_EXIT_FAIL) {
+		fprintf(stderr, "test failed 1 ALLOC\n");
+		ret = T_EXIT_FAIL;
+	}
+
 	unlink(fname);
 	return ret;
 }
-- 
2.39.1


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

* Re: [PATCH liburing 1/2] Add io_uring_prep_msg_ring_fd_alloc() helper
  2023-03-16 13:09 ` [PATCH liburing 1/2] Add io_uring_prep_msg_ring_fd_alloc() helper Pavel Begunkov
@ 2023-03-16 15:01   ` Jens Axboe
  0 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2023-03-16 15:01 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring

On 3/16/23 7:09 AM, Pavel Begunkov wrote:
> Add a helper initialising msg-ring requests transferring files and
> allocating a target file index.

This needs an ffi map entry too, I added it.

-- 
Jens Axboe



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

* Re: [PATCH liburing for-next 0/2] fd msg-ring slot allocation tests
  2023-03-16 13:09 [PATCH liburing for-next 0/2] fd msg-ring slot allocation tests Pavel Begunkov
  2023-03-16 13:09 ` [PATCH liburing 1/2] Add io_uring_prep_msg_ring_fd_alloc() helper Pavel Begunkov
  2023-03-16 13:09 ` [PATCH liburing 2/2] test: test fd msg-ring allocating indexes Pavel Begunkov
@ 2023-03-16 15:02 ` Jens Axboe
  2 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2023-03-16 15:02 UTC (permalink / raw)
  To: io-uring, Pavel Begunkov


On Thu, 16 Mar 2023 13:09:19 +0000, Pavel Begunkov wrote:
> Add a helper for fd msg-ring passing a file and auto allocating the
> target index, and test it.
> 
> Pavel Begunkov (2):
>   Add io_uring_prep_msg_ring_fd_alloc() helper
>   test: test fd msg-ring allocating indexes
> 
> [...]

Applied, thanks!

[1/2] Add io_uring_prep_msg_ring_fd_alloc() helper
      commit: ab9113c58b43c33f305822739abd6084e02c8a63
[2/2] test: test fd msg-ring allocating indexes
      commit: ab9113c58b43c33f305822739abd6084e02c8a63

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2023-03-16 15:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-16 13:09 [PATCH liburing for-next 0/2] fd msg-ring slot allocation tests Pavel Begunkov
2023-03-16 13:09 ` [PATCH liburing 1/2] Add io_uring_prep_msg_ring_fd_alloc() helper Pavel Begunkov
2023-03-16 15:01   ` Jens Axboe
2023-03-16 13:09 ` [PATCH liburing 2/2] test: test fd msg-ring allocating indexes Pavel Begunkov
2023-03-16 15:02 ` [PATCH liburing for-next 0/2] fd msg-ring slot allocation tests 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).