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: 9195147 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 528486077D for ; Thu, 23 Jun 2016 13:30:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42D1926746 for ; Thu, 23 Jun 2016 13:30:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 374D528457; Thu, 23 Jun 2016 13:30:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC22F26746 for ; Thu, 23 Jun 2016 13:30:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932085AbcFWN3J (ORCPT ); Thu, 23 Jun 2016 09:29:09 -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-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Christoph Hellwig Reviewed-by: Sagi Grimbeg --- 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;