mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Jens Axboe <axboe@fb.com>
Cc: "Nicholas A . Bellinger" <nab@linux-iscsi.org>,
	Mike Christie <mchristi@redhat.com>,
	Andy Grover <agrover@redhat.com>, Hannes Reinecke <hare@suse.com>,
	linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Christoph Hellwig <hch@infradead.org>,
	Davidlohr Bueso <dave@stgolabs.net>,
	linux-efi@vger.kernel.org, linux-block@vger.kernel.org,
	Arnd Bergmann <arnd@arndb.de>
Subject: [PATCH v2 1/3] block: provide helpers for reading block count
Date: Thu, 23 Jun 2016 15:30:14 +0200	[thread overview]
Message-ID: <20160623133016.3781907-1-arnd@arndb.de> (raw)

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

             reply	other threads:[~2016-06-23 13:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-23 13:30 Arnd Bergmann [this message]
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

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=20160623133016.3781907-1-arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=agrover@redhat.com \
    --cc=axboe@fb.com \
    --cc=dave@stgolabs.net \
    --cc=hare@suse.com \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mchristi@redhat.com \
    --cc=nab@linux-iscsi.org \
    --cc=target-devel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®