Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1429830

[PATCH v2 1/3] block: provide helpers for reading block count

Path csiph.com!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod
From Arnd Bergmann <arnd@arndb.de>
Newsgroups linux.kernel
Subject [PATCH v2 1/3] block: provide helpers for reading block count
Date Thu, 23 Jun 2016 15:40:01 +0200
Message-ID <rNcRH-27f-3@gated-at.bofh.it> (permalink)
X-Mailer git-send-email 2.9.0
X-Provags-ID V03:K0:c5hq6TeNWqjlfLOByYx1OcjE2lZSKFPqulpSp6Hevsk7+bjXO+2 vvlTXZQOeJf8yt9YfXQOL+EXM8euKmJ8DoiffqFIaCNNrAL4qUpyyFRECz7O7+sKU5BJ8yR snBj6pDqbtl4L/HMV9L9aq+wiX7NkeGL4qQsZkAYo1T9QZ57B8xeTs7hIzBFXrSiwtBgJk1 DO3Tun6vsOtENNg1NtKvw==
X-Ui-Out-Filterresults notjunk:1;V01:K0:58plwRA2L2c=:uoWxcPjt0P4mvS6S8PmgSx GEFePiyRfEcV1dyfqmPNJQkmytYSLZYjfWTr6KY3wt2OHRy67EtjPAgXc+7uE6fkmA76aqyJT CJ7KxC0nEu+LMhFuDZivBD/16NclPAxEi8d24zAlNighhtZQaFz/UMLBYOHk3PSCWeZrsQ1NV SkI38U60xb9cOaPTJDHyesRFjR/IN6iVK6NGCXCZMbZh/yHX+BL73iHbZ75TDqnEzbR1H9wrF ujN81ThIdCWBsOyFxrDZ0aWdPRPlq/LdY0cTujaacOotU/P3LnHKr9to1KkxNAg66PKhFbmIx OH9smLwUJey1yIDVVKTvCCzztItDKk18Uj1qcaeMzzQLMQbPi0voV+cmZf9J7DUgub+zgAPdZ NplDnWXvNwcrotYhws+N3LDEJzMndZV+eEr1zk5QEwDKKiv2Oqh10/OjLSb9OJsu4Y3G4KL5i Bbw6JEiBMHLqMAwmSyl0hhR8h0GF/I/BNR0S8qCpsBLwZcinPe4ICQxf2Vh2p/s70bWYEml8N iCm120VOrH54qBklbDtlcDwzsMLb39mSU46COetSXK5O1GubZpd32cbpbtzmZco/OGGPhYGdF DedJOEZYcPlBvR0fprnZX9pmmHCVCAf3cuhg79ULR6pt2be02zJuxbZXJkFSDFEm2VKpHG1Wo czCh5XWuiKY8+hlcUSqSGOuaq2VoFmCKvZbo3pHpF1bg0b9RAT0jG/KNceGD1JzkQnt4=
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 49
Organization linux.* mail to news gateway
X-Original-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>
X-Original-Date Thu, 23 Jun 2016 15:30:14 +0200
X-Original-Message-ID <20160623133016.3781907-1-arnd@arndb.de>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1429830

Show key headers only | View 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

Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 1/3] block: provide helpers for reading block count Arnd Bergmann <arnd@arndb.de> - 2016-06-23 15:40 +0200
  Re: [PATCH v2 1/3] block: provide helpers for reading block count Christoph Hellwig <hch@infradead.org> - 2016-06-23 16:30 +0200
  Re: [PATCH v2 1/3] block: provide helpers for reading block count Sagi Grimberg <sagi@grimberg.me> - 2016-06-23 18:00 +0200
  Re: [PATCH v2 1/3] block: provide helpers for reading block count Davidlohr Bueso <dave@stgolabs.net> - 2016-06-27 18:40 +0200

csiph-web