From patchwork Thu Jun 23 13:30:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 102107 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp434378qgy; Thu, 23 Jun 2016 06:30:17 -0700 (PDT) X-Received: by 10.67.15.72 with SMTP id fm8mr43700568pad.50.1466688616958; Thu, 23 Jun 2016 06:30:16 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d20si122837pfk.240.2016.06.23.06.30.16; Thu, 23 Jun 2016 06:30:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932118AbcFWN3K (ORCPT + 30 others); Thu, 23 Jun 2016 09:29:10 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:54946 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752166AbcFWN3G (ORCPT ); Thu, 23 Jun 2016 09:29:06 -0400 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue103) with ESMTPA (Nemesis) id 0LxLzO-1bQJ1f44vy-016td7; Thu, 23 Jun 2016 15:28:10 +0200 From: Arnd Bergmann To: Jens Axboe Cc: "Nicholas A . Bellinger" , Mike Christie , Andy Grover , Hannes Reinecke , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Davidlohr Bueso , linux-efi@vger.kernel.org, linux-block@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 1/3] block: provide helpers for reading block count Date: Thu, 23 Jun 2016 15:30:14 +0200 Message-Id: <20160623133016.3781907-1-arnd@arndb.de> 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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Suggested-by: Christoph Hellwig --- include/linux/blkdev.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) -- 2.9.0 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;