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 v2] register: add tagging and buf update helpers
Date: Fri, 27 Aug 2021 20:32:14 +0100	[thread overview]
Message-ID: <314323bcd6d053f063181d5b900f6d8f6fb3ce6a.1630092701.git.asml.silence@gmail.com> (raw)

Add heplers for rsrc (buffers, files) updates and registration with
tags.

Signed-off-by: Pavel Begunkov <[email protected]>
---

v2: update liburing.map

 src/include/liburing.h | 20 ++++++++++++
 src/liburing.map       |  4 +++
 src/register.c         | 71 ++++++++++++++++++++++++++++++++++++++++++
 test/rsrc_tags.c       |  8 +++++
 4 files changed, 103 insertions(+)

diff --git a/src/include/liburing.h b/src/include/liburing.h
index 9b38d23..7b364ce 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -125,9 +125,29 @@ extern struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring);
 extern int io_uring_register_buffers(struct io_uring *ring,
 					const struct iovec *iovecs,
 					unsigned nr_iovecs);
+extern int io_uring_register_buffers_tags(struct io_uring *ring,
+					  const struct iovec *iovecs,
+					  const __u64 *tags,
+					  unsigned nr);
+extern int io_uring_register_buffers_update_tag(struct io_uring *ring,
+						unsigned off,
+						const struct iovec *iovecs,
+						const __u64 *tags,
+						unsigned nr);
 extern int io_uring_unregister_buffers(struct io_uring *ring);
+
 extern int io_uring_register_files(struct io_uring *ring, const int *files,
 					unsigned nr_files);
+extern int io_uring_register_files_tags(struct io_uring *ring,
+					const int *files,
+					const __u64 *tags,
+					unsigned nr);
+extern int io_uring_register_files_update_tag(struct io_uring *ring,
+					      unsigned off,
+					      const int *files,
+					      const __u64 *tags,
+					      unsigned nr_files);
+
 extern int io_uring_unregister_files(struct io_uring *ring);
 extern int io_uring_register_files_update(struct io_uring *ring, unsigned off,
 					int *files, unsigned nr_files);
diff --git a/src/liburing.map b/src/liburing.map
index 012ac4e..b29aa5f 100644
--- a/src/liburing.map
+++ b/src/liburing.map
@@ -36,4 +36,8 @@ LIBURING_2.1 {
 	global:
 		io_uring_mlock_size_params;
 		io_uring_mlock_size;
+		io_uring_register_buffers_tags;
+		io_uring_register_buffers_update_tag;
+		io_uring_register_files_tags;
+		io_uring_register_files_update_tag;
 } LIBURING_2.0;
diff --git a/src/register.c b/src/register.c
index 994aaff..a947aec 100644
--- a/src/register.c
+++ b/src/register.c
@@ -14,6 +14,42 @@
 
 #include "syscall.h"
 
+int io_uring_register_buffers_update_tag(struct io_uring *ring, unsigned off,
+					 const struct iovec *iovecs,
+					 const __u64 *tags,
+					 unsigned nr)
+{
+	struct io_uring_rsrc_update2 up = {
+		.offset	= off,
+		.data = (unsigned long)iovecs,
+		.tags = (unsigned long)tags,
+		.nr = nr,
+	};
+	int ret;
+
+	ret = __sys_io_uring_register(ring->ring_fd,
+				      IORING_REGISTER_BUFFERS_UPDATE,
+				      &up, sizeof(up));
+	return ret < 0 ? -errno : ret;
+}
+
+int io_uring_register_buffers_tags(struct io_uring *ring,
+				   const struct iovec *iovecs,
+				   const __u64 *tags,
+				   unsigned nr)
+{
+	struct io_uring_rsrc_register reg = {
+		.nr = nr,
+		.data = (unsigned long)iovecs,
+		.tags = (unsigned long)tags,
+	};
+	int ret;
+
+	ret = __sys_io_uring_register(ring->ring_fd, IORING_REGISTER_BUFFERS2,
+				      &reg, sizeof(reg));
+	return ret < 0 ? -errno : ret;
+}
+
 int io_uring_register_buffers(struct io_uring *ring, const struct iovec *iovecs,
 			      unsigned nr_iovecs)
 {
@@ -39,6 +75,24 @@ int io_uring_unregister_buffers(struct io_uring *ring)
 	return 0;
 }
 
+int io_uring_register_files_update_tag(struct io_uring *ring, unsigned off,
+					const int *files, const __u64 *tags,
+					unsigned nr_files)
+{
+	struct io_uring_rsrc_update2 up = {
+		.offset	= off,
+		.data = (unsigned long)files,
+		.tags = (unsigned long)tags,
+		.nr = nr_files,
+	};
+	int ret;
+
+	ret = __sys_io_uring_register(ring->ring_fd,
+					IORING_REGISTER_FILES_UPDATE2,
+					&up, sizeof(up));
+	return ret < 0 ? -errno : ret;
+}
+
 /*
  * Register an update for an existing file set. The updates will start at
  * 'off' in the original array, and 'nr_files' is the number of files we'll
@@ -64,6 +118,23 @@ int io_uring_register_files_update(struct io_uring *ring, unsigned off,
 	return ret;
 }
 
+
+int io_uring_register_files_tags(struct io_uring *ring,
+				 const int *files, const __u64 *tags,
+				 unsigned nr)
+{
+	struct io_uring_rsrc_register reg = {
+		.nr = nr,
+		.data = (unsigned long)files,
+		.tags = (unsigned long)tags,
+	};
+	int ret;
+
+	ret = __sys_io_uring_register(ring->ring_fd, IORING_REGISTER_FILES2,
+				      &reg, sizeof(reg));
+	return ret < 0 ? -errno : ret;
+}
+
 int io_uring_register_files(struct io_uring *ring, const int *files,
 			      unsigned nr_files)
 {
diff --git a/test/rsrc_tags.c b/test/rsrc_tags.c
index 337fbb8..57b47f7 100644
--- a/test/rsrc_tags.c
+++ b/test/rsrc_tags.c
@@ -32,6 +32,10 @@ static bool check_cq_empty(struct io_uring *ring)
 	return ret == -EAGAIN;
 }
 
+/*
+ * There are io_uring_register_buffers_tags() and other wrappers,
+ * but they may change, so hand-code to specifically test this ABI.
+ */
 static int register_rsrc(struct io_uring *ring, int type, int nr,
 			  const void *arg, const __u64 *tags)
 {
@@ -52,6 +56,10 @@ static int register_rsrc(struct io_uring *ring, int type, int nr,
 	return ret ? -errno : 0;
 }
 
+/*
+ * There are io_uring_register_buffers_update_tag() and other wrappers,
+ * but they may change, so hand-code to specifically test this ABI.
+ */
 static int update_rsrc(struct io_uring *ring, int type, int nr, int off,
 			const void *arg, const __u64 *tags)
 {
-- 
2.33.0


             reply	other threads:[~2021-08-27 19:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-27 19:32 Pavel Begunkov [this message]
2021-08-27 19:35 ` [PATCH liburing v2] register: add tagging and buf update 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=314323bcd6d053f063181d5b900f6d8f6fb3ce6a.1630092701.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