summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2022-05-14 09:42:22 -0600
committerJens Axboe <axboe@kernel.dk>2022-05-14 09:43:06 -0600
commit15af89d0d906791639ac7950f4f12ed9f30341d3 (patch)
tree1acda664946d4107f7f6c3c8e5fd157956ebde75
parent846097febe8eedfbce550c584f023459d614fbf4 (diff)
downloadliburing-15af89d0d906791639ac7950f4f12ed9f30341d3.tar.gz
liburing-15af89d0d906791639ac7950f4f12ed9f30341d3.tar.bz2
Add sparse registration helper and kernel definition
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--man/io_uring_register_files.320
-rw-r--r--src/include/liburing.h1
-rw-r--r--src/include/liburing/io_uring.h6
-rw-r--r--src/liburing.map1
-rw-r--r--src/register.c25
5 files changed, 48 insertions, 5 deletions
diff --git a/man/io_uring_register_files.3 b/man/io_uring_register_files.3
index e2fed47..cf31460 100644
--- a/man/io_uring_register_files.3
+++ b/man/io_uring_register_files.3
@@ -13,10 +13,15 @@ io_uring_register_files - register file descriptors
.BI "int io_uring_register_files(struct io_uring *" ring ","
.BI " const int *" files ","
.BI " unsigned " nr_files ");"
+.BI
+.BI "int io_uring_register_files_sparse(struct io_uring *" ring ","
+.BI " unsigned " nr_files ");"
.PP
.SH DESCRIPTION
.PP
-The io_uring_register_files() function registers
+The
+.BR io_uring_register_files()
+function registers
.I nr_files
number of file descriptors defined by the array
.I files
@@ -24,12 +29,21 @@ belonging to the
.I ring
for subsequent operations.
-After the caller has registered the buffers, they can be used with the
-submission queue polling operations.
+The
+.BR io_uring_register_files_sparse()
+function registers an empty file table of
+.I nr_files
+number of file descriptors. The sparse variant is available in kernels 5.19
+and later.
+
+Registering a file table is a prerequisite for using any request that uses
+direct descriptors.
.SH RETURN VALUE
On success
.BR io_uring_register_files (3)
+and
+.BR io_uring_register_files_sparse (3)
returns 0. On failure it returns -errno.
.SH SEE ALSO
.BR io_uring_get_sqe (3), io_uring_unregister_files (3)
diff --git a/src/include/liburing.h b/src/include/liburing.h
index 5c03061..c220e90 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -151,6 +151,7 @@ int io_uring_register_files(struct io_uring *ring, const int *files,
unsigned nr_files);
int io_uring_register_files_tags(struct io_uring *ring, const int *files,
const __u64 *tags, unsigned nr);
+int io_uring_register_files_sparse(struct io_uring *ring, unsigned nr);
int io_uring_register_files_update_tag(struct io_uring *ring, unsigned off,
const int *files, const __u64 *tags,
unsigned nr_files);
diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h
index 3225d04..2541573 100644
--- a/src/include/liburing/io_uring.h
+++ b/src/include/liburing/io_uring.h
@@ -355,10 +355,12 @@ struct io_uring_files_update {
__aligned_u64 /* __s32 * */ fds;
};
+#define IORING_RSRC_REGISTER_SPARSE (1U << 0)
+
struct io_uring_rsrc_register {
__u32 nr;
- __u32 resv;
- __u64 resv2;
+ __u32 flags;
+ __u32 resv2;
__aligned_u64 data;
__aligned_u64 tags;
};
diff --git a/src/liburing.map b/src/liburing.map
index c83a15f..1e66849 100644
--- a/src/liburing.map
+++ b/src/liburing.map
@@ -50,4 +50,5 @@ LIBURING_2.2 {
io_uring_submit_and_wait_timeout;
io_uring_register_ring_fd;
io_uring_unregister_ring_fd;
+ io_uring_register_files_sparse;
} LIBURING_2.1;
diff --git a/src/register.c b/src/register.c
index 8cdc332..dde2038 100644
--- a/src/register.c
+++ b/src/register.c
@@ -113,6 +113,31 @@ static int increase_rlimit_nofile(unsigned nr)
return 0;
}
+int io_uring_register_files_sparse(struct io_uring *ring, unsigned nr)
+{
+ struct io_uring_rsrc_register reg = {
+ .flags = IORING_RSRC_REGISTER_SPARSE,
+ .nr = nr,
+ };
+ int ret, did_increase = 0;
+
+ do {
+ ret = ____sys_io_uring_register(ring->ring_fd,
+ IORING_REGISTER_FILES2, &reg,
+ sizeof(reg));
+ if (ret >= 0)
+ break;
+ if (ret == -EMFILE && !did_increase) {
+ did_increase = 1;
+ increase_rlimit_nofile(nr);
+ continue;
+ }
+ break;
+ } while (1);
+
+ return ret;
+}
+
int io_uring_register_files_tags(struct io_uring *ring, const int *files,
const __u64 *tags, unsigned nr)
{