Move the kiocb_start_write() call from lo_submit_rw_aio() to lo_rw_aio_prep() to initialize write accounting earlier in the I/O preparation phase rather than during submission. Make sure both kiocb_start_write() and kiocb_end_write() are called just once. Fixes: 0ba93a906dda ("loop: try to handle loop aio command via NOWAIT IO first") Signed-off-by: Ming Lei --- drivers/block/loop.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 9b842d767381..64295c141b97 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -402,6 +402,9 @@ static int lo_rw_aio_prep(struct loop_device *lo, struct loop_cmd *cmd, cmd->iocb.ki_complete = NULL; cmd->iocb.ki_flags = 0; } + + if (req_op(rq) == REQ_OP_WRITE) + kiocb_start_write(&cmd->iocb); return 0; } @@ -431,11 +434,9 @@ static int lo_submit_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, } atomic_set(&cmd->ref, 2); - - if (rw == ITER_SOURCE) { - kiocb_start_write(&cmd->iocb); + if (rw == ITER_SOURCE) ret = file->f_op->write_iter(&cmd->iocb, &iter); - } else + else ret = file->f_op->read_iter(&cmd->iocb, &iter); lo_rw_aio_do_completion(cmd); -- 2.47.0