Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3123605pxb; Tue, 12 Oct 2021 22:28:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvCFm43rkHlk0H0Av9g6hDKrXWh8tHsBbtVGr5zTSy+qoqUr5NZJ2YCYKsLWgJFWMsSmNi X-Received: by 2002:a05:6402:27d0:: with SMTP id c16mr6285483ede.212.1634102881327; Tue, 12 Oct 2021 22:28:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634102881; cv=none; d=google.com; s=arc-20160816; b=dJpXTJupPKwkKMNyKe0gGkRhzqmzpXTRkzNbgz4lrf5jB3xsJbGdse8a/+4G9vR72r lb0/eYmkJneOOv7SCc5LXPr5wZcwCtxsg4jweAm8FEWLxj2xz6SYHqN/8RuBILADtxV8 KFCx9KncFB/m6VdYRjEVxmQY8Te232SEDROVMpz7DoFKwrAIxRvub8fBuOCeTpdTNQeJ m4rgLchm2XSYApcUiHbN6vyDEuKeLqCnK3YcTWMR1HwCW5ma1hJl8qFP/d/KbhlCqyYu 6I2oe44E/gwFRwFksFPuYV8SRmoc6aOFZj8xxEm2SKSNodnqoNIFT4GObynSjosrmuBK zj5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ipuq67z5QdT3yKKueTO0DdjUY51NfmhCgoNzBVLjg3c=; b=vnYLfxoE5/hLXUh7Cig07SrDoi/NX+62mxKGy3kH+gQJbtW4wLRxa0aQ+M0Skqy0j/ u35qOCLN3vLyd7IRc43lKOn3Ox1BRGzOsXi5urES1XEXweUceULgFRKl7yusq99vhmO8 pSCCoYOkQVFpZELHmNzGHOZDdYK+EA64zYYHSEVVExBhNgxZ/J4pKE4Q5hb44iSyH0aL nXcSwmpw5CClvv0c68Tg2UdXqS9tIeyULhup+Y9E1y5dNPSYP+1WgqUVvAaMjlvZOFO4 Ghc4NSqJDvobumecQRxOcPB7XvNuddwM3FCTi42+5pqKgP2mRJXwYaVEZvOI+YHTpTv0 gp4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=SFr8envK; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dc16si18828365ejb.287.2021.10.12.22.27.38; Tue, 12 Oct 2021 22:28:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=SFr8envK; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229770AbhJMF3i (ORCPT + 99 others); Wed, 13 Oct 2021 01:29:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbhJMF3h (ORCPT ); Wed, 13 Oct 2021 01:29:37 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D697CC061570; Tue, 12 Oct 2021 22:27:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=Ipuq67z5QdT3yKKueTO0DdjUY51NfmhCgoNzBVLjg3c=; b=SFr8envKNT3NNogjfPe5eNqifV kHuUE7klLxDfNX7H8i8ZKZgHk6/vGM6OPgfskI3Mbhho7gAqGM0EdECulx7yRzc86zQpHT4Lkjx5a y39fiiARo+ET68jmgySPFzaIJjQR+Gh0Kug5ebf3xq4ywVfYgUFkX0oLejNmBEgl/By0S6aHMqZQL gnGV1rSZ2q2pgoeHjyHfNyZc4Olho6XDLVZcwHrpMpZXqXpxYW6wggDueq7kJqesecOwoaA+4aq7S FDeSXRS0VRHIESM7+9u4MidzNWcJdzTU9HSa29xjQqjKpksMbRd5SC1/1N7UjVU+7Zes8bbfVtk4+ G7B+TEEA==; Received: from 089144212063.atnat0021.highway.a1.net ([89.144.212.63] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1maWis-0076j5-8P; Wed, 13 Oct 2021 05:23:13 +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-mtd@lists.infradead.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 11/29] btrfs: use bdev_nr_sectors instead of open coding it Date: Wed, 13 Oct 2021 07:10:24 +0200 Message-Id: <20211013051042.1065752-12-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211013051042.1065752-1-hch@lst.de> References: <20211013051042.1065752-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Use the proper helper to read the block device size. Signed-off-by: Christoph Hellwig --- fs/btrfs/dev-replace.c | 2 +- fs/btrfs/disk-io.c | 3 ++- fs/btrfs/ioctl.c | 4 ++-- fs/btrfs/volumes.c | 7 ++++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index d029be40ea6f0..67799b3132120 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -283,7 +283,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, } - if (i_size_read(bdev->bd_inode) < + if ((bdev_nr_sectors(bdev) << SECTOR_SHIFT) < btrfs_device_get_total_bytes(srcdev)) { btrfs_err(fs_info, "target device is smaller than source device!"); diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 355ea88d5c5f7..07983f7e66e9f 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3740,7 +3740,8 @@ struct btrfs_super_block *btrfs_read_dev_one_super(struct block_device *bdev, else if (ret) return ERR_PTR(ret); - if (bytenr + BTRFS_SUPER_INFO_SIZE >= i_size_read(bdev->bd_inode)) + if (bytenr + BTRFS_SUPER_INFO_SIZE >= + (bdev_nr_sectors(bdev) << SECTOR_SHIFT)) return ERR_PTR(-EINVAL); page = read_cache_page_gfp(mapping, bytenr >> PAGE_SHIFT, GFP_NOFS); diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index cc61813213d83..5e6589b6ad8e4 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1730,7 +1730,7 @@ static noinline int btrfs_ioctl_resize(struct file *file, } if (!strcmp(sizestr, "max")) - new_size = device->bdev->bd_inode->i_size; + new_size = bdev_nr_sectors(device->bdev) << SECTOR_SHIFT; else { if (sizestr[0] == '-') { mod = -1; @@ -1771,7 +1771,7 @@ static noinline int btrfs_ioctl_resize(struct file *file, ret = -EINVAL; goto out_finish; } - if (new_size > device->bdev->bd_inode->i_size) { + if (new_size > (bdev_nr_sectors(device->bdev) << SECTOR_SHIFT)) { ret = -EFBIG; goto out_finish; } diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 2ec3b8ac8fa35..11c5f9ec02511 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1286,7 +1286,7 @@ static struct btrfs_super_block *btrfs_read_disk_super(struct block_device *bdev pgoff_t index; /* make sure our super fits in the device */ - if (bytenr + PAGE_SIZE >= i_size_read(bdev->bd_inode)) + if (bytenr + PAGE_SIZE >= (bdev_nr_sectors(bdev) << SECTOR_SHIFT)) return ERR_PTR(-EINVAL); /* make sure our super fits in the page */ @@ -2610,7 +2610,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path device->io_width = fs_info->sectorsize; device->io_align = fs_info->sectorsize; device->sector_size = fs_info->sectorsize; - device->total_bytes = round_down(i_size_read(bdev->bd_inode), + device->total_bytes = round_down(bdev_nr_sectors(bdev) << SECTOR_SHIFT, fs_info->sectorsize); device->disk_total_bytes = device->total_bytes; device->commit_total_bytes = device->total_bytes; @@ -7236,7 +7236,8 @@ static int read_one_dev(struct extent_buffer *leaf, fill_device_from_item(leaf, dev_item, device); if (device->bdev) { - u64 max_total_bytes = i_size_read(device->bdev->bd_inode); + u64 max_total_bytes = + bdev_nr_sectors(device->bdev) << SECTOR_SHIFT; if (device->total_bytes > max_total_bytes) { btrfs_err(fs_info, -- 2.30.2