ranged file slot alloc
v2 cover ranged file slot alloc
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(-)
Signature · 1 line
2.36.1
PATCH v2 1/5 update io_uring.h with file slot alloc ranges
--- src/include/liburing/io_uring.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
src/include/liburing/io_uring.h +10 -0
@@ -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 */
Signature · 1 line
2.36.1
PATCH v2 2/5 alloc range helpers
In reply to Pavel Begunkov--- src/include/liburing.h | 3 +++ src/liburing.map | 1 + src/register.c | 14 ++++++++++++++ 3 files changed, 18 insertions(+)
src/include/liburing.h +3 -0
@@ -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.
src/liburing.map +1 -0
@@ -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;
src/register.c +14 -0
@@ -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 ); +}
Signature · 1 line
2.36.1
PATCH v2 3/5 file-register: fix return codes
In reply to Pavel BegunkovUse T_EXIT* in file-register.c
--- test/file-register.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
test/file-register.c +14 -14
@@ -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 ;
Signature · 1 line
2.36.1
PATCH v2 4/5 tests: print file-register errors to stderr
In reply to Pavel Begunkov--- test/file-register.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
test/file-register.c +18 -18
@@ -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 ; }
Signature · 1 line
2.36.1
PATCH v2 5/5 test range file alloc
In reply to Pavel Begunkov--- test/file-register.c | 171 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+)
test/file-register.c +171 -0
@@ -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 ; }
Signature · 1 line
2.36.1
Jens Axboe
maintainerQuoted 9 lines · Pavel Begunkov
Add helpers and test ranged file slot allocation feature
Pavel Begunkov (5):
updateio_uring.hwith file slot alloc ranges
alloc range helpers
file-register: fix return codes
tests: print file-register errors to stderr
test range file alloc
Quoted 6 lines
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.
Signature · 1 line
Jens Axboe
Quoted 10 lines · Pavel Begunkov
Add helpers and test ranged file slot allocation feature
Pavel Begunkov (5):
updateio_uring.hwith 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: 5829a98f5f5338502572392de4ac60e0865a44acBest regards,
Signature · 1 line
Jens Axboe