Skip to content

Commit af197f5

Browse files
committed
io_uring: enable poll retry for any file with ->read_iter / ->write_iter
We can have files like eventfd where it's perfectly fine to do poll based retry on them, right now io_file_supports_async() doesn't take that into account. Pass in data direction and check the f_op instead of just always needing an async worker. Signed-off-by: Jens Axboe <[email protected]>
1 parent 5b0bbee commit af197f5

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

fs/io_uring.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,7 @@ static struct file *__io_file_get(struct io_submit_state *state, int fd)
20382038
* any file. For now, just ensure that anything potentially problematic is done
20392039
* inline.
20402040
*/
2041-
static bool io_file_supports_async(struct file *file)
2041+
static bool io_file_supports_async(struct file *file, int rw)
20422042
{
20432043
umode_t mode = file_inode(file)->i_mode;
20442044

@@ -2047,7 +2047,13 @@ static bool io_file_supports_async(struct file *file)
20472047
if (S_ISREG(mode) && file->f_op != &io_uring_fops)
20482048
return true;
20492049

2050-
return false;
2050+
if (!(file->f_mode & FMODE_NOWAIT))
2051+
return false;
2052+
2053+
if (rw == READ)
2054+
return file->f_op->read_iter != NULL;
2055+
2056+
return file->f_op->write_iter != NULL;
20512057
}
20522058

20532059
static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
@@ -2575,7 +2581,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock)
25752581
* If the file doesn't support async, mark it as REQ_F_MUST_PUNT so
25762582
* we know to async punt it even if it was opened O_NONBLOCK
25772583
*/
2578-
if (force_nonblock && !io_file_supports_async(req->file))
2584+
if (force_nonblock && !io_file_supports_async(req->file, READ))
25792585
goto copy_iov;
25802586

25812587
iov_count = iov_iter_count(&iter);
@@ -2666,7 +2672,7 @@ static int io_write(struct io_kiocb *req, bool force_nonblock)
26662672
* If the file doesn't support async, mark it as REQ_F_MUST_PUNT so
26672673
* we know to async punt it even if it was opened O_NONBLOCK
26682674
*/
2669-
if (force_nonblock && !io_file_supports_async(req->file))
2675+
if (force_nonblock && !io_file_supports_async(req->file, WRITE))
26702676
goto copy_iov;
26712677

26722678
/* file path doesn't support NOWAIT for non-direct_IO */
@@ -2760,11 +2766,11 @@ static int io_splice_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
27602766
return 0;
27612767
}
27622768

2763-
static bool io_splice_punt(struct file *file)
2769+
static bool io_splice_punt(struct file *file, int rw)
27642770
{
27652771
if (get_pipe_info(file))
27662772
return false;
2767-
if (!io_file_supports_async(file))
2773+
if (!io_file_supports_async(file, rw))
27682774
return true;
27692775
return !(file->f_flags & O_NONBLOCK);
27702776
}
@@ -2779,7 +2785,7 @@ static int io_splice(struct io_kiocb *req, bool force_nonblock)
27792785
long ret;
27802786

27812787
if (force_nonblock) {
2782-
if (io_splice_punt(in) || io_splice_punt(out))
2788+
if (io_splice_punt(in, READ) || io_splice_punt(out, WRITE))
27832789
return -EAGAIN;
27842790
flags |= SPLICE_F_NONBLOCK;
27852791
}

0 commit comments

Comments
 (0)