[PATCH 09/12] block: add partial sector parameter helper

Keith Busch kbusch at fb.com
Thu Jun 30 13:42:09 PDT 2022


From: Keith Busch <kbusch at kernel.org>

Check if an iov is a read, and aligned to a partial sector access. If so
set the skipped and truncated bytes.

Signed-off-by: Keith Busch <kbusch at kernel.org>
---
 include/linux/blkdev.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 4396fcf04bb8..e631cdd01df4 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1362,6 +1362,27 @@ static inline bool blkdev_dio_unaligned(struct block_device *bdev, loff_t p,
 		!bdev_iter_is_aligned(bdev, iter);
 }
 
+static inline bool blkdev_bit_bucket(struct block_device *bdev, loff_t pos,
+				loff_t len, struct iov_iter *iter, u16 *skip,
+				u16 *trunc)
+{
+	unsigned int blksz = bdev_logical_block_size(bdev);
+
+	if (iov_iter_rw(iter) != READ ||
+	    !blk_queue_bb(bdev_get_queue(bdev)) ||
+	    iter->nr_segs > 1)
+		return false;
+
+	if (!iov_iter_is_aligned(iter, bdev_dma_alignment(bdev),
+				 bdev_dma_alignment(bdev)))
+	        return false;
+
+	*skip = pos & (blksz - 1);
+	*trunc = blksz - ((pos + len) & (blksz - 1));
+
+	return true;
+}
+
 static inline int blk_rq_aligned(struct request_queue *q, unsigned long addr,
 				 unsigned int len)
 {
-- 
2.30.2




More information about the Linux-nvme mailing list