2323#include "poll.h"
2424#include "rw.h"
2525
26+ static void io_complete_rw (struct kiocb * kiocb , long res );
27+ static void io_complete_rw_iopoll (struct kiocb * kiocb , long res );
28+
2629struct io_rw {
2730 /* NOTE: kiocb has the file as the first member, so don't do it here */
2831 struct kiocb kiocb ;
@@ -289,6 +292,11 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
289292 rw -> kiocb .dio_complete = NULL ;
290293 rw -> kiocb .ki_flags = 0 ;
291294
295+ if (req -> ctx -> flags & IORING_SETUP_IOPOLL )
296+ rw -> kiocb .ki_complete = io_complete_rw_iopoll ;
297+ else
298+ rw -> kiocb .ki_complete = io_complete_rw ;
299+
292300 rw -> addr = READ_ONCE (sqe -> addr );
293301 rw -> len = READ_ONCE (sqe -> len );
294302 rw -> flags = READ_ONCE (sqe -> rw_flags );
@@ -817,10 +825,8 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type)
817825 if (ctx -> flags & IORING_SETUP_IOPOLL ) {
818826 if (!(kiocb -> ki_flags & IOCB_DIRECT ) || !file -> f_op -> iopoll )
819827 return - EOPNOTSUPP ;
820-
821828 kiocb -> private = NULL ;
822829 kiocb -> ki_flags |= IOCB_HIPRI ;
823- kiocb -> ki_complete = io_complete_rw_iopoll ;
824830 req -> iopoll_completed = 0 ;
825831 if (ctx -> flags & IORING_SETUP_HYBRID_IOPOLL ) {
826832 /* make sure every req only blocks once*/
@@ -830,7 +836,6 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type)
830836 } else {
831837 if (kiocb -> ki_flags & IOCB_HIPRI )
832838 return - EINVAL ;
833- kiocb -> ki_complete = io_complete_rw ;
834839 }
835840
836841 if (req -> flags & REQ_F_HAS_METADATA ) {
0 commit comments