From: Bart Van Assche <bart.vanassche@wdc.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
Bart Van Assche <bart.vanassche@wdc.com>,
Ming Lei <ming.lei@redhat.com>
Subject: [PATCH 1/3] block: Fix blk_rq_payload_bytes()
Date: Mon, 25 Jun 2018 17:10:07 -0700 [thread overview]
Message-ID: <20180626001009.16557-2-bart.vanassche@wdc.com> (raw)
In-Reply-To: <20180626001009.16557-1-bart.vanassche@wdc.com>
The SCSI sd driver converts a block layer request into a SCSI WRITE
SAME command in the following cases:
1. REQ_OP_DISCARD if the sd driver has been configured to translate
this request type into WRITE SAME.
2. REQ_OP_WRITE_SAME.
The SCSI sd driver sets RQF_SPECIAL_PAYLOAD in case (1) but not in
case (2). Make sure that blk_rq_payload_bytes() handles both cases
correctly.
Fixes: 2e3258ecfaeb ("block: add blk_rq_payload_bytes")
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Ming Lei <ming.lei@redhat.com>
---
include/linux/blkdev.h | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index dcf5e0990bfa..b7519a5c1002 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1091,15 +1091,19 @@ static inline unsigned int blk_rq_zone_is_seq(struct request *rq)
#endif /* CONFIG_BLK_DEV_ZONED */
/*
- * Some commands like WRITE SAME have a payload or data transfer size which
- * is different from the size of the request. Any driver that supports such
- * commands using the RQF_SPECIAL_PAYLOAD flag needs to use this helper to
- * calculate the data transfer size.
+ * Some commands like DISCARD and WRITE SAME have a payload size which is
+ * different from the number of bytes affected on the storage medium. Any
+ * driver that supports such commands needs to use this helper to calculate
+ * the data buffer size.
*/
-static inline unsigned int blk_rq_payload_bytes(struct request *rq)
+static inline unsigned int blk_rq_payload_bytes(const struct request *rq)
{
if (rq->rq_flags & RQF_SPECIAL_PAYLOAD)
return rq->special_vec.bv_len;
+ if (req_op(rq) == REQ_OP_WRITE_SAME) {
+ WARN_ON_ONCE(rq->bio->bi_vcnt != 1);
+ return rq->bio->bi_io_vec->bv_len;
+ }
return blk_rq_bytes(rq);
}
--
2.17.1
next prev parent reply other threads:[~2018-06-26 0:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-26 0:10 [PATCH 0/3] Fix blk_mq_end_request() and blk_end_request() for WRITE SAME Bart Van Assche
2018-06-26 0:10 ` Bart Van Assche [this message]
2018-06-26 0:10 ` [PATCH 2/3] sd: Remove the __data_len hack for WRITE SAME again Bart Van Assche
2018-06-26 0:10 ` [PATCH 3/3] block: Fix blk_end_request_all() for WRITE SAME requests Bart Van Assche
2018-06-26 15:53 ` [PATCH 0/3] Fix blk_mq_end_request() and blk_end_request() for WRITE SAME Martin K. Petersen
2018-06-26 16:24 ` Bart Van Assche
2018-06-29 8:58 ` Christoph Hellwig
2018-06-29 15:50 ` Bart Van Assche
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=20180626001009.16557-2-bart.vanassche@wdc.com \
--to=bart.vanassche@wdc.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--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