io_uring: allow allocated fixed files for accept fastpoll-mshot
authorJens Axboe <axboe@kernel.dk>
Sat, 7 May 2022 16:08:31 +0000 (10:08 -0600)
committerJens Axboe <axboe@kernel.dk>
Mon, 9 May 2022 12:29:53 +0000 (06:29 -0600)
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 <axboe@kernel.dk>
fs/io_uring.c

index 5faff07a109bcab2e1af6c77f393e6ddd0ba3c97..a0ad67bcfe9834400440f32ee5df9054b84653c4 100644 (file)
@@ -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)) {