Skip to content

Commit c5b8562

Browse files
committed
io_uring: allow O_NONBLOCK async retry
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: [email protected] Fixes: 490e896 ("io_uring: only force async punt if poll based retry can't handle it") Signed-off-by: Jens Axboe <[email protected]>
1 parent f5fa38c commit c5b8562

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

fs/io_uring.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,10 @@ static bool io_file_supports_async(struct file *file, int rw)
20612061
if (S_ISREG(mode) && file->f_op != &io_uring_fops)
20622062
return true;
20632063

2064+
/* any ->read/write should understand O_NONBLOCK */
2065+
if (file->f_flags & O_NONBLOCK)
2066+
return true;
2067+
20642068
if (!(file->f_mode & FMODE_NOWAIT))
20652069
return false;
20662070

@@ -2103,8 +2107,7 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
21032107
kiocb->ki_ioprio = get_current_ioprio();
21042108

21052109
/* don't allow async punt if RWF_NOWAIT was requested */
2106-
if ((kiocb->ki_flags & IOCB_NOWAIT) ||
2107-
(req->file->f_flags & O_NONBLOCK))
2110+
if (kiocb->ki_flags & IOCB_NOWAIT)
21082111
req->flags |= REQ_F_NOWAIT;
21092112

21102113
if (force_nonblock)
@@ -2745,7 +2748,8 @@ static int io_write(struct io_kiocb *req, bool force_nonblock)
27452748
if (ret)
27462749
goto out_free;
27472750
/* any defer here is final, must blocking retry */
2748-
if (!file_can_poll(req->file))
2751+
if (!(req->flags & REQ_F_NOWAIT) &&
2752+
!file_can_poll(req->file))
27492753
req->flags |= REQ_F_MUST_PUNT;
27502754
return -EAGAIN;
27512755
}

0 commit comments

Comments
 (0)