From: Jens Axboe Date: Sat, 7 May 2022 16:08:31 +0000 (-0600) Subject: io_uring: allow allocated fixed files for accept X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=refs%2Fheads%2Ffastpoll-mshot;p=linux-2.6-block.git io_uring: allow allocated fixed files for accept If the applications passes in UINT_MAX as the file_slot, then that's a hint to allocate a fixed file descriptor rather than have one be passed in directly. This can be useful for having io_uring manage the direct descriptor space, and also allows multi-shot support to work with fixed files. Normal accept direct requests will complete with 0 for success, and < 0 in case of error. If io_uring is asked to allocated the direct descriptor, then the direct descriptor is returned in case of success. Signed-off-by: Jens Axboe --- diff --git a/fs/io_uring.c b/fs/io_uring.c index 5faff07a109b..a0ad67bcfe98 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -5772,9 +5772,13 @@ static int io_accept_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) return -EINVAL; accept->file_slot = READ_ONCE(sqe->file_index); - if (accept->file_slot && ((accept->flags & SOCK_CLOEXEC) || - flags & IORING_ACCEPT_MULTISHOT)) - return -EINVAL; + if (accept->file_slot) { + if (accept->flags & SOCK_CLOEXEC) + return -EINVAL; + if (accept->file_slot != UINT_MAX && + req->flags & IORING_ACCEPT_MULTISHOT) + return -EINVAL; + } if (accept->flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)) return -EINVAL; if (SOCK_NONBLOCK != O_NONBLOCK && (accept->flags & SOCK_NONBLOCK)) @@ -5838,8 +5842,8 @@ retry: fd_install(fd, file); ret = fd; } else { - ret = io_install_fixed_file(req, file, issue_flags, - accept->file_slot - 1); + ret = io_fixed_file_install(req, issue_flags, file, + accept->file_slot); } if (!(req->flags & REQ_F_APOLL_MULTISHOT)) {