diff mbox series

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

Message ID 20220630204212.1265638-10-kbusch@fb.com (mailing list archive)
State New, archived
Headers show
Series block: support for partial sector reads | expand

Commit Message

Keith Busch June 30, 2022, 8:42 p.m. UTC
From: Keith Busch <kbusch@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@kernel.org>
---
 include/linux/blkdev.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
diff mbox series

Patch

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)
 {