linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Ming Lei <ming.lei@redhat.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH 2/8] loop: remove always true check
Date: Tue, 26 Oct 2021 09:31:52 +0200	[thread overview]
Message-ID: <20211026073152.GB31967@lst.de> (raw)
In-Reply-To: <20211025094437.2837701-3-ming.lei@redhat.com>

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)

  reply	other threads:[~2021-10-26  7:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-25  9:44 [PATCH 0/8] loop: improve dio on backing file Ming Lei
2021-10-25  9:44 ` [PATCH 1/8] loop: move flush_dcache_page to ->complete of request Ming Lei
2021-10-26  7:21   ` Christoph Hellwig
2021-10-25  9:44 ` [PATCH 2/8] loop: remove always true check Ming Lei
2021-10-26  7:31   ` Christoph Hellwig [this message]
2021-10-25  9:44 ` [PATCH 3/8] loop: add one helper for submitting IO on backing file Ming Lei
2021-10-25  9:44 ` [PATCH 4/8] loop: cover simple read/write via lo_rw_aio() Ming Lei
2021-10-26  7:35   ` Christoph Hellwig
2021-10-25  9:44 ` [PATCH 5/8] loop: fallback to buffered IO in case of dio submission Ming Lei
2021-10-26  7:36   ` Christoph Hellwig
2021-10-25  9:44 ` [PATCH 6/8] loop: relax loop dio use condition Ming Lei
2021-10-26  7:37   ` Christoph Hellwig
2021-10-27  0:20   ` kernel test robot
2021-10-25  9:44 ` [PATCH 7/8] loop: remove lo->use_dio Ming Lei
2021-10-25  9:44 ` [RFC PATCH 8/8] loop: use backing dio at default Ming Lei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211026073152.GB31967@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).