Jens Axboe <axboe@xxxxxxxxx> writes: > Currently we only support registrering a fixed file set. If changes need > to be made to that set, the application must unregister the existing set > first, then register a new one. > > This patchset adds support for sparse file sets (patch 1), which means > the application can register a fileset with room for expansion. This is > done through having unregistered slots use fd == -1. > > On top of that, we can add IORING_REGISTER_FILES_UPDATE. This allows > modifying the existing file set through: > > - Replacing empty slots with valid file descriptors > - Replacing valid descriptors with an empty slot > - Modifying an existing slot, replacing a file descriptor with a new one I don't pretend to understand the socket code you wrote. The io_uring bits look good to me. I also added a testcase to your file-register.c program--diff below. The test passes, of course. :) Reviewed-by: Jeff Moyer <jmoyer@xxxxxxxxxx> Cheers, Jeff diff --git a/test/file-register.c b/test/file-register.c index b25f0f5..322545f 100644 --- a/test/file-register.c +++ b/test/file-register.c @@ -358,6 +358,40 @@ err: return 1; } +/* + * Register 0 files, but reserve space for 10. Then add one file. + */ +static int test_zero(struct io_uring *ring) +{ + struct io_uring_files_update up; + int *files; + int ret; + + files = open_files(0, 10, 0); + ret = io_uring_register(ring->ring_fd, IORING_REGISTER_FILES, files, 10); + if (ret) + goto err; + + up.fds = open_files(1, 0, 1); + up.offset = 0; + ret = io_uring_register(ring->ring_fd, + IORING_REGISTER_FILES_UPDATE, &up, 1); + if (ret != 1) { + printf("ret=%d, errno=%d\n", ret, errno); + goto err; + } + + ret = io_uring_register(ring->ring_fd, IORING_UNREGISTER_FILES, NULL, 0); + if (ret) + goto err; + + close_files(up.fds, 1, 1); + return 0; +err: + close_files(up.fds, 1, 1); + return 1; +} + int main(int argc, char *argv[]) { struct io_uring ring; @@ -426,5 +460,11 @@ int main(int argc, char *argv[]) return ret; } + ret = test_zero(&ring); + if (ret) { + printf("test_zero failed\n"); + return ret; + } + return 0; }