io_uring: allow O_NONBLOCK async retry
authorJens Axboe <axboe@kernel.dk>
Wed, 10 Jun 2020 01:23:05 +0000 (19:23 -0600)
committerJens Axboe <axboe@kernel.dk>
Wed, 10 Jun 2020 01:38:24 +0000 (19:38 -0600)
We can assume that O_NONBLOCK is always honored, even if we don't
have a ->read/write_iter() for the file type. Also unify the read/write
checking for allowing async punt, having the write side factoring in the
REQ_F_NOWAIT flag as well.

Cc: stable@vger.kernel.org
Fixes: 490e89676a52 ("io_uring: only force async punt if poll based retry can't handle it")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/io_uring.c

index 3ffe03194c1ea572a85b2dbae20d4b7bc959a89b..ebea82e0996393b81eb5757f05e9f48f53fada2b 100644 (file)
@@ -2061,6 +2061,10 @@ static bool io_file_supports_async(struct file *file, int rw)
        if (S_ISREG(mode) && file->f_op != &io_uring_fops)
                return true;
 
+       /* any ->read/write should understand O_NONBLOCK */
+       if (file->f_flags & O_NONBLOCK)
+               return true;
+
        if (!(file->f_mode & FMODE_NOWAIT))
                return false;
 
@@ -2103,8 +2107,7 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                kiocb->ki_ioprio = get_current_ioprio();
 
        /* don't allow async punt if RWF_NOWAIT was requested */
-       if ((kiocb->ki_flags & IOCB_NOWAIT) ||
-           (req->file->f_flags & O_NONBLOCK))
+       if (kiocb->ki_flags & IOCB_NOWAIT)
                req->flags |= REQ_F_NOWAIT;
 
        if (force_nonblock)
@@ -2745,7 +2748,8 @@ copy_iov:
                        if (ret)
                                goto out_free;
                        /* any defer here is final, must blocking retry */
-                       if (!file_can_poll(req->file))
+                       if (!(req->flags & REQ_F_NOWAIT) &&
+                           !file_can_poll(req->file))
                                req->flags |= REQ_F_MUST_PUNT;
                        return -EAGAIN;
                }