block: add blk_rq_payload_bytes
authorChristoph Hellwig <hch@lst.de>
Fri, 13 Jan 2017 11:29:10 +0000 (12:29 +0100)
committerJens Axboe <axboe@fb.com>
Fri, 13 Jan 2017 22:17:04 +0000 (15:17 -0700)
Add a helper to calculate the actual data transfer size for special
payload requests.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
include/linux/blkdev.h

index ff3d774f27512a08f5e5e59db179aa9de9c63cf5..1ca8e8fd10789d0fff1aa0b21ede64b72075e094 100644 (file)
@@ -1000,6 +1000,19 @@ static inline unsigned int blk_rq_cur_sectors(const struct request *rq)
        return blk_rq_cur_bytes(rq) >> 9;
 }
 
+/*
+ * 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.
+ */
+static inline unsigned int blk_rq_payload_bytes(struct request *rq)
+{
+       if (rq->rq_flags & RQF_SPECIAL_PAYLOAD)
+               return rq->special_vec.bv_len;
+       return blk_rq_bytes(rq);
+}
+
 static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
                                                     int op)
 {