From patchwork Mon Oct 18 10:11:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12565549 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80788C4321E for ; Mon, 18 Oct 2021 10:11:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6276960FC2 for ; Mon, 18 Oct 2021 10:11:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230212AbhJRKOE (ORCPT ); Mon, 18 Oct 2021 06:14:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbhJRKOD (ORCPT ); Mon, 18 Oct 2021 06:14:03 -0400 Received: from bombadil.infradead.org (unknown [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21044C06161C; Mon, 18 Oct 2021 03:11:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=xjTWeSayf3PGdeuuH3Uv1mvdxKcTliIdGd38f16e0vY=; b=KMWyFjUUP4rTm1jU72NoSazyjw NukgJKTB3XLeVN5/NaHZeMw1abHoo6KJQXk2WQvU/LsTslU9QVmfYML22zcD3OIFxgbvqOWiXdnaR OpY1s7tltedd/mn56643zLiVtvcycJPwOmHKOR3RPDXVr8PVpqxRhuugiqdEMDLPy7Gw62jdy8gjA FCOsAmyXMJVwe63VVc61EYBxID5DtFF4IstC57V/rHMPXBAphyH570DHr1Ob6pxFi144uTQUosdjx mAcl43jh0ueJZ2x4rqHyyAr2lalnUkUd9hsorIFLNvRC3ubFHhIW5VBzOdWy2PLwjmzFlpw5QEA+l 4CL6wc2A==; Received: from [2001:4bb8:199:73c5:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcPcI-00EtzV-J2; Mon, 18 Oct 2021 10:11:39 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Coly Li , Mike Snitzer , Song Liu , David Sterba , Josef Bacik , "Theodore Ts'o" , OGAWA Hirofumi , Dave Kleikamp , Ryusuke Konishi , Anton Altaparmakov , Konstantin Komarov , Kees Cook , Phillip Lougher , Jan Kara , linux-block@vger.kernel.org, dm-devel@redhat.com, drbd-dev@lists.linbit.com, linux-bcache@vger.kernel.org, linux-raid@vger.kernel.org, linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-nfs@vger.kernel.org, linux-nilfs@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, ntfs3@lists.linux.dev, reiserfs-devel@vger.kernel.org Subject: [PATCH 02/30] block: add a bdev_nr_bytes helper Date: Mon, 18 Oct 2021 12:11:02 +0200 Message-Id: <20211018101130.1838532-3-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211018101130.1838532-1-hch@lst.de> References: <20211018101130.1838532-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Add a helper to query the size of a block device in bytes. This will be used to remove open coded access to ->bd_inode. Signed-off-by: Christoph Hellwig Reviewed-by: Kees Cook --- include/linux/genhd.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 082a3e5fd8fa1..b560aee1d69f0 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -235,9 +235,14 @@ static inline sector_t get_start_sect(struct block_device *bdev) return bdev->bd_start_sect; } +static inline loff_t bdev_nr_bytes(struct block_device *bdev) +{ + return i_size_read(bdev->bd_inode); +} + static inline sector_t bdev_nr_sectors(struct block_device *bdev) { - return i_size_read(bdev->bd_inode) >> 9; + return bdev_nr_bytes(bdev) >> SECTOR_SHIFT; } static inline sector_t get_capacity(struct gendisk *disk)