linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/3] block: provide helpers for reading block count
@ 2016-06-23 13:30 Arnd Bergmann
  2016-06-23 13:30 ` [PATCH v2 2/3] partition/efi: use bdev_logical_block_count() Arnd Bergmann
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Arnd Bergmann @ 2016-06-23 13:30 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Nicholas A . Bellinger, Mike Christie, Andy Grover,
	Hannes Reinecke, linux-scsi, target-devel, linux-kernel,
	Christoph Hellwig, Davidlohr Bueso, linux-efi, linux-block,
	Arnd Bergmann

Several drivers use an expensive do_div() to compute the number
of logical or physical blocks in a blockdev, which can be done
more efficiently using a shift, since the blocksize is always
a power of two number.

Let's introduce bdev_logical_block_count() and bdev_physical_block_count()
helper functions mirroring the bdev_logical_block_size() and
bdev_physical_block_size() interfaces for the block size.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Suggested-by: Christoph Hellwig <hch@infradead.org>
---
 include/linux/blkdev.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 9d1e0a4650dc..ae8c408f6c22 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1226,6 +1226,13 @@ static inline unsigned short bdev_logical_block_size(struct block_device *bdev)
 	return queue_logical_block_size(bdev_get_queue(bdev));
 }
 
+static inline sector_t bdev_logical_block_count(struct block_device *bdev)
+{
+	unsigned int block_shift = ilog2(bdev_logical_block_size(bdev));
+
+	return bdev->bd_inode->i_size >> block_shift;
+}
+
 static inline unsigned int queue_physical_block_size(struct request_queue *q)
 {
 	return q->limits.physical_block_size;
@@ -1236,6 +1243,13 @@ static inline unsigned int bdev_physical_block_size(struct block_device *bdev)
 	return queue_physical_block_size(bdev_get_queue(bdev));
 }
 
+static inline sector_t bdev_physical_block_count(struct block_device *bdev)
+{
+	unsigned int block_shift = ilog2(bdev_physical_block_size(bdev));
+
+	return bdev->bd_inode->i_size >> block_shift;
+}
+
 static inline unsigned int queue_io_min(struct request_queue *q)
 {
 	return q->limits.io_min;
-- 
2.9.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-06-27 16:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-23 13:30 [PATCH v2 1/3] block: provide helpers for reading block count Arnd Bergmann
2016-06-23 13:30 ` [PATCH v2 2/3] partition/efi: use bdev_logical_block_count() Arnd Bergmann
2016-06-23 13:30 ` [PATCH v2 3/3] target/iblock: " Arnd Bergmann
2016-06-23 14:22 ` [PATCH v2 1/3] block: provide helpers for reading block count Christoph Hellwig
2016-06-23 15:52 ` Sagi Grimberg
2016-06-27 16:30 ` Davidlohr Bueso

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