* [PATCH liburing v2 1/5] update io_uring.h with file slot alloc ranges
2022-06-30 14:10 [PATCH liburing v2 0/5] ranged file slot alloc Pavel Begunkov
@ 2022-06-30 14:10 ` Pavel Begunkov
2022-06-30 14:10 ` [PATCH liburing v2 2/5] alloc range helpers Pavel Begunkov
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Pavel Begunkov @ 2022-06-30 14:10 UTC (permalink / raw)
To: io-uring; +Cc: Jens Axboe, asml.silence
Signed-off-by: Pavel Begunkov <[email protected]>
---
src/include/liburing/io_uring.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h
index 0fd1f98..c01c5a3 100644
--- a/src/include/liburing/io_uring.h
+++ b/src/include/liburing/io_uring.h
@@ -414,6 +414,9 @@ enum {
/* sync cancelation API */
IORING_REGISTER_SYNC_CANCEL = 24,
+ /* register a range of fixed file slots for automatic slot allocation */
+ IORING_REGISTER_FILE_ALLOC_RANGE = 25,
+
/* this goes last */
IORING_REGISTER_LAST
};
@@ -558,6 +561,13 @@ struct io_uring_getevents_arg {
__u64 ts;
};
+struct io_uring_file_index_range {
+ /* [off, off + len) */
+ __u32 off;
+ __u32 len;
+ __u64 resv;
+};
+
/*
* accept flags stored in sqe->ioprio
*/
--
2.36.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH liburing v2 2/5] alloc range helpers
2022-06-30 14:10 [PATCH liburing v2 0/5] ranged file slot alloc Pavel Begunkov
2022-06-30 14:10 ` [PATCH liburing v2 1/5] update io_uring.h with file slot alloc ranges Pavel Begunkov
@ 2022-06-30 14:10 ` Pavel Begunkov
2022-06-30 14:10 ` [PATCH liburing v2 3/5] file-register: fix return codes Pavel Begunkov
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Pavel Begunkov @ 2022-06-30 14:10 UTC (permalink / raw)
To: io-uring; +Cc: Jens Axboe, asml.silence
Signed-off-by: Pavel Begunkov <[email protected]>
---
src/include/liburing.h | 3 +++
src/liburing.map | 1 +
src/register.c | 14 ++++++++++++++
3 files changed, 18 insertions(+)
diff --git a/src/include/liburing.h b/src/include/liburing.h
index bb2fb87..45b4da0 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -186,6 +186,9 @@ int io_uring_unregister_buf_ring(struct io_uring *ring, int bgid);
int io_uring_register_sync_cancel(struct io_uring *ring,
struct io_uring_sync_cancel_reg *reg);
+int io_uring_register_file_alloc_range(struct io_uring *ring,
+ unsigned off, unsigned len);
+
/*
* Helper for the peek/wait single cqe functions. Exported because of that,
* but probably shouldn't be used directly in an application.
diff --git a/src/liburing.map b/src/liburing.map
index a487865..318d3d7 100644
--- a/src/liburing.map
+++ b/src/liburing.map
@@ -59,4 +59,5 @@ LIBURING_2.2 {
LIBURING_2.3 {
global:
io_uring_register_sync_cancel;
+ io_uring_register_file_alloc_range;
} LIBURING_2.2;
diff --git a/src/register.c b/src/register.c
index f2b1026..ee370d6 100644
--- a/src/register.c
+++ b/src/register.c
@@ -352,3 +352,17 @@ int io_uring_register_sync_cancel(struct io_uring *ring,
return ____sys_io_uring_register(ring->ring_fd,
IORING_REGISTER_SYNC_CANCEL, reg, 1);
}
+
+int io_uring_register_file_alloc_range(struct io_uring *ring,
+ unsigned off, unsigned len)
+{
+ struct io_uring_file_index_range range;
+
+ memset(&range, 0, sizeof(range));
+ range.off = off;
+ range.len = len;
+
+ return ____sys_io_uring_register(ring->ring_fd,
+ IORING_REGISTER_FILE_ALLOC_RANGE,
+ &range, 0);
+}
--
2.36.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH liburing v2 3/5] file-register: fix return codes
2022-06-30 14:10 [PATCH liburing v2 0/5] ranged file slot alloc Pavel Begunkov
2022-06-30 14:10 ` [PATCH liburing v2 1/5] update io_uring.h with file slot alloc ranges Pavel Begunkov
2022-06-30 14:10 ` [PATCH liburing v2 2/5] alloc range helpers Pavel Begunkov
@ 2022-06-30 14:10 ` Pavel Begunkov
2022-06-30 14:10 ` [PATCH liburing v2 4/5] tests: print file-register errors to stderr Pavel Begunkov
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Pavel Begunkov @ 2022-06-30 14:10 UTC (permalink / raw)
To: io-uring; +Cc: Jens Axboe, asml.silence
Use T_EXIT* in file-register.c
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/file-register.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/test/file-register.c b/test/file-register.c
index cd00a90..6a9cbb1 100644
--- a/test/file-register.c
+++ b/test/file-register.c
@@ -847,25 +847,25 @@ int main(int argc, char *argv[])
ret = test_basic(&ring, 0);
if (ret) {
printf("test_basic failed\n");
- return ret;
+ return T_EXIT_FAIL;
}
ret = test_basic(&ring, 1);
if (ret) {
printf("test_basic failed\n");
- return ret;
+ return T_EXIT_FAIL;
}
ret = test_basic_many(&ring);
if (ret) {
printf("test_basic_many failed\n");
- return ret;
+ return T_EXIT_FAIL;
}
ret = test_sparse(&ring);
if (ret) {
printf("test_sparse failed\n");
- return ret;
+ return T_EXIT_FAIL;
}
if (no_update)
@@ -874,49 +874,49 @@ int main(int argc, char *argv[])
ret = test_additions(&ring);
if (ret) {
printf("test_additions failed\n");
- return ret;
+ return T_EXIT_FAIL;
}
ret = test_removals(&ring);
if (ret) {
printf("test_removals failed\n");
- return ret;
+ return T_EXIT_FAIL;
}
ret = test_replace(&ring);
if (ret) {
printf("test_replace failed\n");
- return ret;
+ return T_EXIT_FAIL;
}
ret = test_replace_all(&ring);
if (ret) {
printf("test_replace_all failed\n");
- return ret;
+ return T_EXIT_FAIL;
}
ret = test_grow(&ring);
if (ret) {
printf("test_grow failed\n");
- return ret;
+ return T_EXIT_FAIL;
}
ret = test_shrink(&ring);
if (ret) {
printf("test_shrink failed\n");
- return ret;
+ return T_EXIT_FAIL;
}
ret = test_zero(&ring);
if (ret) {
printf("test_zero failed\n");
- return ret;
+ return T_EXIT_FAIL;
}
ret = test_huge(&ring);
if (ret) {
printf("test_huge failed\n");
- return ret;
+ return T_EXIT_FAIL;
}
ret = test_skip(&ring);
@@ -928,7 +928,7 @@ int main(int argc, char *argv[])
ret = test_sparse_updates();
if (ret) {
printf("test_sparse_updates failed\n");
- return ret;
+ return T_EXIT_FAIL;
}
ret = test_fixed_removal_ordering();
@@ -946,7 +946,7 @@ int main(int argc, char *argv[])
ret = test_partial_register_fail();
if (ret) {
printf("test_partial_register_fail failed\n");
- return ret;
+ return T_EXIT_FAIL;
}
return T_EXIT_PASS;
--
2.36.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH liburing v2 4/5] tests: print file-register errors to stderr
2022-06-30 14:10 [PATCH liburing v2 0/5] ranged file slot alloc Pavel Begunkov
` (2 preceding siblings ...)
2022-06-30 14:10 ` [PATCH liburing v2 3/5] file-register: fix return codes Pavel Begunkov
@ 2022-06-30 14:10 ` Pavel Begunkov
2022-06-30 14:10 ` [PATCH liburing v2 5/5] test range file alloc Pavel Begunkov
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Pavel Begunkov @ 2022-06-30 14:10 UTC (permalink / raw)
To: io-uring; +Cc: Jens Axboe, asml.silence
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/file-register.c | 36 ++++++++++++++++++------------------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/test/file-register.c b/test/file-register.c
index 6a9cbb1..4004a81 100644
--- a/test/file-register.c
+++ b/test/file-register.c
@@ -840,31 +840,31 @@ int main(int argc, char *argv[])
ret = io_uring_queue_init(8, &ring, 0);
if (ret) {
- printf("ring setup failed\n");
+ fprintf(stderr, "ring setup failed\n");
return T_EXIT_FAIL;
}
ret = test_basic(&ring, 0);
if (ret) {
- printf("test_basic failed\n");
+ fprintf(stderr, "test_basic failed\n");
return T_EXIT_FAIL;
}
ret = test_basic(&ring, 1);
if (ret) {
- printf("test_basic failed\n");
+ fprintf(stderr, "test_basic failed\n");
return T_EXIT_FAIL;
}
ret = test_basic_many(&ring);
if (ret) {
- printf("test_basic_many failed\n");
+ fprintf(stderr, "test_basic_many failed\n");
return T_EXIT_FAIL;
}
ret = test_sparse(&ring);
if (ret) {
- printf("test_sparse failed\n");
+ fprintf(stderr, "test_sparse failed\n");
return T_EXIT_FAIL;
}
@@ -873,79 +873,79 @@ int main(int argc, char *argv[])
ret = test_additions(&ring);
if (ret) {
- printf("test_additions failed\n");
+ fprintf(stderr, "test_additions failed\n");
return T_EXIT_FAIL;
}
ret = test_removals(&ring);
if (ret) {
- printf("test_removals failed\n");
+ fprintf(stderr, "test_removals failed\n");
return T_EXIT_FAIL;
}
ret = test_replace(&ring);
if (ret) {
- printf("test_replace failed\n");
+ fprintf(stderr, "test_replace failed\n");
return T_EXIT_FAIL;
}
ret = test_replace_all(&ring);
if (ret) {
- printf("test_replace_all failed\n");
+ fprintf(stderr, "test_replace_all failed\n");
return T_EXIT_FAIL;
}
ret = test_grow(&ring);
if (ret) {
- printf("test_grow failed\n");
+ fprintf(stderr, "test_grow failed\n");
return T_EXIT_FAIL;
}
ret = test_shrink(&ring);
if (ret) {
- printf("test_shrink failed\n");
+ fprintf(stderr, "test_shrink failed\n");
return T_EXIT_FAIL;
}
ret = test_zero(&ring);
if (ret) {
- printf("test_zero failed\n");
+ fprintf(stderr, "test_zero failed\n");
return T_EXIT_FAIL;
}
ret = test_huge(&ring);
if (ret) {
- printf("test_huge failed\n");
+ fprintf(stderr, "test_huge failed\n");
return T_EXIT_FAIL;
}
ret = test_skip(&ring);
if (ret) {
- printf("test_skip failed\n");
+ fprintf(stderr, "test_skip failed\n");
return T_EXIT_FAIL;
}
ret = test_sparse_updates();
if (ret) {
- printf("test_sparse_updates failed\n");
+ fprintf(stderr, "test_sparse_updates failed\n");
return T_EXIT_FAIL;
}
ret = test_fixed_removal_ordering();
if (ret) {
- printf("test_fixed_removal_ordering failed\n");
+ fprintf(stderr, "test_fixed_removal_ordering failed\n");
return T_EXIT_FAIL;
}
ret = test_mixed_af_unix();
if (ret) {
- printf("test_mixed_af_unix failed\n");
+ fprintf(stderr, "test_mixed_af_unix failed\n");
return T_EXIT_FAIL;
}
ret = test_partial_register_fail();
if (ret) {
- printf("test_partial_register_fail failed\n");
+ fprintf(stderr, "test_partial_register_fail failed\n");
return T_EXIT_FAIL;
}
--
2.36.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH liburing v2 5/5] test range file alloc
2022-06-30 14:10 [PATCH liburing v2 0/5] ranged file slot alloc Pavel Begunkov
` (3 preceding siblings ...)
2022-06-30 14:10 ` [PATCH liburing v2 4/5] tests: print file-register errors to stderr Pavel Begunkov
@ 2022-06-30 14:10 ` Pavel Begunkov
2022-06-30 14:59 ` [PATCH liburing v2 0/5] ranged file slot alloc Jens Axboe
2022-06-30 16:47 ` Jens Axboe
6 siblings, 0 replies; 8+ messages in thread
From: Pavel Begunkov @ 2022-06-30 14:10 UTC (permalink / raw)
To: io-uring; +Cc: Jens Axboe, asml.silence
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/file-register.c | 171 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 171 insertions(+)
diff --git a/test/file-register.c b/test/file-register.c
index 4004a81..e713233 100644
--- a/test/file-register.c
+++ b/test/file-register.c
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
+#include <limits.h>
#include <sys/resource.h>
#include "helpers.h"
@@ -830,6 +831,170 @@ static int test_partial_register_fail(void)
return 0;
}
+static int file_update_alloc(struct io_uring *ring, int *fd)
+{
+ struct io_uring_sqe *sqe;
+ struct io_uring_cqe *cqe;
+ int ret;
+
+ sqe = io_uring_get_sqe(ring);
+ io_uring_prep_files_update(sqe, fd, 1, IORING_FILE_INDEX_ALLOC);
+
+ ret = io_uring_submit(ring);
+ if (ret != 1) {
+ fprintf(stderr, "%s: got %d, wanted 1\n", __FUNCTION__, ret);
+ return -1;
+ }
+
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret < 0) {
+ fprintf(stderr, "%s: io_uring_wait_cqe=%d\n", __FUNCTION__, ret);
+ return -1;
+ }
+ ret = cqe->res;
+ io_uring_cqe_seen(ring, cqe);
+ return ret;
+}
+
+static int test_out_of_range_file_ranges(struct io_uring *ring)
+{
+ int ret;
+
+ ret = io_uring_register_file_alloc_range(ring, 8, 3);
+ if (ret != -EINVAL) {
+ fprintf(stderr, "overlapping range %i\n", ret);
+ return 1;
+ }
+
+ ret = io_uring_register_file_alloc_range(ring, 10, 1);
+ if (ret != -EINVAL) {
+ fprintf(stderr, "out of range index %i\n", ret);
+ return 1;
+ }
+
+ ret = io_uring_register_file_alloc_range(ring, 7, ~1U);
+ if (ret != -EOVERFLOW) {
+ fprintf(stderr, "overflow %i\n", ret);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int test_overallocating_file_range(struct io_uring *ring, int fds[2])
+{
+ int roff = 7, rlen = 2;
+ int ret, i, fd;
+
+ ret = io_uring_register_file_alloc_range(ring, roff, rlen);
+ if (ret) {
+ fprintf(stderr, "io_uring_register_file_alloc_range %i\n", ret);
+ return 1;
+ }
+
+ for (i = 0; i < rlen; i++) {
+ fd = fds[0];
+ ret = file_update_alloc(ring, &fd);
+ if (ret != 1) {
+ fprintf(stderr, "file_update_alloc\n");
+ return 1;
+ }
+
+ if (fd < roff || fd >= roff + rlen) {
+ fprintf(stderr, "invalid off result %i\n", fd);
+ return 1;
+ }
+ }
+
+ fd = fds[0];
+ ret = file_update_alloc(ring, &fd);
+ if (ret != -ENFILE) {
+ fprintf(stderr, "overallocated %i, off %i\n", ret, fd);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int test_zero_range_alloc(struct io_uring *ring, int fds[2])
+{
+ int ret, fd;
+
+ ret = io_uring_register_file_alloc_range(ring, 7, 0);
+ if (ret) {
+ fprintf(stderr, "io_uring_register_file_alloc_range failed %i\n", ret);
+ return 1;
+ }
+
+ fd = fds[0];
+ ret = file_update_alloc(ring, &fd);
+ if (ret != -ENFILE) {
+ fprintf(stderr, "zero alloc %i\n", ret);
+ return 1;
+ }
+ return 0;
+}
+
+static int test_file_alloc_ranges(void)
+{
+ struct io_uring ring;
+ int ret, pipe_fds[2];
+
+ if (pipe(pipe_fds)) {
+ fprintf(stderr, "pipes\n");
+ return 1;
+ }
+ ret = io_uring_queue_init(8, &ring, 0);
+ if (ret) {
+ fprintf(stderr, "queue_init: %d\n", ret);
+ return 1;
+ }
+
+ ret = io_uring_register_files_sparse(&ring, 10);
+ if (ret == -EINVAL) {
+not_supported:
+ close(pipe_fds[0]);
+ close(pipe_fds[1]);
+ io_uring_queue_exit(&ring);
+ printf("file alloc ranges are not supported, skip\n");
+ return 0;
+ } else if (ret) {
+ fprintf(stderr, "io_uring_register_files_sparse %i\n", ret);
+ return ret;
+ }
+
+ ret = io_uring_register_file_alloc_range(&ring, 0, 1);
+ if (ret) {
+ if (ret == -EINVAL)
+ goto not_supported;
+ fprintf(stderr, "io_uring_register_file_alloc_range %i\n", ret);
+ return 1;
+ }
+
+ ret = test_overallocating_file_range(&ring, pipe_fds);
+ if (ret) {
+ fprintf(stderr, "test_overallocating_file_range() failed\n");
+ return 1;
+ }
+
+ ret = test_out_of_range_file_ranges(&ring);
+ if (ret) {
+ fprintf(stderr, "test_out_of_range_file_ranges() failed\n");
+ return 1;
+ }
+
+ ret = test_zero_range_alloc(&ring, pipe_fds);
+ if (ret) {
+ fprintf(stderr, "test_zero_range_alloc() failed\n");
+ return 1;
+ }
+
+ close(pipe_fds[0]);
+ close(pipe_fds[1]);
+ io_uring_queue_exit(&ring);
+ return 0;
+}
+
int main(int argc, char *argv[])
{
struct io_uring ring;
@@ -949,5 +1114,11 @@ int main(int argc, char *argv[])
return T_EXIT_FAIL;
}
+ ret = test_file_alloc_ranges();
+ if (ret) {
+ fprintf(stderr, "test_partial_register_fail failed\n");
+ return T_EXIT_FAIL;
+ }
+
return T_EXIT_PASS;
}
--
2.36.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH liburing v2 0/5] ranged file slot alloc
2022-06-30 14:10 [PATCH liburing v2 0/5] ranged file slot alloc Pavel Begunkov
` (4 preceding siblings ...)
2022-06-30 14:10 ` [PATCH liburing v2 5/5] test range file alloc Pavel Begunkov
@ 2022-06-30 14:59 ` Jens Axboe
2022-06-30 16:47 ` Jens Axboe
6 siblings, 0 replies; 8+ messages in thread
From: Jens Axboe @ 2022-06-30 14:59 UTC (permalink / raw)
To: Pavel Begunkov, io-uring
On 6/30/22 8:10 AM, Pavel Begunkov wrote:
> Add helpers and test ranged file slot allocation feature
>
> Pavel Begunkov (5):
> update io_uring.h with file slot alloc ranges
> alloc range helpers
> file-register: fix return codes
> tests: print file-register errors to stderr
> test range file alloc
>
> src/include/liburing.h | 3 +
> src/include/liburing/io_uring.h | 10 ++
> src/liburing.map | 1 +
> src/register.c | 14 ++
> test/file-register.c | 235 +++++++++++++++++++++++++++-----
> 5 files changed, 231 insertions(+), 32 deletions(-)
Looks fine to me, but also needs a man page addition... Trying to do
better here going forward so I don't have to spend days before a
release checking what hasn't been documented, and then also write
everything myself.
I can apply this one as-is, but please do send a man page patch as
well.
--
Jens Axboe
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH liburing v2 0/5] ranged file slot alloc
2022-06-30 14:10 [PATCH liburing v2 0/5] ranged file slot alloc Pavel Begunkov
` (5 preceding siblings ...)
2022-06-30 14:59 ` [PATCH liburing v2 0/5] ranged file slot alloc Jens Axboe
@ 2022-06-30 16:47 ` Jens Axboe
6 siblings, 0 replies; 8+ messages in thread
From: Jens Axboe @ 2022-06-30 16:47 UTC (permalink / raw)
To: io-uring, asml.silence
On Thu, 30 Jun 2022 15:10:12 +0100, Pavel Begunkov wrote:
> Add helpers and test ranged file slot allocation feature
>
> Pavel Begunkov (5):
> update io_uring.h with file slot alloc ranges
> alloc range helpers
> file-register: fix return codes
> tests: print file-register errors to stderr
> test range file alloc
>
> [...]
Applied, thanks!
[1/5] update io_uring.h with file slot alloc ranges
commit: 98626db560568fc6f572f829930798f48d226f63
[2/5] alloc range helpers
commit: 161c6a65bd079872fb938665d15802d0e62a9cc9
[3/5] file-register: fix return codes
commit: 52c3bea1ce9926e656b84fb050b61a57f0c3cac8
[4/5] tests: print file-register errors to stderr
commit: c60c80b99f2f425423a7e57a97e359d295b8851c
[5/5] test range file alloc
commit: 5829a98f5f5338502572392de4ac60e0865a44ac
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 8+ messages in thread