linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ritika Srivastava <ritika.srivastava@oracle.com>
To: linux-block@vger.kernel.org, axboe@kernel.dk
Cc: martin.petersen@oracle.com, hch@infradead.org,
	ritika.srivastava@oracle.com
Subject: [PATCH v4 2/2] block: better deal with the delayed not supported case in blk_cloned_rq_check_limits
Date: Tue, 18 Aug 2020 10:39:40 -0700	[thread overview]
Message-ID: <1597772380-3034-1-git-send-email-ritika.srivastava@oracle.com> (raw)

If WRITE_ZERO/WRITE_SAME operation is not supported by the storage,
blk_cloned_rq_check_limits() will return IO error which will cause
device-mapper to fail the paths.

Instead, if the queue limit is set to 0, return BLK_STS_NOTSUPP.
BLK_STS_NOTSUPP will be ignored by device-mapper and will not fail the
paths.

Suggested-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Ritika Srivastava <ritika.srivastava@oracle.com>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
---
Changelog:
v4: Explain the window of error in the comments.
    Add reviewed-by tag from Martin
v3: Formatting changes and subject updated from previous version
    -block: return BLK_STS_NOTSUPP if operation is not supported
v2: Document scenario and SCSI error encountered in a comment in
    blk_cloned_rq_check_limits().
---
 block/blk-core.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index d241ab8..43401d3 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1223,10 +1223,24 @@ blk_qc_t submit_bio(struct bio *bio)
 static blk_status_t blk_cloned_rq_check_limits(struct request_queue *q,
 				      struct request *rq)
 {
-	if (blk_rq_sectors(rq) > blk_queue_get_max_sectors(q, req_op(rq))) {
+	unsigned int max_sectors = blk_queue_get_max_sectors(q, req_op(rq));
+
+	if (blk_rq_sectors(rq) > max_sectors) {
+		/*
+		 * SCSI device does not have a good way to return if
+		 * Write Same/Zero is actually supported. If a device rejects
+		 * a non-read/write command (discard, write same,etc.) the
+		 * low-level device driver will set the relevant queue limit to
+		 * 0 to prevent blk-lib from issuing more of the offending
+		 * operations. Commands queued prior to the queue limit being
+		 * reset need to be completed with BLK_STS_NOTSUPP to avoid I/O
+		 * errors being propagated to upper layers.
+		 */
+		if (max_sectors == 0)
+			return BLK_STS_NOTSUPP;
+
 		printk(KERN_ERR "%s: over max size limit. (%u > %u)\n",
-			__func__, blk_rq_sectors(rq),
-			blk_queue_get_max_sectors(q, req_op(rq)));
+			__func__, blk_rq_sectors(rq), max_sectors);
 		return BLK_STS_IOERR;
 	}
 
@@ -1253,8 +1267,11 @@ static blk_status_t blk_cloned_rq_check_limits(struct request_queue *q,
  */
 blk_status_t blk_insert_cloned_request(struct request_queue *q, struct request *rq)
 {
-	if (blk_cloned_rq_check_limits(q, rq))
-		return BLK_STS_IOERR;
+	blk_status_t ret;
+
+	ret = blk_cloned_rq_check_limits(q, rq);
+	if (ret != BLK_STS_OK)
+		return ret;
 
 	if (rq->rq_disk &&
 	    should_fail_request(&rq->rq_disk->part0, blk_rq_bytes(rq)))
-- 
1.8.3.1


             reply	other threads:[~2020-08-18 17:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-18 17:39 Ritika Srivastava [this message]
2020-08-18 19:43 ` [PATCH v4 2/2] block: better deal with the delayed not supported case in blk_cloned_rq_check_limits Christoph Hellwig
2020-08-26 17:03   ` Ritika Srivastava
2020-09-01 20:17 Return BLK_STS_NOTSUPP and blk_status_t from blk_cloned_rq_check_limits() Ritika Srivastava
2020-09-01 20:17 ` [PATCH v4 2/2] block: better deal with the delayed not supported case in blk_cloned_rq_check_limits Ritika Srivastava

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=1597772380-3034-1-git-send-email-ritika.srivastava@oracle.com \
    --to=ritika.srivastava@oracle.com \
    --cc=axboe@kernel.dk \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=martin.petersen@oracle.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).