From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH liburing] register: add tagging and buf update helpers
Date: Fri, 27 Aug 2021 19:46:03 +0100 [thread overview]
Message-ID: <f4f19901c6f925e103dea32be252763ba8a4d2d3.1630089830.git.asml.silence@gmail.com> (raw)
Add heplers for rsrc (buffers, files) updates and registration with
tags.
Signed-off-by: Pavel Begunkov <[email protected]>
---
tested by:
1) using with rsrc_tags test
2) expressing previous helpers with new ones + tags=NULL
src/include/liburing.h | 20 ++++++++++++
src/register.c | 72 ++++++++++++++++++++++++++++++++++++++++++
test/rsrc_tags.c | 8 +++++
3 files changed, 100 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/register.c b/src/register.c
index 994aaff..b29011a 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,
+ ®, 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,24 @@ 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;
+ int ret;
+
+ memset(®, 0, sizeof(reg));
+ reg.nr = nr;
+ reg.data = (unsigned long)files;
+ reg.tags = (unsigned long)tags;
+
+ ret = __sys_io_uring_register(ring->ring_fd, IORING_REGISTER_FILES2,
+ ®, 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
next reply other threads:[~2021-08-27 18:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-27 18:46 Pavel Begunkov [this message]
2021-08-27 18:48 ` [PATCH liburing] register: add tagging and buf update helpers Jens Axboe
2021-08-27 18:51 ` Pavel Begunkov
2021-08-27 18:52 ` Pavel Begunkov
2021-08-27 19:14 ` Jens Axboe
2021-08-27 19:35 ` Pavel Begunkov
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=f4f19901c6f925e103dea32be252763ba8a4d2d3.1630089830.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