Skip to content

Commit c081099

Browse files
axboeXiaoguang Wang
authored andcommitted
io_uring: allow O_NONBLOCK async retry
to #28736503 commit c5b8562 upstream 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: 490e896 ("io_uring: only force async punt if poll based retry can't handle it") Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com> Acked-by: Joseph Qi <joseph.qi@linux.alibaba.com>
1 parent c349b38 commit c081099

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
@@ -2052,6 +2052,10 @@ static bool io_file_supports_async(struct file *file, int rw)
20522052
if (S_ISREG(mode) && file->f_op != &io_uring_fops)
20532053
return true;
20542054

2055+
/* any ->read/write should understand O_NONBLOCK */
2056+
if (file->f_flags & O_NONBLOCK)
2057+
return true;
2058+
20552059
if (!(file->f_mode & FMODE_NOWAIT))
20562060
return false;
20572061

@@ -2094,8 +2098,7 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
20942098
kiocb->ki_ioprio = get_current_ioprio();
20952099

20962100
/* don't allow async punt if RWF_NOWAIT was requested */
2097-
if ((kiocb->ki_flags & IOCB_NOWAIT) ||
2098-
(req->file->f_flags & O_NONBLOCK))
2101+
if (kiocb->ki_flags & IOCB_NOWAIT)
20992102
req->flags |= REQ_F_NOWAIT;
21002103

21012104
if (force_nonblock)
@@ -2736,7 +2739,8 @@ static int io_write(struct io_kiocb *req, bool force_nonblock)
27362739
if (ret)
27372740
goto out_free;
27382741
/* any defer here is final, must blocking retry */
2739-
if (!file_can_poll(req->file))
2742+
if (!(req->flags & REQ_F_NOWAIT) &&
2743+
!file_can_poll(req->file))
27402744
req->flags |= REQ_F_MUST_PUNT;
27412745
return -EAGAIN;
27422746
}

0 commit comments

Comments
 (0)