@@ -2038,7 +2038,7 @@ static struct file *__io_file_get(struct io_submit_state *state, int fd)
2038
2038
* any file. For now, just ensure that anything potentially problematic is done
2039
2039
* inline.
2040
2040
*/
2041
- static bool io_file_supports_async (struct file * file )
2041
+ static bool io_file_supports_async (struct file * file , int rw )
2042
2042
{
2043
2043
umode_t mode = file_inode (file )-> i_mode ;
2044
2044
@@ -2047,7 +2047,13 @@ static bool io_file_supports_async(struct file *file)
2047
2047
if (S_ISREG (mode ) && file -> f_op != & io_uring_fops )
2048
2048
return true;
2049
2049
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 ;
2051
2057
}
2052
2058
2053
2059
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)
2575
2581
* If the file doesn't support async, mark it as REQ_F_MUST_PUNT so
2576
2582
* we know to async punt it even if it was opened O_NONBLOCK
2577
2583
*/
2578
- if (force_nonblock && !io_file_supports_async (req -> file ))
2584
+ if (force_nonblock && !io_file_supports_async (req -> file , READ ))
2579
2585
goto copy_iov ;
2580
2586
2581
2587
iov_count = iov_iter_count (& iter );
@@ -2666,7 +2672,7 @@ static int io_write(struct io_kiocb *req, bool force_nonblock)
2666
2672
* If the file doesn't support async, mark it as REQ_F_MUST_PUNT so
2667
2673
* we know to async punt it even if it was opened O_NONBLOCK
2668
2674
*/
2669
- if (force_nonblock && !io_file_supports_async (req -> file ))
2675
+ if (force_nonblock && !io_file_supports_async (req -> file , WRITE ))
2670
2676
goto copy_iov ;
2671
2677
2672
2678
/* 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)
2760
2766
return 0 ;
2761
2767
}
2762
2768
2763
- static bool io_splice_punt (struct file * file )
2769
+ static bool io_splice_punt (struct file * file , int rw )
2764
2770
{
2765
2771
if (get_pipe_info (file ))
2766
2772
return false;
2767
- if (!io_file_supports_async (file ))
2773
+ if (!io_file_supports_async (file , rw ))
2768
2774
return true;
2769
2775
return !(file -> f_flags & O_NONBLOCK );
2770
2776
}
@@ -2779,7 +2785,7 @@ static int io_splice(struct io_kiocb *req, bool force_nonblock)
2779
2785
long ret ;
2780
2786
2781
2787
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 ))
2783
2789
return - EAGAIN ;
2784
2790
flags |= SPLICE_F_NONBLOCK ;
2785
2791
}
0 commit comments