Message ID | 20211025094437.2837701-3-ming.lei@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | loop: improve dio on backing file | expand |
lo_complete_rq is still a complete mess. I'd suggest something like this instead: diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 8f140d6374356..1648d30a8cb4a 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -517,40 +517,37 @@ static void lo_flush_dcache_for_read(struct request *rq) static void lo_complete_rq(struct request *rq) { struct loop_cmd *cmd = blk_mq_rq_to_pdu(rq); - blk_status_t ret = BLK_STS_OK; + + if (cmd->ret < 0) { + blk_mq_end_request(rq, errno_to_blk_status(cmd->ret)); + return; + } /* Kernel wrote to our pages, call flush_dcache_page */ if (req_op(rq) == REQ_OP_READ && !cmd->use_aio && cmd->ret >= 0) lo_flush_dcache_for_read(rq); - if (!cmd->use_aio || cmd->ret < 0 || cmd->ret == blk_rq_bytes(rq) || - req_op(rq) != REQ_OP_READ) { - if (cmd->ret < 0) - ret = errno_to_blk_status(cmd->ret); - goto end_io; - } - /* - * Short READ - if we got some data, advance our request and - * retry it. If we got no data, end the rest with EIO. + * Short READ - if we got some data, advance our request and retry it. + * If we got no data, end the rest with EIO. */ - if (cmd->ret) { - blk_update_request(rq, BLK_STS_OK, cmd->ret); - cmd->ret = 0; - blk_mq_requeue_request(rq, true); - } else { - if (cmd->use_aio) { - struct bio *bio = rq->bio; + if (req_op(rq) == REQ_OP_READ && cmd->use_aio && + cmd->ret != blk_rq_bytes(rq)) { + if (cmd->ret) { + blk_update_request(rq, BLK_STS_OK, cmd->ret); + cmd->ret = 0; + blk_mq_requeue_request(rq, true); + } else { + struct bio *bio; - while (bio) { + for (bio = rq->bio; bio; bio = bio->bi_next) zero_fill_bio(bio); - bio = bio->bi_next; - } + blk_mq_end_request(rq, BLK_STS_IOERR); } - ret = BLK_STS_IOERR; -end_io: - blk_mq_end_request(rq, ret); + return; } + + blk_mq_end_request(rq, BLK_STS_OK); } static void lo_rw_aio_do_completion(struct loop_cmd *cmd)
diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 8f140d637435..8c3f5d2affc7 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -539,13 +539,11 @@ static void lo_complete_rq(struct request *rq) cmd->ret = 0; blk_mq_requeue_request(rq, true); } else { - if (cmd->use_aio) { - struct bio *bio = rq->bio; + struct bio *bio = rq->bio; - while (bio) { - zero_fill_bio(bio); - bio = bio->bi_next; - } + while (bio) { + zero_fill_bio(bio); + bio = bio->bi_next; } ret = BLK_STS_IOERR; end_io:
In lo_complete_rq(), in case of !cmd->use_aio, we simply call blk_mq_end_request(), so the check of cmd->use_aio isn't necessary, since it is always true when the check is run. Signed-off-by: Ming Lei <ming.lei@redhat.com> --- drivers/block/loop.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)