linux-bcache.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* don't use ->bd_inode to access the block device size
@ 2021-10-13  5:10 Christoph Hellwig
  2021-10-13  5:10 ` [PATCH 01/29] bcache: remove bdev_sectors Christoph Hellwig
                   ` (31 more replies)
  0 siblings, 32 replies; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Hi Jens,

various drivers currently poke directy at the block device inode, which
is a bit of a mess.  This series cleans up the places that read the
block device size to use the proper helpers.  I have separate patches
for many of the other bd_inode uses, but this series is already big
enough as-is,

I wondered about adding a helper for looking at the size in byte units
to avoid the SECTOR_SHIFT shifts in various places.  But given that
I could not come up with a good name and block devices fundamentally
work in sector size granularity I decided against that.

Diffstat:
 block/fops.c                        |    2 +-
 drivers/block/drbd/drbd_int.h       |    3 +--
 drivers/md/bcache/super.c           |    2 +-
 drivers/md/bcache/util.h            |    4 ----
 drivers/md/bcache/writeback.c       |    2 +-
 drivers/md/dm-bufio.c               |    2 +-
 drivers/md/dm-cache-metadata.c      |    2 +-
 drivers/md/dm-cache-target.c        |    2 +-
 drivers/md/dm-clone-target.c        |    2 +-
 drivers/md/dm-dust.c                |    5 ++---
 drivers/md/dm-ebs-target.c          |    2 +-
 drivers/md/dm-era-target.c          |    2 +-
 drivers/md/dm-exception-store.h     |    2 +-
 drivers/md/dm-flakey.c              |    3 +--
 drivers/md/dm-integrity.c           |    6 +++---
 drivers/md/dm-linear.c              |    3 +--
 drivers/md/dm-log-writes.c          |    4 ++--
 drivers/md/dm-log.c                 |    2 +-
 drivers/md/dm-mpath.c               |    2 +-
 drivers/md/dm-raid.c                |    6 +++---
 drivers/md/dm-switch.c              |    2 +-
 drivers/md/dm-table.c               |    3 +--
 drivers/md/dm-thin-metadata.c       |    2 +-
 drivers/md/dm-thin.c                |    2 +-
 drivers/md/dm-verity-target.c       |    3 +--
 drivers/md/dm-writecache.c          |    2 +-
 drivers/md/dm-zoned-target.c        |    2 +-
 drivers/md/md.c                     |   26 +++++++++++---------------
 drivers/mtd/devices/block2mtd.c     |    5 +++--
 drivers/nvme/target/io-cmd-bdev.c   |    4 ++--
 drivers/target/target_core_iblock.c |    5 +++--
 fs/affs/super.c                     |    2 +-
 fs/btrfs/dev-replace.c              |    2 +-
 fs/btrfs/disk-io.c                  |    3 ++-
 fs/btrfs/ioctl.c                    |    4 ++--
 fs/btrfs/volumes.c                  |    7 ++++---
 fs/buffer.c                         |    4 ++--
 fs/cramfs/inode.c                   |    2 +-
 fs/ext4/super.c                     |    2 +-
 fs/fat/inode.c                      |    5 +----
 fs/hfs/mdb.c                        |    2 +-
 fs/hfsplus/wrapper.c                |    2 +-
 fs/jfs/resize.c                     |    5 ++---
 fs/jfs/super.c                      |    5 ++---
 fs/nfs/blocklayout/dev.c            |    4 ++--
 fs/nilfs2/ioctl.c                   |    2 +-
 fs/nilfs2/super.c                   |    2 +-
 fs/nilfs2/the_nilfs.c               |    3 ++-
 fs/ntfs/super.c                     |    8 +++-----
 fs/ntfs3/super.c                    |    3 +--
 fs/pstore/blk.c                     |    4 ++--
 fs/reiserfs/super.c                 |    7 ++-----
 fs/squashfs/super.c                 |    5 +++--
 fs/udf/lowlevel.c                   |    5 ++---
 fs/udf/super.c                      |    9 +++------
 include/linux/genhd.h               |    6 ++++++
 56 files changed, 100 insertions(+), 117 deletions(-)

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 01/29] bcache: remove bdev_sectors
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  5:21   ` Coly Li
  2021-10-13  6:09   ` Kees Cook
  2021-10-13  5:10 ` [PATCH 02/29] drbd: use bdev_nr_sectors instead of open coding it Christoph Hellwig
                   ` (30 subsequent siblings)
  31 siblings, 2 replies; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the equivalent block layer helper instead.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/md/bcache/super.c     | 2 +-
 drivers/md/bcache/util.h      | 4 ----
 drivers/md/bcache/writeback.c | 2 +-
 3 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index f2874c77ff797..4f89985abe4b7 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1002,7 +1002,7 @@ static void calc_cached_dev_sectors(struct cache_set *c)
 	struct cached_dev *dc;
 
 	list_for_each_entry(dc, &c->cached_devs, list)
-		sectors += bdev_sectors(dc->bdev);
+		sectors += bdev_nr_sectors(dc->bdev);
 
 	c->cached_dev_sectors = sectors;
 }
diff --git a/drivers/md/bcache/util.h b/drivers/md/bcache/util.h
index b64460a762677..a7da7930a7fda 100644
--- a/drivers/md/bcache/util.h
+++ b/drivers/md/bcache/util.h
@@ -584,8 +584,4 @@ static inline unsigned int fract_exp_two(unsigned int x,
 void bch_bio_map(struct bio *bio, void *base);
 int bch_bio_alloc_pages(struct bio *bio, gfp_t gfp_mask);
 
-static inline sector_t bdev_sectors(struct block_device *bdev)
-{
-	return bdev->bd_inode->i_size >> 9;
-}
 #endif /* _BCACHE_UTIL_H */
diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
index 8120da278161e..c7560f66dca88 100644
--- a/drivers/md/bcache/writeback.c
+++ b/drivers/md/bcache/writeback.c
@@ -45,7 +45,7 @@ static uint64_t __calc_target_rate(struct cached_dev *dc)
 	 * backing volume uses about 2% of the cache for dirty data.
 	 */
 	uint32_t bdev_share =
-		div64_u64(bdev_sectors(dc->bdev) << WRITEBACK_SHARE_SHIFT,
+		div64_u64(bdev_nr_sectors(dc->bdev) << WRITEBACK_SHARE_SHIFT,
 				c->cached_dev_sectors);
 
 	uint64_t cache_dirty_target =
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 02/29] drbd: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
  2021-10-13  5:10 ` [PATCH 01/29] bcache: remove bdev_sectors Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  6:09   ` Kees Cook
  2021-10-13 22:33   ` Chaitanya Kulkarni
  2021-10-13  5:10 ` [PATCH 03/29] dm: " Christoph Hellwig
                   ` (29 subsequent siblings)
  31 siblings, 2 replies; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/block/drbd/drbd_int.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
index 5d9181382ce19..75fda53eed8cf 100644
--- a/drivers/block/drbd/drbd_int.h
+++ b/drivers/block/drbd/drbd_int.h
@@ -1826,8 +1826,7 @@ static inline sector_t drbd_md_last_sector(struct drbd_backing_dev *bdev)
 /* Returns the number of 512 byte sectors of the device */
 static inline sector_t drbd_get_capacity(struct block_device *bdev)
 {
-	/* return bdev ? get_capacity(bdev->bd_disk) : 0; */
-	return bdev ? i_size_read(bdev->bd_inode) >> 9 : 0;
+	return bdev ? bdev_nr_sectors(bdev) : 0;
 }
 
 /**
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 03/29] dm: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
  2021-10-13  5:10 ` [PATCH 01/29] bcache: remove bdev_sectors Christoph Hellwig
  2021-10-13  5:10 ` [PATCH 02/29] drbd: use bdev_nr_sectors instead of open coding it Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  6:10   ` Kees Cook
  2021-10-13 16:43   ` Mike Snitzer
  2021-10-13  5:10 ` [PATCH 04/29] md: " Christoph Hellwig
                   ` (28 subsequent siblings)
  31 siblings, 2 replies; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/md/dm-bufio.c           | 2 +-
 drivers/md/dm-cache-metadata.c  | 2 +-
 drivers/md/dm-cache-target.c    | 2 +-
 drivers/md/dm-clone-target.c    | 2 +-
 drivers/md/dm-dust.c            | 5 ++---
 drivers/md/dm-ebs-target.c      | 2 +-
 drivers/md/dm-era-target.c      | 2 +-
 drivers/md/dm-exception-store.h | 2 +-
 drivers/md/dm-flakey.c          | 3 +--
 drivers/md/dm-integrity.c       | 6 +++---
 drivers/md/dm-linear.c          | 3 +--
 drivers/md/dm-log-writes.c      | 4 ++--
 drivers/md/dm-log.c             | 2 +-
 drivers/md/dm-mpath.c           | 2 +-
 drivers/md/dm-raid.c            | 6 +++---
 drivers/md/dm-switch.c          | 2 +-
 drivers/md/dm-table.c           | 3 +--
 drivers/md/dm-thin-metadata.c   | 2 +-
 drivers/md/dm-thin.c            | 2 +-
 drivers/md/dm-verity-target.c   | 3 +--
 drivers/md/dm-writecache.c      | 2 +-
 drivers/md/dm-zoned-target.c    | 2 +-
 22 files changed, 28 insertions(+), 33 deletions(-)

diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index 50f3e673729c3..104ebc1f08dcc 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -1525,7 +1525,7 @@ EXPORT_SYMBOL_GPL(dm_bufio_get_block_size);
 
 sector_t dm_bufio_get_device_size(struct dm_bufio_client *c)
 {
-	sector_t s = i_size_read(c->bdev->bd_inode) >> SECTOR_SHIFT;
+	sector_t s = bdev_nr_sectors(c->bdev);
 	if (s >= c->start)
 		s -= c->start;
 	else
diff --git a/drivers/md/dm-cache-metadata.c b/drivers/md/dm-cache-metadata.c
index 89a73204dbf47..2874f222c3138 100644
--- a/drivers/md/dm-cache-metadata.c
+++ b/drivers/md/dm-cache-metadata.c
@@ -334,7 +334,7 @@ static int __write_initial_superblock(struct dm_cache_metadata *cmd)
 	int r;
 	struct dm_block *sblock;
 	struct cache_disk_superblock *disk_super;
-	sector_t bdev_size = i_size_read(cmd->bdev->bd_inode) >> SECTOR_SHIFT;
+	sector_t bdev_size = bdev_nr_sectors(cmd->bdev);
 
 	/* FIXME: see if we can lose the max sectors limit */
 	if (bdev_size > DM_CACHE_METADATA_MAX_SECTORS)
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index bdd500447dea2..447d030036d18 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -1940,7 +1940,7 @@ static void cache_dtr(struct dm_target *ti)
 
 static sector_t get_dev_size(struct dm_dev *dev)
 {
-	return i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT;
+	return bdev_nr_sectors(dev->bdev);
 }
 
 /*----------------------------------------------------------------*/
diff --git a/drivers/md/dm-clone-target.c b/drivers/md/dm-clone-target.c
index 84dbe08ad2053..e4bb2fde1b54f 100644
--- a/drivers/md/dm-clone-target.c
+++ b/drivers/md/dm-clone-target.c
@@ -1514,7 +1514,7 @@ static void clone_status(struct dm_target *ti, status_type_t type,
 
 static sector_t get_dev_size(struct dm_dev *dev)
 {
-	return i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT;
+	return bdev_nr_sectors(dev->bdev);
 }
 
 /*---------------------------------------------------------------------------*/
diff --git a/drivers/md/dm-dust.c b/drivers/md/dm-dust.c
index 3163e2b1418e7..03672204b0e38 100644
--- a/drivers/md/dm-dust.c
+++ b/drivers/md/dm-dust.c
@@ -415,7 +415,7 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
 			char *result, unsigned int maxlen)
 {
 	struct dust_device *dd = ti->private;
-	sector_t size = i_size_read(dd->dev->bdev->bd_inode) >> SECTOR_SHIFT;
+	sector_t size = bdev_nr_sectors(dd->dev->bdev);
 	bool invalid_msg = false;
 	int r = -EINVAL;
 	unsigned long long tmp, block;
@@ -544,8 +544,7 @@ static int dust_prepare_ioctl(struct dm_target *ti, struct block_device **bdev)
 	/*
 	 * Only pass ioctls through if the device sizes match exactly.
 	 */
-	if (dd->start ||
-	    ti->len != i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT)
+	if (dd->start || ti->len != bdev_nr_sectors(dev->bdev))
 		return 1;
 
 	return 0;
diff --git a/drivers/md/dm-ebs-target.c b/drivers/md/dm-ebs-target.c
index d25989660a768..7ce5d509b9403 100644
--- a/drivers/md/dm-ebs-target.c
+++ b/drivers/md/dm-ebs-target.c
@@ -416,7 +416,7 @@ static int ebs_prepare_ioctl(struct dm_target *ti, struct block_device **bdev)
 	 * Only pass ioctls through if the device sizes match exactly.
 	 */
 	*bdev = dev->bdev;
-	return !!(ec->start || ti->len != i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT);
+	return !!(ec->start || ti->len != bdev_nr_sectors(dev->bdev));
 }
 
 static void ebs_io_hints(struct dm_target *ti, struct queue_limits *limits)
diff --git a/drivers/md/dm-era-target.c b/drivers/md/dm-era-target.c
index 2a78f68741431..1f6bf152b3c74 100644
--- a/drivers/md/dm-era-target.c
+++ b/drivers/md/dm-era-target.c
@@ -1681,7 +1681,7 @@ static int era_message(struct dm_target *ti, unsigned argc, char **argv,
 
 static sector_t get_dev_size(struct dm_dev *dev)
 {
-	return i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT;
+	return bdev_nr_sectors(dev->bdev);
 }
 
 static int era_iterate_devices(struct dm_target *ti,
diff --git a/drivers/md/dm-exception-store.h b/drivers/md/dm-exception-store.h
index 3f4139ac1f602..b5f20eba36415 100644
--- a/drivers/md/dm-exception-store.h
+++ b/drivers/md/dm-exception-store.h
@@ -168,7 +168,7 @@ static inline void dm_consecutive_chunk_count_dec(struct dm_exception *e)
  */
 static inline sector_t get_dev_size(struct block_device *bdev)
 {
-	return i_size_read(bdev->bd_inode) >> SECTOR_SHIFT;
+	return bdev_nr_sectors(bdev);
 }
 
 static inline chunk_t sector_to_chunk(struct dm_exception_store *store,
diff --git a/drivers/md/dm-flakey.c b/drivers/md/dm-flakey.c
index 4b94ffe6f2d4f..345229d7e59c1 100644
--- a/drivers/md/dm-flakey.c
+++ b/drivers/md/dm-flakey.c
@@ -456,8 +456,7 @@ static int flakey_prepare_ioctl(struct dm_target *ti, struct block_device **bdev
 	/*
 	 * Only pass ioctls through if the device sizes match exactly.
 	 */
-	if (fc->start ||
-	    ti->len != i_size_read((*bdev)->bd_inode) >> SECTOR_SHIFT)
+	if (fc->start || ti->len != bdev_nr_sectors((*bdev)))
 		return 1;
 	return 0;
 }
diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
index dc03b70f6e65c..d0f788e72abf9 100644
--- a/drivers/md/dm-integrity.c
+++ b/drivers/md/dm-integrity.c
@@ -4113,11 +4113,11 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
 		}
 	}
 
-	ic->data_device_sectors = i_size_read(ic->dev->bdev->bd_inode) >> SECTOR_SHIFT;
+	ic->data_device_sectors = bdev_nr_sectors(ic->dev->bdev);
 	if (!ic->meta_dev)
 		ic->meta_device_sectors = ic->data_device_sectors;
 	else
-		ic->meta_device_sectors = i_size_read(ic->meta_dev->bdev->bd_inode) >> SECTOR_SHIFT;
+		ic->meta_device_sectors = bdev_nr_sectors(ic->meta_dev->bdev);
 
 	if (!journal_sectors) {
 		journal_sectors = min((sector_t)DEFAULT_MAX_JOURNAL_SECTORS,
@@ -4367,7 +4367,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
 	DEBUG_print("	journal_sections %u\n", (unsigned)le32_to_cpu(ic->sb->journal_sections));
 	DEBUG_print("	journal_entries %u\n", ic->journal_entries);
 	DEBUG_print("	log2_interleave_sectors %d\n", ic->sb->log2_interleave_sectors);
-	DEBUG_print("	data_device_sectors 0x%llx\n", i_size_read(ic->dev->bdev->bd_inode) >> SECTOR_SHIFT);
+	DEBUG_print("	data_device_sectors 0x%llx\n", bdev_nr_sectors(ic->dev->bdev));
 	DEBUG_print("	initial_sectors 0x%x\n", ic->initial_sectors);
 	DEBUG_print("	metadata_run 0x%x\n", ic->metadata_run);
 	DEBUG_print("	log2_metadata_run %d\n", ic->log2_metadata_run);
diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c
index 679b4c0a2eea1..66ba16713f696 100644
--- a/drivers/md/dm-linear.c
+++ b/drivers/md/dm-linear.c
@@ -135,8 +135,7 @@ static int linear_prepare_ioctl(struct dm_target *ti, struct block_device **bdev
 	/*
 	 * Only pass ioctls through if the device sizes match exactly.
 	 */
-	if (lc->start ||
-	    ti->len != i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT)
+	if (lc->start || ti->len != bdev_nr_sectors(dev->bdev))
 		return 1;
 	return 0;
 }
diff --git a/drivers/md/dm-log-writes.c b/drivers/md/dm-log-writes.c
index d93a4db235124..46de085a96709 100644
--- a/drivers/md/dm-log-writes.c
+++ b/drivers/md/dm-log-writes.c
@@ -446,7 +446,7 @@ static int log_super(struct log_writes_c *lc)
 
 static inline sector_t logdev_last_sector(struct log_writes_c *lc)
 {
-	return i_size_read(lc->logdev->bdev->bd_inode) >> SECTOR_SHIFT;
+	return bdev_nr_sectors(lc->logdev->bdev);
 }
 
 static int log_writes_kthread(void *arg)
@@ -851,7 +851,7 @@ static int log_writes_prepare_ioctl(struct dm_target *ti,
 	/*
 	 * Only pass ioctls through if the device sizes match exactly.
 	 */
-	if (ti->len != i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT)
+	if (ti->len != bdev_nr_sectors(dev->bdev))
 		return 1;
 	return 0;
 }
diff --git a/drivers/md/dm-log.c b/drivers/md/dm-log.c
index 1ecf75ef276a4..a24d87aa7f556 100644
--- a/drivers/md/dm-log.c
+++ b/drivers/md/dm-log.c
@@ -447,7 +447,7 @@ static int create_log_context(struct dm_dirty_log *log, struct dm_target *ti,
 				bdev_logical_block_size(lc->header_location.
 							    bdev));
 
-		if (buf_size > i_size_read(dev->bdev->bd_inode)) {
+		if (buf_size > (bdev_nr_sectors(dev->bdev) << SECTOR_SHIFT)) {
 			DMWARN("log device %s too small: need %llu bytes",
 				dev->name, (unsigned long long)buf_size);
 			kfree(lc);
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 694aaca4eea24..5794f5415155d 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -2061,7 +2061,7 @@ static int multipath_prepare_ioctl(struct dm_target *ti,
 	/*
 	 * Only pass ioctls through if the device sizes match exactly.
 	 */
-	if (!r && ti->len != i_size_read((*bdev)->bd_inode) >> SECTOR_SHIFT)
+	if (!r && ti->len != bdev_nr_sectors((*bdev)))
 		return 1;
 	return r;
 }
diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index d9ef52159a22b..2b26435a6946e 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -1261,7 +1261,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,
 			md_rdev_init(jdev);
 			jdev->mddev = &rs->md;
 			jdev->bdev = rs->journal_dev.dev->bdev;
-			jdev->sectors = to_sector(i_size_read(jdev->bdev->bd_inode));
+			jdev->sectors = bdev_nr_sectors(jdev->bdev);
 			if (jdev->sectors < MIN_RAID456_JOURNAL_SPACE) {
 				rs->ti->error = "No space for raid4/5/6 journal";
 				return -ENOSPC;
@@ -1607,7 +1607,7 @@ static int _check_data_dev_sectors(struct raid_set *rs)
 
 	rdev_for_each(rdev, &rs->md)
 		if (!test_bit(Journal, &rdev->flags) && rdev->bdev) {
-			ds = min(ds, to_sector(i_size_read(rdev->bdev->bd_inode)));
+			ds = min(ds, bdev_nr_sectors(rdev->bdev));
 			if (ds < rs->md.dev_sectors) {
 				rs->ti->error = "Component device(s) too small";
 				return -EINVAL;
@@ -2662,7 +2662,7 @@ static int rs_adjust_data_offsets(struct raid_set *rs)
 	 * Make sure we got a minimum amount of free sectors per device
 	 */
 	if (rs->data_offset &&
-	    to_sector(i_size_read(rdev->bdev->bd_inode)) - rs->md.dev_sectors < MIN_FREE_RESHAPE_SPACE) {
+	    bdev_nr_sectors(rdev->bdev) - rs->md.dev_sectors < MIN_FREE_RESHAPE_SPACE) {
 		rs->ti->error = data_offset ? "No space for forward reshape" :
 					      "No space for backward reshape";
 		return -ENOSPC;
diff --git a/drivers/md/dm-switch.c b/drivers/md/dm-switch.c
index 028a92ff6d576..534dc2ca8bb06 100644
--- a/drivers/md/dm-switch.c
+++ b/drivers/md/dm-switch.c
@@ -529,7 +529,7 @@ static int switch_prepare_ioctl(struct dm_target *ti, struct block_device **bdev
 	 * Only pass ioctls through if the device sizes match exactly.
 	 */
 	if (ti->len + sctx->path_list[path_nr].start !=
-	    i_size_read((*bdev)->bd_inode) >> SECTOR_SHIFT)
+	    bdev_nr_sectors((*bdev)))
 		return 1;
 	return 0;
 }
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 1fa4d5582dca5..d95142102bd25 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -227,8 +227,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
 {
 	struct queue_limits *limits = data;
 	struct block_device *bdev = dev->bdev;
-	sector_t dev_size =
-		i_size_read(bdev->bd_inode) >> SECTOR_SHIFT;
+	sector_t dev_size = bdev_nr_sectors(bdev);
 	unsigned short logical_block_size_sectors =
 		limits->logical_block_size >> SECTOR_SHIFT;
 	char b[BDEVNAME_SIZE];
diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
index c88ed14d49e65..1a96a07cbf443 100644
--- a/drivers/md/dm-thin-metadata.c
+++ b/drivers/md/dm-thin-metadata.c
@@ -549,7 +549,7 @@ static int __write_initial_superblock(struct dm_pool_metadata *pmd)
 	int r;
 	struct dm_block *sblock;
 	struct thin_disk_superblock *disk_super;
-	sector_t bdev_size = i_size_read(pmd->bdev->bd_inode) >> SECTOR_SHIFT;
+	sector_t bdev_size = bdev_nr_sectors(pmd->bdev);
 
 	if (bdev_size > THIN_METADATA_MAX_SECTORS)
 		bdev_size = THIN_METADATA_MAX_SECTORS;
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index 4c67b77c23c1b..ec119d2422d5d 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -3212,7 +3212,7 @@ static int metadata_pre_commit_callback(void *context)
 
 static sector_t get_dev_size(struct block_device *bdev)
 {
-	return i_size_read(bdev->bd_inode) >> SECTOR_SHIFT;
+	return bdev_nr_sectors(bdev);
 }
 
 static void warn_if_metadata_device_too_big(struct block_device *bdev)
diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c
index 88e2702b473b0..4651859d4233b 100644
--- a/drivers/md/dm-verity-target.c
+++ b/drivers/md/dm-verity-target.c
@@ -825,8 +825,7 @@ static int verity_prepare_ioctl(struct dm_target *ti, struct block_device **bdev
 
 	*bdev = v->data_dev->bdev;
 
-	if (v->data_start ||
-	    ti->len != i_size_read(v->data_dev->bdev->bd_inode) >> SECTOR_SHIFT)
+	if (v->data_start || ti->len != bdev_nr_sectors(v->data_dev->bdev))
 		return 1;
 	return 0;
 }
diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c
index 18320444fb0a9..339f2319ae65a 100644
--- a/drivers/md/dm-writecache.c
+++ b/drivers/md/dm-writecache.c
@@ -2341,7 +2341,7 @@ static int writecache_ctr(struct dm_target *ti, unsigned argc, char **argv)
 		ti->error = "Cache data device lookup failed";
 		goto bad;
 	}
-	wc->memory_map_size = i_size_read(wc->ssd_dev->bdev->bd_inode);
+	wc->memory_map_size = bdev_nr_sectors(wc->ssd_dev->bdev) << SECTOR_SHIFT;
 
 	/*
 	 * Parse the cache block size
diff --git a/drivers/md/dm-zoned-target.c b/drivers/md/dm-zoned-target.c
index ae1bc48c0043d..8dc21c09329f2 100644
--- a/drivers/md/dm-zoned-target.c
+++ b/drivers/md/dm-zoned-target.c
@@ -733,7 +733,7 @@ static int dmz_get_zoned_device(struct dm_target *ti, char *path,
 	dev->dev_idx = idx;
 	(void)bdevname(dev->bdev, dev->name);
 
-	dev->capacity = i_size_read(bdev->bd_inode) >> SECTOR_SHIFT;
+	dev->capacity = bdev_nr_sectors(bdev);
 	if (ti->begin) {
 		ti->error = "Partial mapping is not supported";
 		goto err;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 04/29] md: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (2 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 03/29] dm: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  6:12   ` Kees Cook
  2021-10-13  5:10 ` [PATCH 05/29] mtd/block2mtd: " Christoph Hellwig
                   ` (27 subsequent siblings)
  31 siblings, 1 reply; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/md/md.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index ec09083ff0eff..9b4f4bf349120 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -890,8 +890,7 @@ static struct md_personality *find_pers(int level, char *clevel)
 /* return the offset of the super block in 512byte sectors */
 static inline sector_t calc_dev_sboffset(struct md_rdev *rdev)
 {
-	sector_t num_sectors = i_size_read(rdev->bdev->bd_inode) / 512;
-	return MD_NEW_SIZE_SECTORS(num_sectors);
+	return MD_NEW_SIZE_SECTORS(bdev_nr_sectors(rdev->bdev));
 }
 
 static int alloc_disk_sb(struct md_rdev *rdev)
@@ -1633,8 +1632,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
 	 */
 	switch(minor_version) {
 	case 0:
-		sb_start = i_size_read(rdev->bdev->bd_inode) >> 9;
-		sb_start -= 8*2;
+		sb_start = bdev_nr_sectors(rdev->bdev) - 8 * 2;
 		sb_start &= ~(sector_t)(4*2-1);
 		break;
 	case 1:
@@ -1789,10 +1787,9 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
 		else
 			ret = 0;
 	}
-	if (minor_version) {
-		sectors = (i_size_read(rdev->bdev->bd_inode) >> 9);
-		sectors -= rdev->data_offset;
-	} else
+	if (minor_version)
+		sectors = bdev_nr_sectors(rdev->bdev) - rdev->data_offset;
+	else
 		sectors = rdev->sb_start;
 	if (sectors < le64_to_cpu(sb->data_size))
 		return -EINVAL;
@@ -2170,8 +2167,7 @@ super_1_rdev_size_change(struct md_rdev *rdev, sector_t num_sectors)
 		return 0; /* too confusing */
 	if (rdev->sb_start < rdev->data_offset) {
 		/* minor versions 1 and 2; superblock before data */
-		max_sectors = i_size_read(rdev->bdev->bd_inode) >> 9;
-		max_sectors -= rdev->data_offset;
+		max_sectors = bdev_nr_sectors(rdev->bdev) - rdev->data_offset;
 		if (!num_sectors || num_sectors > max_sectors)
 			num_sectors = max_sectors;
 	} else if (rdev->mddev->bitmap_info.offset) {
@@ -2180,7 +2176,7 @@ super_1_rdev_size_change(struct md_rdev *rdev, sector_t num_sectors)
 	} else {
 		/* minor version 0; superblock after data */
 		sector_t sb_start, bm_space;
-		sector_t dev_size = i_size_read(rdev->bdev->bd_inode) >> 9;
+		sector_t dev_size = bdev_nr_sectors(rdev->bdev);
 
 		/* 8K is for superblock */
 		sb_start = dev_size - 8*2;
@@ -3384,7 +3380,7 @@ rdev_size_store(struct md_rdev *rdev, const char *buf, size_t len)
 			if (!sectors)
 				return -EBUSY;
 		} else if (!sectors)
-			sectors = (i_size_read(rdev->bdev->bd_inode) >> 9) -
+			sectors = bdev_nr_sectors(rdev->bdev) -
 				rdev->data_offset;
 		if (!my_mddev->pers->resize)
 			/* Cannot change size for RAID0 or Linear etc */
@@ -3711,7 +3707,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
 
 	kobject_init(&rdev->kobj, &rdev_ktype);
 
-	size = i_size_read(rdev->bdev->bd_inode) >> BLOCK_SIZE_BITS;
+	size = (bdev_nr_sectors(rdev->bdev) << SECTOR_SHIFT) >> BLOCK_SIZE_BITS;
 	if (!size) {
 		pr_warn("md: %s has zero or unknown size, marking faulty!\n",
 			bdevname(rdev->bdev,b));
@@ -6882,7 +6878,7 @@ int md_add_new_disk(struct mddev *mddev, struct mdu_disk_info_s *info)
 
 		if (!mddev->persistent) {
 			pr_debug("md: nonpersistent superblock ...\n");
-			rdev->sb_start = i_size_read(rdev->bdev->bd_inode) / 512;
+			rdev->sb_start = bdev_nr_sectors(rdev->bdev);
 		} else
 			rdev->sb_start = calc_dev_sboffset(rdev);
 		rdev->sectors = rdev->sb_start;
@@ -6969,7 +6965,7 @@ static int hot_add_disk(struct mddev *mddev, dev_t dev)
 	if (mddev->persistent)
 		rdev->sb_start = calc_dev_sboffset(rdev);
 	else
-		rdev->sb_start = i_size_read(rdev->bdev->bd_inode) / 512;
+		rdev->sb_start = bdev_nr_sectors(rdev->bdev);
 
 	rdev->sectors = rdev->sb_start;
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 05/29] mtd/block2mtd: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (3 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 04/29] md: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  5:10 ` [PATCH 06/29] nvmet: " Christoph Hellwig
                   ` (26 subsequent siblings)
  31 siblings, 0 replies; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/mtd/devices/block2mtd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index c08721b11642b..d2d1a712188ce 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -269,7 +269,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size,
 		goto err_free_block2mtd;
 	}
 
-	if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
+	if ((long)(bdev_nr_sectors(dev->blkdev) << SECTOR_SHIFT) % erase_size) {
 		pr_err("erasesize must be a divisor of device size\n");
 		goto err_free_block2mtd;
 	}
@@ -284,7 +284,8 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size,
 
 	dev->mtd.name = name;
 
-	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
+	dev->mtd.size =
+		(bdev_nr_sectors(dev->blkdev) << SECTOR_SHIFT) & PAGE_MASK;
 	dev->mtd.erasesize = erase_size;
 	dev->mtd.writesize = 1;
 	dev->mtd.writebufsize = PAGE_SIZE;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 06/29] nvmet: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (4 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 05/29] mtd/block2mtd: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13 22:33   ` Chaitanya Kulkarni
  2021-10-13  5:10 ` [PATCH 07/29] target/iblock: " Christoph Hellwig
                   ` (25 subsequent siblings)
  31 siblings, 1 reply; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/nvme/target/io-cmd-bdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c
index 6139e1de50a66..683246303f62e 100644
--- a/drivers/nvme/target/io-cmd-bdev.c
+++ b/drivers/nvme/target/io-cmd-bdev.c
@@ -87,7 +87,7 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns)
 		ns->bdev = NULL;
 		return ret;
 	}
-	ns->size = i_size_read(ns->bdev->bd_inode);
+	ns->size = bdev_nr_sectors(ns->bdev) << SECTOR_SHIFT;
 	ns->blksize_shift = blksize_bits(bdev_logical_block_size(ns->bdev));
 
 	ns->pi_type = 0;
@@ -108,7 +108,7 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns)
 
 void nvmet_bdev_ns_revalidate(struct nvmet_ns *ns)
 {
-	ns->size = i_size_read(ns->bdev->bd_inode);
+	ns->size = bdev_nr_sectors(ns->bdev) << SECTOR_SHIFT;
 }
 
 u16 blk_to_nvme_status(struct nvmet_req *req, blk_status_t blk_sts)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 07/29] target/iblock: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (5 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 06/29] nvmet: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  9:31   ` Bodo Stroesser
  2021-10-13 22:37   ` Chaitanya Kulkarni
  2021-10-13  5:10 ` [PATCH 08/29] fs: use bdev_nr_sectors instead of open coding it in blkdev_max_block Christoph Hellwig
                   ` (24 subsequent siblings)
  31 siblings, 2 replies; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/target/target_core_iblock.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c
index 31df20abe141f..ab7f5678ebc44 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -232,8 +232,9 @@ static unsigned long long iblock_emulate_read_cap_with_block_size(
 	struct block_device *bd,
 	struct request_queue *q)
 {
-	unsigned long long blocks_long = (div_u64(i_size_read(bd->bd_inode),
-					bdev_logical_block_size(bd)) - 1);
+	loff_t size = bdev_nr_sectors(bd) << SECTOR_SHIFT;
+	unsigned long long blocks_long =
+		div_u64(size, bdev_logical_block_size(bd)) - 1;
 	u32 block_size = bdev_logical_block_size(bd);
 
 	if (block_size == dev->dev_attrib.block_size)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 08/29] fs: use bdev_nr_sectors instead of open coding it in blkdev_max_block
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (6 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 07/29] target/iblock: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13 10:42   ` Jan Kara
  2021-10-13 22:35   ` Chaitanya Kulkarni
  2021-10-13  5:10 ` [PATCH 09/29] fs: simplify init_page_buffers Christoph Hellwig
                   ` (23 subsequent siblings)
  31 siblings, 2 replies; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index c615387aedcae..3fb9c5b457ab6 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -878,7 +878,7 @@ link_dev_buffers(struct page *page, struct buffer_head *head)
 static sector_t blkdev_max_block(struct block_device *bdev, unsigned int size)
 {
 	sector_t retval = ~((sector_t)0);
-	loff_t sz = i_size_read(bdev->bd_inode);
+	loff_t sz = bdev_nr_sectors(bdev) << SECTOR_SHIFT;
 
 	if (sz) {
 		unsigned int sizebits = blksize_bits(size);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 09/29] fs: simplify init_page_buffers
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (7 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 08/29] fs: use bdev_nr_sectors instead of open coding it in blkdev_max_block Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  6:14   ` Kees Cook
  2021-10-13 10:42   ` Jan Kara
  2021-10-13  5:10 ` [PATCH 10/29] affs: use bdev_nr_sectors instead of open coding it Christoph Hellwig
                   ` (22 subsequent siblings)
  31 siblings, 2 replies; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

No need to convert from bdev to inode and back.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index 3fb9c5b457ab6..ef1fe4f77a952 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -897,7 +897,7 @@ init_page_buffers(struct page *page, struct block_device *bdev,
 	struct buffer_head *head = page_buffers(page);
 	struct buffer_head *bh = head;
 	int uptodate = PageUptodate(page);
-	sector_t end_block = blkdev_max_block(I_BDEV(bdev->bd_inode), size);
+	sector_t end_block = blkdev_max_block(bdev, size);
 
 	do {
 		if (!buffer_mapped(bh)) {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 10/29] affs: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (8 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 09/29] fs: simplify init_page_buffers Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  6:14   ` Kees Cook
  2021-10-13  5:10 ` [PATCH 11/29] btrfs: " Christoph Hellwig
                   ` (21 subsequent siblings)
  31 siblings, 1 reply; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/affs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/affs/super.c b/fs/affs/super.c
index c6c2a513ec92d..c609005a9eaaa 100644
--- a/fs/affs/super.c
+++ b/fs/affs/super.c
@@ -389,7 +389,7 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
 	 * blocks, we will have to change it.
 	 */
 
-	size = i_size_read(sb->s_bdev->bd_inode) >> 9;
+	size = bdev_nr_sectors(sb->s_bdev);
 	pr_debug("initial blocksize=%d, #blocks=%d\n", 512, size);
 
 	affs_set_blocksize(sb, PAGE_SIZE);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 11/29] btrfs: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (9 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 10/29] affs: use bdev_nr_sectors instead of open coding it Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  7:08   ` Anand Jain
                     ` (2 more replies)
  2021-10-13  5:10 ` [PATCH 12/29] cramfs: " Christoph Hellwig
                   ` (20 subsequent siblings)
  31 siblings, 3 replies; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 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


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 12/29] cramfs: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (10 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 11/29] btrfs: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  6:16   ` Kees Cook
  2021-10-13  5:10 ` [PATCH 13/29] fat: " Christoph Hellwig
                   ` (19 subsequent siblings)
  31 siblings, 1 reply; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/cramfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c
index 2be65269a987c..3e44cc3ed0543 100644
--- a/fs/cramfs/inode.c
+++ b/fs/cramfs/inode.c
@@ -209,7 +209,7 @@ static void *cramfs_blkdev_read(struct super_block *sb, unsigned int offset,
 		return read_buffers[i] + blk_offset;
 	}
 
-	devsize = mapping->host->i_size >> PAGE_SHIFT;
+	devsize = bdev_nr_sectors(sb->s_bdev) >> (PAGE_SHIFT - SECTOR_SHIFT);
 
 	/* Ok, read in BLKS_PER_BUF pages completely first. */
 	for (i = 0; i < BLKS_PER_BUF; i++) {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 13/29] fat: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (11 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 12/29] cramfs: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  6:16   ` Kees Cook
  2021-10-13  5:10 ` [PATCH 14/29] hfs: " Christoph Hellwig
                   ` (18 subsequent siblings)
  31 siblings, 1 reply; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/fat/inode.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index de0c9b013a851..9f3cd03668adc 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -1536,14 +1536,11 @@ static int fat_read_static_bpb(struct super_block *sb,
 	struct fat_bios_param_block *bpb)
 {
 	static const char *notdos1x = "This doesn't look like a DOS 1.x volume";
-
+	sector_t bd_sects = bdev_nr_sectors(sb->s_bdev);
 	struct fat_floppy_defaults *fdefaults = NULL;
 	int error = -EINVAL;
-	sector_t bd_sects;
 	unsigned i;
 
-	bd_sects = i_size_read(sb->s_bdev->bd_inode) / SECTOR_SIZE;
-
 	/* 16-bit DOS 1.x reliably wrote bootstrap short-jmp code */
 	if (b->ignored[0] != 0xeb || b->ignored[2] != 0x90) {
 		if (!silent)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 14/29] hfs: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (12 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 13/29] fat: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  6:16   ` Kees Cook
  2021-10-13  5:10 ` [PATCH 15/29] hfsplus: " Christoph Hellwig
                   ` (17 subsequent siblings)
  31 siblings, 1 reply; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/hfs/mdb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/hfs/mdb.c b/fs/hfs/mdb.c
index cdf0edeeb2781..5beb826524354 100644
--- a/fs/hfs/mdb.c
+++ b/fs/hfs/mdb.c
@@ -36,7 +36,7 @@ static int hfs_get_last_session(struct super_block *sb,
 
 	/* default values */
 	*start = 0;
-	*size = i_size_read(sb->s_bdev->bd_inode) >> 9;
+	*size = bdev_nr_sectors(sb->s_bdev);
 
 	if (HFS_SB(sb)->session >= 0) {
 		struct cdrom_tocentry te;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 15/29] hfsplus: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (13 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 14/29] hfs: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  6:16   ` Kees Cook
  2021-10-13  5:10 ` [PATCH 16/29] jfs: " Christoph Hellwig
                   ` (16 subsequent siblings)
  31 siblings, 1 reply; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/hfsplus/wrapper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/hfsplus/wrapper.c b/fs/hfsplus/wrapper.c
index 0350dc7821bf9..51ae6f1eb4a55 100644
--- a/fs/hfsplus/wrapper.c
+++ b/fs/hfsplus/wrapper.c
@@ -131,7 +131,7 @@ static int hfsplus_get_last_session(struct super_block *sb,
 
 	/* default values */
 	*start = 0;
-	*size = i_size_read(sb->s_bdev->bd_inode) >> 9;
+	*size = bdev_nr_sectors(sb->s_bdev);
 
 	if (HFSPLUS_SB(sb)->session >= 0) {
 		struct cdrom_tocentry te;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 16/29] jfs: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (14 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 15/29] hfsplus: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13 14:13   ` Dave Kleikamp
  2021-10-13  5:10 ` [PATCH 17/29] nfs/blocklayout: " Christoph Hellwig
                   ` (15 subsequent siblings)
  31 siblings, 1 reply; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/jfs/resize.c | 2 +-
 fs/jfs/super.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/jfs/resize.c b/fs/jfs/resize.c
index bde787c354fcc..51a8b22e71030 100644
--- a/fs/jfs/resize.c
+++ b/fs/jfs/resize.c
@@ -199,7 +199,7 @@ int jfs_extendfs(struct super_block *sb, s64 newLVSize, int newLogSize)
 	txQuiesce(sb);
 
 	/* Reset size of direct inode */
-	sbi->direct_inode->i_size =  i_size_read(sb->s_bdev->bd_inode);
+	sbi->direct_inode->i_size = bdev_nr_sectors(sb->s_bdev) << SECTOR_SHIFT;
 
 	if (sbi->mntflag & JFS_INLINELOG) {
 		/*
diff --git a/fs/jfs/super.c b/fs/jfs/super.c
index 9030aeaf0f886..992870160903d 100644
--- a/fs/jfs/super.c
+++ b/fs/jfs/super.c
@@ -551,7 +551,7 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
 		ret = -ENOMEM;
 		goto out_unload;
 	}
-	inode->i_size = i_size_read(sb->s_bdev->bd_inode);
+	inode->i_size = bdev_nr_sectors(sb->s_bdev) << SECTOR_SHIFT;
 	inode->i_mapping->a_ops = &jfs_metapage_aops;
 	inode_fake_hash(inode);
 	mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 17/29] nfs/blocklayout: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (15 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 16/29] jfs: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  5:10 ` [PATCH 18/29] nilfs2: " Christoph Hellwig
                   ` (14 subsequent siblings)
  31 siblings, 0 replies; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/nfs/blocklayout/dev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/nfs/blocklayout/dev.c b/fs/nfs/blocklayout/dev.c
index acb1d22907daf..42772985cb43e 100644
--- a/fs/nfs/blocklayout/dev.c
+++ b/fs/nfs/blocklayout/dev.c
@@ -252,7 +252,7 @@ bl_parse_simple(struct nfs_server *server, struct pnfs_block_dev *d,
 	d->bdev = bdev;
 
 
-	d->len = i_size_read(d->bdev->bd_inode);
+	d->len = bdev_nr_sectors(d->bdev) << SECTOR_SHIFT;
 	d->map = bl_map_simple;
 
 	printk(KERN_INFO "pNFS: using block device %s\n",
@@ -367,7 +367,7 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d,
 		return PTR_ERR(bdev);
 	d->bdev = bdev;
 
-	d->len = i_size_read(d->bdev->bd_inode);
+	d->len = bdev_nr_sectors(d->bdev) << SECTOR_SHIFT;
 	d->map = bl_map_simple;
 	d->pr_key = v->scsi.pr_key;
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 18/29] nilfs2: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (16 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 17/29] nfs/blocklayout: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  5:10 ` [PATCH 19/29] ntfs3: " Christoph Hellwig
                   ` (13 subsequent siblings)
  31 siblings, 0 replies; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/nilfs2/ioctl.c     | 2 +-
 fs/nilfs2/super.c     | 2 +-
 fs/nilfs2/the_nilfs.c | 3 ++-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
index 640ac8fe891e6..4c12cc0e265e1 100644
--- a/fs/nilfs2/ioctl.c
+++ b/fs/nilfs2/ioctl.c
@@ -1107,7 +1107,7 @@ static int nilfs_ioctl_set_alloc_range(struct inode *inode, void __user *argp)
 		goto out;
 
 	ret = -ERANGE;
-	if (range[1] > i_size_read(inode->i_sb->s_bdev->bd_inode))
+	if (range[1] > (bdev_nr_sectors(inode->i_sb->s_bdev) << SECTOR_SHIFT))
 		goto out;
 
 	segbytes = nilfs->ns_blocks_per_segment * nilfs->ns_blocksize;
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index f6b2d280aab5a..1842663339acc 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -403,7 +403,7 @@ int nilfs_resize_fs(struct super_block *sb, __u64 newsize)
 	int ret;
 
 	ret = -ERANGE;
-	devsize = i_size_read(sb->s_bdev->bd_inode);
+	devsize = bdev_nr_sectors(sb->s_bdev) << SECTOR_SHIFT;
 	if (newsize > devsize)
 		goto out;
 
diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c
index c8bfc01da5d71..d68df998213e9 100644
--- a/fs/nilfs2/the_nilfs.c
+++ b/fs/nilfs2/the_nilfs.c
@@ -489,7 +489,8 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs,
 {
 	struct nilfs_super_block **sbp = nilfs->ns_sbp;
 	struct buffer_head **sbh = nilfs->ns_sbh;
-	u64 sb2off = NILFS_SB2_OFFSET_BYTES(nilfs->ns_bdev->bd_inode->i_size);
+	loff_t size = bdev_nr_sectors(nilfs->ns_bdev) << SECTOR_SHIFT;
+	u64 sb2off = NILFS_SB2_OFFSET_BYTES(size);
 	int valid[2], swp = 0;
 
 	sbp[0] = nilfs_read_super_block(sb, NILFS_SB_OFFSET_BYTES, blocksize,
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 19/29] ntfs3: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (17 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 18/29] nilfs2: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  5:10 ` [PATCH 20/29] pstore/blk: " Christoph Hellwig
                   ` (12 subsequent siblings)
  31 siblings, 0 replies; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/ntfs3/super.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c
index 55bbc9200a10e..b9782b57a4036 100644
--- a/fs/ntfs3/super.c
+++ b/fs/ntfs3/super.c
@@ -918,7 +918,6 @@ static int ntfs_fill_super(struct super_block *sb, void *data, int silent)
 	int err;
 	struct ntfs_sb_info *sbi;
 	struct block_device *bdev = sb->s_bdev;
-	struct inode *bd_inode = bdev->bd_inode;
 	struct request_queue *rq = bdev_get_queue(bdev);
 	struct inode *inode = NULL;
 	struct ntfs_inode *ni;
@@ -967,7 +966,7 @@ static int ntfs_fill_super(struct super_block *sb, void *data, int silent)
 
 	/* Parse boot. */
 	err = ntfs_init_from_boot(sb, rq ? queue_logical_block_size(rq) : 512,
-				  bd_inode->i_size);
+				  bdev_nr_sectors(bdev) << SECTOR_SHIFT);
 	if (err)
 		goto out;
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 20/29] pstore/blk: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (18 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 19/29] ntfs3: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  5:10 ` [PATCH 21/29] reiserfs: " Christoph Hellwig
                   ` (11 subsequent siblings)
  31 siblings, 0 replies; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/pstore/blk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/pstore/blk.c b/fs/pstore/blk.c
index 04ce58c939a0b..f43009cb2ec82 100644
--- a/fs/pstore/blk.c
+++ b/fs/pstore/blk.c
@@ -223,8 +223,8 @@ static int __register_pstore_blk(struct pstore_device_info *dev,
 		goto err_fput;
 	}
 
-	inode = I_BDEV(psblk_file->f_mapping->host)->bd_inode;
-	dev->zone.total_size = i_size_read(inode);
+	inode = psblk_file->f_mapping->host;
+	dev->zone.total_size = bdev_nr_sectors(I_BDEV(inode)) << SECTOR_SHIFT;
 
 	ret = __register_pstore_device(dev);
 	if (ret)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 21/29] reiserfs: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (19 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 20/29] pstore/blk: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13 10:43   ` Jan Kara
  2021-10-13  5:10 ` [PATCH 22/29] squashfs: " Christoph Hellwig
                   ` (10 subsequent siblings)
  31 siblings, 1 reply; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size and remove two
cargo culted checks that can't be false.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/reiserfs/super.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
index 58481f8d63d5b..6c9681e2809f0 100644
--- a/fs/reiserfs/super.c
+++ b/fs/reiserfs/super.c
@@ -1986,8 +1986,7 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
 	 * smaller than the filesystem. If the check fails then abort and
 	 * scream, because bad stuff will happen otherwise.
 	 */
-	if (s->s_bdev && s->s_bdev->bd_inode
-	    && i_size_read(s->s_bdev->bd_inode) <
+	if ((bdev_nr_sectors(s->s_bdev) << SECTOR_SHIFT) <
 	    sb_block_count(rs) * sb_blocksize(rs)) {
 		SWARN(silent, s, "", "Filesystem cannot be "
 		      "mounted because it is bigger than the device");
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 22/29] squashfs: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (20 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 21/29] reiserfs: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13 19:37   ` Phillip Lougher
  2021-10-13  5:10 ` [PATCH 23/29] block: use bdev_nr_sectors instead of open coding it in blkdev_fallocate Christoph Hellwig
                   ` (9 subsequent siblings)
  31 siblings, 1 reply; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/squashfs/super.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c
index 60d6951915f44..e83042ecf0d86 100644
--- a/fs/squashfs/super.c
+++ b/fs/squashfs/super.c
@@ -16,6 +16,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/blkdev.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
 #include <linux/fs_parser.h>
@@ -179,8 +180,8 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)
 	/* Check the filesystem does not extend beyond the end of the
 	   block device */
 	msblk->bytes_used = le64_to_cpu(sblk->bytes_used);
-	if (msblk->bytes_used < 0 || msblk->bytes_used >
-			i_size_read(sb->s_bdev->bd_inode))
+	if (msblk->bytes_used < 0 ||
+	    msblk->bytes_used > (bdev_nr_sectors(sb->s_bdev) << SECTOR_SHIFT))
 		goto failed_mount;
 
 	/* Check block size for sanity */
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 23/29] block: use bdev_nr_sectors instead of open coding it in blkdev_fallocate
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (21 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 22/29] squashfs: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13 10:44   ` Jan Kara
  2021-10-13 22:34   ` Chaitanya Kulkarni
  2021-10-13  5:10 ` [PATCH 24/29] block: add a sb_bdev_nr_blocks helper Christoph Hellwig
                   ` (8 subsequent siblings)
  31 siblings, 2 replies; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/fops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/fops.c b/block/fops.c
index 7bb9581a146cf..6e27dd2748504 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -548,7 +548,7 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start,
 		return -EOPNOTSUPP;
 
 	/* Don't go off the end of the device. */
-	isize = i_size_read(bdev->bd_inode);
+	isize = bdev_nr_sectors(bdev) << SECTOR_SHIFT;
 	if (start >= isize)
 		return -EINVAL;
 	if (end >= isize) {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 24/29] block: add a sb_bdev_nr_blocks helper
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (22 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 23/29] block: use bdev_nr_sectors instead of open coding it in blkdev_fallocate Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  6:27   ` Kees Cook
  2021-10-13  5:10 ` [PATCH 25/29] ext4: use sb_bdev_nr_blocks Christoph Hellwig
                   ` (7 subsequent siblings)
  31 siblings, 1 reply; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Add a helper to return the size of sb->s_bdev in sb->s_blocksize_bits
based unites.  Note that SECTOR_SHIFT has to be open coded due to
include dependency issues for now, but I have a plan to sort that out
eventually.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 include/linux/genhd.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 082a3e5fd8fa1..6eaef8fa78bcd 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -245,6 +245,12 @@ static inline sector_t get_capacity(struct gendisk *disk)
 	return bdev_nr_sectors(disk->part0);
 }
 
+static inline u64 sb_bdev_nr_blocks(struct super_block *sb)
+{
+	return bdev_nr_sectors(sb->s_bdev) >>
+		(sb->s_blocksize_bits - 9 /* SECTOR_SHIFT */);
+}
+
 int bdev_disk_changed(struct gendisk *disk, bool invalidate);
 void blk_drop_partitions(struct gendisk *disk);
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 25/29] ext4: use sb_bdev_nr_blocks
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (23 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 24/29] block: add a sb_bdev_nr_blocks helper Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  6:29   ` Kees Cook
                     ` (3 more replies)
  2021-10-13  5:10 ` [PATCH 26/29] jfs: " Christoph Hellwig
                   ` (6 subsequent siblings)
  31 siblings, 4 replies; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the sb_bdev_nr_blocks helper instead of open coding it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/ext4/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 0775950ee84e3..3dde8be5df490 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -4468,7 +4468,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 		goto cantfind_ext4;
 
 	/* check blocks count against device size */
-	blocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits;
+	blocks_count = sb_bdev_nr_blocks(sb);
 	if (blocks_count && ext4_blocks_count(es) > blocks_count) {
 		ext4_msg(sb, KERN_WARNING, "bad geometry: block count %llu "
 		       "exceeds size of device (%llu blocks)",
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 26/29] jfs: use sb_bdev_nr_blocks
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (24 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 25/29] ext4: use sb_bdev_nr_blocks Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  6:31   ` Kees Cook
  2021-10-13  5:10 ` [PATCH 27/29] ntfs: " Christoph Hellwig
                   ` (5 subsequent siblings)
  31 siblings, 1 reply; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the sb_bdev_nr_blocks helper instead of open coding it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/jfs/resize.c | 3 +--
 fs/jfs/super.c  | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/jfs/resize.c b/fs/jfs/resize.c
index 51a8b22e71030..f23445fa4b417 100644
--- a/fs/jfs/resize.c
+++ b/fs/jfs/resize.c
@@ -86,8 +86,7 @@ int jfs_extendfs(struct super_block *sb, s64 newLVSize, int newLogSize)
 		goto out;
 	}
 
-	VolumeSize = i_size_read(sb->s_bdev->bd_inode) >> sb->s_blocksize_bits;
-
+	VolumeSize = sb_bdev_nr_blocks(sb);
 	if (VolumeSize) {
 		if (newLVSize > VolumeSize) {
 			printk(KERN_WARNING "jfs_extendfs: invalid size\n");
diff --git a/fs/jfs/super.c b/fs/jfs/super.c
index 992870160903d..fecef43f94ae8 100644
--- a/fs/jfs/super.c
+++ b/fs/jfs/super.c
@@ -284,8 +284,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
 		}
 		case Opt_resize_nosize:
 		{
-			*newLVSize = i_size_read(sb->s_bdev->bd_inode) >>
-				sb->s_blocksize_bits;
+			*newLVSize = sb_bdev_nr_blocks(sb);
 			if (*newLVSize == 0)
 				pr_err("JFS: Cannot determine volume size\n");
 			break;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 27/29] ntfs: use sb_bdev_nr_blocks
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (25 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 26/29] jfs: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  6:33   ` Kees Cook
  2021-10-13  5:10 ` [PATCH 28/29] reiserfs: " Christoph Hellwig
                   ` (4 subsequent siblings)
  31 siblings, 1 reply; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the sb_bdev_nr_blocks helper instead of open coding it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/ntfs/super.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
index 0d7e948cb29c9..5ae8de09b271b 100644
--- a/fs/ntfs/super.c
+++ b/fs/ntfs/super.c
@@ -2772,13 +2772,12 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
 	ntfs_debug("Set device block size to %i bytes (block size bits %i).",
 			blocksize, sb->s_blocksize_bits);
 	/* Determine the size of the device in units of block_size bytes. */
-	if (!i_size_read(sb->s_bdev->bd_inode)) {
+	vol->nr_blocks = sb_bdev_nr_blocks(sb);
+	if (!vol->nr_blocks) {
 		if (!silent)
 			ntfs_error(sb, "Unable to determine device size.");
 		goto err_out_now;
 	}
-	vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >>
-			sb->s_blocksize_bits;
 	/* Read the boot sector and return unlocked buffer head to it. */
 	if (!(bh = read_ntfs_boot_sector(sb, silent))) {
 		if (!silent)
@@ -2816,8 +2815,7 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
 			goto err_out_now;
 		}
 		BUG_ON(blocksize != sb->s_blocksize);
-		vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >>
-				sb->s_blocksize_bits;
+		vol->nr_blocks = sb_bdev_nr_blocks(sb);
 		ntfs_debug("Changed device block size to %i bytes (block size "
 				"bits %i) to match volume sector size.",
 				blocksize, sb->s_blocksize_bits);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 28/29] reiserfs: use sb_bdev_nr_blocks
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (26 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 27/29] ntfs: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  6:33   ` Kees Cook
  2021-10-13 10:46   ` Jan Kara
  2021-10-13  5:10 ` [PATCH 29/29] udf: " Christoph Hellwig
                   ` (3 subsequent siblings)
  31 siblings, 2 replies; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the sb_bdev_nr_blocks helper instead of open coding it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/reiserfs/super.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
index 6c9681e2809f0..b12baadb7e9bb 100644
--- a/fs/reiserfs/super.c
+++ b/fs/reiserfs/super.c
@@ -1199,9 +1199,7 @@ static int reiserfs_parse_options(struct super_block *s,
 
 			if (!strcmp(arg, "auto")) {
 				/* From JFS code, to auto-get the size. */
-				*blocks =
-				    i_size_read(s->s_bdev->bd_inode) >> s->
-				    s_blocksize_bits;
+				*blocks = sb_bdev_nr_blocks(s);
 			} else {
 				*blocks = simple_strtoul(arg, &p, 0);
 				if (*p != '\0') {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 29/29] udf: use sb_bdev_nr_blocks
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (27 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 28/29] reiserfs: " Christoph Hellwig
@ 2021-10-13  5:10 ` Christoph Hellwig
  2021-10-13  6:34   ` Kees Cook
  2021-10-13 10:47   ` Jan Kara
  2021-10-13  6:39 ` don't use ->bd_inode to access the block device size Kees Cook
                   ` (2 subsequent siblings)
  31 siblings, 2 replies; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-13  5:10 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

Use the sb_bdev_nr_blocks helper instead of open coding it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/udf/lowlevel.c | 5 ++---
 fs/udf/super.c    | 9 +++------
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/fs/udf/lowlevel.c b/fs/udf/lowlevel.c
index f1094cdcd6cde..46d6971721975 100644
--- a/fs/udf/lowlevel.c
+++ b/fs/udf/lowlevel.c
@@ -47,8 +47,7 @@ unsigned int udf_get_last_session(struct super_block *sb)
 
 unsigned long udf_get_last_block(struct super_block *sb)
 {
-	struct block_device *bdev = sb->s_bdev;
-	struct cdrom_device_info *cdi = disk_to_cdi(bdev->bd_disk);
+	struct cdrom_device_info *cdi = disk_to_cdi(sb->s_bdev->bd_disk);
 	unsigned long lblock = 0;
 
 	/*
@@ -56,7 +55,7 @@ unsigned long udf_get_last_block(struct super_block *sb)
 	 * Try using the device size...
 	 */
 	if (!cdi || cdrom_get_last_written(cdi, &lblock) || lblock == 0)
-		lblock = i_size_read(bdev->bd_inode) >> sb->s_blocksize_bits;
+		lblock = sb_bdev_nr_blocks(sb);
 
 	if (lblock)
 		return lblock - 1;
diff --git a/fs/udf/super.c b/fs/udf/super.c
index b2d7c57d06881..34247fba6df91 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -1175,8 +1175,7 @@ static int udf_load_vat(struct super_block *sb, int p_index, int type1_index)
 	struct udf_inode_info *vati;
 	uint32_t pos;
 	struct virtualAllocationTable20 *vat20;
-	sector_t blocks = i_size_read(sb->s_bdev->bd_inode) >>
-			  sb->s_blocksize_bits;
+	sector_t blocks = sb_bdev_nr_blocks(sb);
 
 	udf_find_vat_block(sb, p_index, type1_index, sbi->s_last_block);
 	if (!sbi->s_vat_inode &&
@@ -1838,8 +1837,7 @@ static int udf_check_anchor_block(struct super_block *sb, sector_t block,
 	int ret;
 
 	if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV) &&
-	    udf_fixed_to_variable(block) >=
-	    i_size_read(sb->s_bdev->bd_inode) >> sb->s_blocksize_bits)
+	    udf_fixed_to_variable(block) >= sb_bdev_nr_blocks(sb))
 		return -EAGAIN;
 
 	bh = udf_read_tagged(sb, block, block, &ident);
@@ -1901,8 +1899,7 @@ static int udf_scan_anchors(struct super_block *sb, sector_t *lastblock,
 		last[last_count++] = *lastblock - 152;
 
 	for (i = 0; i < last_count; i++) {
-		if (last[i] >= i_size_read(sb->s_bdev->bd_inode) >>
-				sb->s_blocksize_bits)
+		if (last[i] >= sb_bdev_nr_blocks(sb))
 			continue;
 		ret = udf_check_anchor_block(sb, last[i], fileset);
 		if (ret != -EAGAIN) {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 76+ messages in thread

* Re: [PATCH 01/29] bcache: remove bdev_sectors
  2021-10-13  5:10 ` [PATCH 01/29] bcache: remove bdev_sectors Christoph Hellwig
@ 2021-10-13  5:21   ` Coly Li
  2021-10-13  6:09   ` Kees Cook
  1 sibling, 0 replies; 76+ messages in thread
From: Coly Li @ 2021-10-13  5:21 UTC (permalink / raw)
  To: Christoph Hellwig, Jens Axboe
  Cc: 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On 10/13/21 1:10 PM, Christoph Hellwig wrote:
> Use the equivalent block layer helper instead.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Acked-by: Coly Li <colyli@suse.de>

Thanks.

Coly Li

> ---
>   drivers/md/bcache/super.c     | 2 +-
>   drivers/md/bcache/util.h      | 4 ----
>   drivers/md/bcache/writeback.c | 2 +-
>   3 files changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index f2874c77ff797..4f89985abe4b7 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -1002,7 +1002,7 @@ static void calc_cached_dev_sectors(struct cache_set *c)
>   	struct cached_dev *dc;
>   
>   	list_for_each_entry(dc, &c->cached_devs, list)
> -		sectors += bdev_sectors(dc->bdev);
> +		sectors += bdev_nr_sectors(dc->bdev);
>   
>   	c->cached_dev_sectors = sectors;
>   }
> diff --git a/drivers/md/bcache/util.h b/drivers/md/bcache/util.h
> index b64460a762677..a7da7930a7fda 100644
> --- a/drivers/md/bcache/util.h
> +++ b/drivers/md/bcache/util.h
> @@ -584,8 +584,4 @@ static inline unsigned int fract_exp_two(unsigned int x,
>   void bch_bio_map(struct bio *bio, void *base);
>   int bch_bio_alloc_pages(struct bio *bio, gfp_t gfp_mask);
>   
> -static inline sector_t bdev_sectors(struct block_device *bdev)
> -{
> -	return bdev->bd_inode->i_size >> 9;
> -}
>   #endif /* _BCACHE_UTIL_H */
> diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
> index 8120da278161e..c7560f66dca88 100644
> --- a/drivers/md/bcache/writeback.c
> +++ b/drivers/md/bcache/writeback.c
> @@ -45,7 +45,7 @@ static uint64_t __calc_target_rate(struct cached_dev *dc)
>   	 * backing volume uses about 2% of the cache for dirty data.
>   	 */
>   	uint32_t bdev_share =
> -		div64_u64(bdev_sectors(dc->bdev) << WRITEBACK_SHARE_SHIFT,
> +		div64_u64(bdev_nr_sectors(dc->bdev) << WRITEBACK_SHARE_SHIFT,
>   				c->cached_dev_sectors);
>   
>   	uint64_t cache_dirty_target =


^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 01/29] bcache: remove bdev_sectors
  2021-10-13  5:10 ` [PATCH 01/29] bcache: remove bdev_sectors Christoph Hellwig
  2021-10-13  5:21   ` Coly Li
@ 2021-10-13  6:09   ` Kees Cook
  1 sibling, 0 replies; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:09 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:14AM +0200, Christoph Hellwig wrote:
> Use the equivalent block layer helper instead.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 02/29] drbd: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 02/29] drbd: use bdev_nr_sectors instead of open coding it Christoph Hellwig
@ 2021-10-13  6:09   ` Kees Cook
  2021-10-13 22:33   ` Chaitanya Kulkarni
  1 sibling, 0 replies; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:09 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:15AM +0200, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 03/29] dm: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 03/29] dm: " Christoph Hellwig
@ 2021-10-13  6:10   ` Kees Cook
  2021-10-13 16:43   ` Mike Snitzer
  1 sibling, 0 replies; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:10 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:16AM +0200, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 04/29] md: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 04/29] md: " Christoph Hellwig
@ 2021-10-13  6:12   ` Kees Cook
  2021-10-13 21:14     ` Song Liu
  0 siblings, 1 reply; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:12 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:17AM +0200, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

I think it might make sense, as you suggest earlier, to add a "bytes"
helper. This is the first user in the series needing:

	bdev_nr_sectors(...bdev) << SECTOR_SHIFT

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 09/29] fs: simplify init_page_buffers
  2021-10-13  5:10 ` [PATCH 09/29] fs: simplify init_page_buffers Christoph Hellwig
@ 2021-10-13  6:14   ` Kees Cook
  2021-10-13 10:42   ` Jan Kara
  1 sibling, 0 replies; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:14 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:22AM +0200, Christoph Hellwig wrote:
> No need to convert from bdev to inode and back.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 10/29] affs: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 10/29] affs: use bdev_nr_sectors instead of open coding it Christoph Hellwig
@ 2021-10-13  6:14   ` Kees Cook
  0 siblings, 0 replies; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:14 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:23AM +0200, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 12/29] cramfs: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 12/29] cramfs: " Christoph Hellwig
@ 2021-10-13  6:16   ` Kees Cook
  0 siblings, 0 replies; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:16 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:25AM +0200, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/cramfs/inode.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c
> index 2be65269a987c..3e44cc3ed0543 100644
> --- a/fs/cramfs/inode.c
> +++ b/fs/cramfs/inode.c
> @@ -209,7 +209,7 @@ static void *cramfs_blkdev_read(struct super_block *sb, unsigned int offset,
>  		return read_buffers[i] + blk_offset;
>  	}
>  
> -	devsize = mapping->host->i_size >> PAGE_SHIFT;
> +	devsize = bdev_nr_sectors(sb->s_bdev) >> (PAGE_SHIFT - SECTOR_SHIFT);

I find this less readable than "bytes >> PAGE_SHIFT". I'd suggest this
use a new bdev_nr_bytes() helper.

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 13/29] fat: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 13/29] fat: " Christoph Hellwig
@ 2021-10-13  6:16   ` Kees Cook
  0 siblings, 0 replies; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:16 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:26AM +0200, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 14/29] hfs: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 14/29] hfs: " Christoph Hellwig
@ 2021-10-13  6:16   ` Kees Cook
  0 siblings, 0 replies; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:16 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:27AM +0200, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 15/29] hfsplus: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 15/29] hfsplus: " Christoph Hellwig
@ 2021-10-13  6:16   ` Kees Cook
  0 siblings, 0 replies; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:16 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:28AM +0200, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 24/29] block: add a sb_bdev_nr_blocks helper
  2021-10-13  5:10 ` [PATCH 24/29] block: add a sb_bdev_nr_blocks helper Christoph Hellwig
@ 2021-10-13  6:27   ` Kees Cook
  0 siblings, 0 replies; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:27 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:37AM +0200, Christoph Hellwig wrote:
> Add a helper to return the size of sb->s_bdev in sb->s_blocksize_bits
> based unites.  Note that SECTOR_SHIFT has to be open coded due to
> include dependency issues for now, but I have a plan to sort that out
> eventually.

Wouldn't that just need a quick lift into a new header file to be
included by genhd.h, blkev.h, and:

drivers/mtd/ssfdc.c:#define SECTOR_SHIFT                9
fs/hfsplus/hfsplus_raw.h:#define HFSPLUS_SECTOR_SHIFT         9

I think that's worth doing at some point in this series since genhd.h
already has existing open-coded "9"s. And, really, a *lot* of other
places too:

$ git grep -E '(<<|>>) 9' | grep -E '\b(block|blk|sector|bdev)\b' | wc -l
240

> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  include/linux/genhd.h | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/include/linux/genhd.h b/include/linux/genhd.h
> index 082a3e5fd8fa1..6eaef8fa78bcd 100644
> --- a/include/linux/genhd.h
> +++ b/include/linux/genhd.h
> @@ -245,6 +245,12 @@ static inline sector_t get_capacity(struct gendisk *disk)
>  	return bdev_nr_sectors(disk->part0);
>  }
>  
> +static inline u64 sb_bdev_nr_blocks(struct super_block *sb)
> +{
> +	return bdev_nr_sectors(sb->s_bdev) >>
> +		(sb->s_blocksize_bits - 9 /* SECTOR_SHIFT */);
> +}
> +
>  int bdev_disk_changed(struct gendisk *disk, bool invalidate);
>  void blk_drop_partitions(struct gendisk *disk);
>  
> -- 
> 2.30.2
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 25/29] ext4: use sb_bdev_nr_blocks
  2021-10-13  5:10 ` [PATCH 25/29] ext4: use sb_bdev_nr_blocks Christoph Hellwig
@ 2021-10-13  6:29   ` Kees Cook
  2021-10-13  6:30   ` Kees Cook
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:29 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:38AM +0200, Christoph Hellwig wrote:
> Use the sb_bdev_nr_blocks helper instead of open coding it.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/ext4/super.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 0775950ee84e3..3dde8be5df490 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -4468,7 +4468,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
>  		goto cantfind_ext4;
>  
>  	/* check blocks count against device size */
> -	blocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits;
> +	blocks_count = sb_bdev_nr_blocks(sb);

Is s_blocksize_bits always 9 here? If not, this isn't equivalent.

-Kees

>  	if (blocks_count && ext4_blocks_count(es) > blocks_count) {
>  		ext4_msg(sb, KERN_WARNING, "bad geometry: block count %llu "
>  		       "exceeds size of device (%llu blocks)",
> -- 
> 2.30.2
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 25/29] ext4: use sb_bdev_nr_blocks
  2021-10-13  5:10 ` [PATCH 25/29] ext4: use sb_bdev_nr_blocks Christoph Hellwig
  2021-10-13  6:29   ` Kees Cook
@ 2021-10-13  6:30   ` Kees Cook
  2021-10-13 10:46   ` Jan Kara
  2021-10-13 15:51   ` Theodore Ts'o
  3 siblings, 0 replies; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:30 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:38AM +0200, Christoph Hellwig wrote:
> Use the sb_bdev_nr_blocks helper instead of open coding it.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/ext4/super.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 0775950ee84e3..3dde8be5df490 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -4468,7 +4468,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
>  		goto cantfind_ext4;
>  
>  	/* check blocks count against device size */
> -	blocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits;
> +	blocks_count = sb_bdev_nr_blocks(sb);

Wait, my bad. Yes, this is fine. It's going through two helpers. :)

Reviewed-by: Kees Cook <keescook@chromium.org>


>  	if (blocks_count && ext4_blocks_count(es) > blocks_count) {
>  		ext4_msg(sb, KERN_WARNING, "bad geometry: block count %llu "
>  		       "exceeds size of device (%llu blocks)",
> -- 
> 2.30.2
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 26/29] jfs: use sb_bdev_nr_blocks
  2021-10-13  5:10 ` [PATCH 26/29] jfs: " Christoph Hellwig
@ 2021-10-13  6:31   ` Kees Cook
  0 siblings, 0 replies; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:31 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:39AM +0200, Christoph Hellwig wrote:
> Use the sb_bdev_nr_blocks helper instead of open coding it.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 27/29] ntfs: use sb_bdev_nr_blocks
  2021-10-13  5:10 ` [PATCH 27/29] ntfs: " Christoph Hellwig
@ 2021-10-13  6:33   ` Kees Cook
  0 siblings, 0 replies; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:33 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:40AM +0200, Christoph Hellwig wrote:
> Use the sb_bdev_nr_blocks helper instead of open coding it.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/ntfs/super.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
> index 0d7e948cb29c9..5ae8de09b271b 100644
> --- a/fs/ntfs/super.c
> +++ b/fs/ntfs/super.c
> @@ -2772,13 +2772,12 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
>  	ntfs_debug("Set device block size to %i bytes (block size bits %i).",
>  			blocksize, sb->s_blocksize_bits);
>  	/* Determine the size of the device in units of block_size bytes. */
> -	if (!i_size_read(sb->s_bdev->bd_inode)) {
> +	vol->nr_blocks = sb_bdev_nr_blocks(sb);
> +	if (!vol->nr_blocks) {

I might be worth mentioning in the commit log why this is safe (i.e. the
"side effect" of the assignment doesn't need to be delayed since it will
be thrown away in the failure path).

>  		if (!silent)
>  			ntfs_error(sb, "Unable to determine device size.");
>  		goto err_out_now;
>  	}
> -	vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >>
> -			sb->s_blocksize_bits;
>  	/* Read the boot sector and return unlocked buffer head to it. */
>  	if (!(bh = read_ntfs_boot_sector(sb, silent))) {
>  		if (!silent)
> @@ -2816,8 +2815,7 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
>  			goto err_out_now;
>  		}
>  		BUG_ON(blocksize != sb->s_blocksize);
> -		vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >>
> -				sb->s_blocksize_bits;
> +		vol->nr_blocks = sb_bdev_nr_blocks(sb);
>  		ntfs_debug("Changed device block size to %i bytes (block size "
>  				"bits %i) to match volume sector size.",
>  				blocksize, sb->s_blocksize_bits);

Reviewed-by: Kees Cook <keescook@chromium.org>


> -- 
> 2.30.2
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 28/29] reiserfs: use sb_bdev_nr_blocks
  2021-10-13  5:10 ` [PATCH 28/29] reiserfs: " Christoph Hellwig
@ 2021-10-13  6:33   ` Kees Cook
  2021-10-13 10:46   ` Jan Kara
  1 sibling, 0 replies; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:33 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:41AM +0200, Christoph Hellwig wrote:
> Use the sb_bdev_nr_blocks helper instead of open coding it.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 29/29] udf: use sb_bdev_nr_blocks
  2021-10-13  5:10 ` [PATCH 29/29] udf: " Christoph Hellwig
@ 2021-10-13  6:34   ` Kees Cook
  2021-10-13 10:47   ` Jan Kara
  1 sibling, 0 replies; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:34 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:42AM +0200, Christoph Hellwig wrote:
> Use the sb_bdev_nr_blocks helper instead of open coding it.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: don't use ->bd_inode to access the block device size
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (28 preceding siblings ...)
  2021-10-13  5:10 ` [PATCH 29/29] udf: " Christoph Hellwig
@ 2021-10-13  6:39 ` Kees Cook
  2021-10-13  7:14 ` Anand Jain
  2021-10-14  6:28 ` Christoph Hellwig
  31 siblings, 0 replies; 76+ messages in thread
From: Kees Cook @ 2021-10-13  6:39 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Anton Altaparmakov, Konstantin Komarov,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:13AM +0200, Christoph Hellwig wrote:
> I wondered about adding a helper for looking at the size in byte units
> to avoid the SECTOR_SHIFT shifts in various places.  But given that
> I could not come up with a good name and block devices fundamentally
> work in sector size granularity I decided against that.

Without something like bdev_nr_bytes(), this series has 13 of 29 patches
actually _adding_ an open-coded calculation:

[PATCH 05/29] mtd/block2mtd: use bdev_nr_sectors instead of open coding it
[PATCH 06/29] nvmet: use bdev_nr_sectors instead of open coding it
[PATCH 07/29] target/iblock: use bdev_nr_sectors instead of open coding it
[PATCH 08/29] fs: use bdev_nr_sectors instead of open coding it in blkdev_max_block
[PATCH 11/29] btrfs: use bdev_nr_sectors instead of open coding it
[PATCH 16/29] jfs: use bdev_nr_sectors instead of open coding it
[PATCH 17/29] nfs/blocklayout: use bdev_nr_sectors instead of open coding it
[PATCH 18/29] nilfs2: use bdev_nr_sectors instead of open coding it
[PATCH 19/29] ntfs3: use bdev_nr_sectors instead of open coding it
[PATCH 20/29] pstore/blk: use bdev_nr_sectors instead of open coding it
[PATCH 21/29] reiserfs: use bdev_nr_sectors instead of open coding it
[PATCH 22/29] squashfs: use bdev_nr_sectors instead of open coding it
[PATCH 23/29] block: use bdev_nr_sectors instead of open coding it in blkdev_fallocate

I think it's well worth having that helper (or at least leaving these
alone). Otherwise, this is a lot of churn without a clear net benefit,
IMO.

The others look good to me, though!

-Kees

>
> Diffstat:
>  block/fops.c                        |    2 +-
>  drivers/block/drbd/drbd_int.h       |    3 +--
>  drivers/md/bcache/super.c           |    2 +-
>  drivers/md/bcache/util.h            |    4 ----
>  drivers/md/bcache/writeback.c       |    2 +-
>  drivers/md/dm-bufio.c               |    2 +-
>  drivers/md/dm-cache-metadata.c      |    2 +-
>  drivers/md/dm-cache-target.c        |    2 +-
>  drivers/md/dm-clone-target.c        |    2 +-
>  drivers/md/dm-dust.c                |    5 ++---
>  drivers/md/dm-ebs-target.c          |    2 +-
>  drivers/md/dm-era-target.c          |    2 +-
>  drivers/md/dm-exception-store.h     |    2 +-
>  drivers/md/dm-flakey.c              |    3 +--
>  drivers/md/dm-integrity.c           |    6 +++---
>  drivers/md/dm-linear.c              |    3 +--
>  drivers/md/dm-log-writes.c          |    4 ++--
>  drivers/md/dm-log.c                 |    2 +-
>  drivers/md/dm-mpath.c               |    2 +-
>  drivers/md/dm-raid.c                |    6 +++---
>  drivers/md/dm-switch.c              |    2 +-
>  drivers/md/dm-table.c               |    3 +--
>  drivers/md/dm-thin-metadata.c       |    2 +-
>  drivers/md/dm-thin.c                |    2 +-
>  drivers/md/dm-verity-target.c       |    3 +--
>  drivers/md/dm-writecache.c          |    2 +-
>  drivers/md/dm-zoned-target.c        |    2 +-
>  drivers/md/md.c                     |   26 +++++++++++---------------
>  drivers/mtd/devices/block2mtd.c     |    5 +++--
>  drivers/nvme/target/io-cmd-bdev.c   |    4 ++--
>  drivers/target/target_core_iblock.c |    5 +++--
>  fs/affs/super.c                     |    2 +-
>  fs/btrfs/dev-replace.c              |    2 +-
>  fs/btrfs/disk-io.c                  |    3 ++-
>  fs/btrfs/ioctl.c                    |    4 ++--
>  fs/btrfs/volumes.c                  |    7 ++++---
>  fs/buffer.c                         |    4 ++--
>  fs/cramfs/inode.c                   |    2 +-
>  fs/ext4/super.c                     |    2 +-
>  fs/fat/inode.c                      |    5 +----
>  fs/hfs/mdb.c                        |    2 +-
>  fs/hfsplus/wrapper.c                |    2 +-
>  fs/jfs/resize.c                     |    5 ++---
>  fs/jfs/super.c                      |    5 ++---
>  fs/nfs/blocklayout/dev.c            |    4 ++--
>  fs/nilfs2/ioctl.c                   |    2 +-
>  fs/nilfs2/super.c                   |    2 +-
>  fs/nilfs2/the_nilfs.c               |    3 ++-
>  fs/ntfs/super.c                     |    8 +++-----
>  fs/ntfs3/super.c                    |    3 +--
>  fs/pstore/blk.c                     |    4 ++--
>  fs/reiserfs/super.c                 |    7 ++-----
>  fs/squashfs/super.c                 |    5 +++--
>  fs/udf/lowlevel.c                   |    5 ++---
>  fs/udf/super.c                      |    9 +++------
>  include/linux/genhd.h               |    6 ++++++
>  56 files changed, 100 insertions(+), 117 deletions(-)

--
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 11/29] btrfs: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 11/29] btrfs: " Christoph Hellwig
@ 2021-10-13  7:08   ` Anand Jain
  2021-10-13 22:36   ` Chaitanya Kulkarni
  2021-10-14  2:44   ` Keith Busch
  2 siblings, 0 replies; 76+ messages in thread
From: Anand Jain @ 2021-10-13  7:08 UTC (permalink / raw)
  To: Christoph Hellwig, 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On 13/10/2021 13:10, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good.

Reviewed-by: Anand Jain <anand.jain@oracle.com>


^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: don't use ->bd_inode to access the block device size
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (29 preceding siblings ...)
  2021-10-13  6:39 ` don't use ->bd_inode to access the block device size Kees Cook
@ 2021-10-13  7:14 ` Anand Jain
  2021-10-14  6:28 ` Christoph Hellwig
  31 siblings, 0 replies; 76+ messages in thread
From: Anand Jain @ 2021-10-13  7:14 UTC (permalink / raw)
  To: Christoph Hellwig, 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On 13/10/2021 13:10, Christoph Hellwig wrote:
> Hi Jens,
> 
> various drivers currently poke directy at the block device inode, which
> is a bit of a mess.  This series cleans up the places that read the
> block device size to use the proper helpers.  I have separate patches
> for many of the other bd_inode uses, but this series is already big
> enough as-is,
> 
> I wondered about adding a helper for looking at the size in byte units
> to avoid the SECTOR_SHIFT shifts in various places.  But given that
> I could not come up with a good name and 


> block devices fundamentally
> work in sector size granularity I decided against that.

Yes.  However,  POV of its usage outside the block-layer, a wrapper 
helper is a lot better. No.? If you agree, how about naming it bdev_size()?

Thanks, Anand

> 
> Diffstat:
>   block/fops.c                        |    2 +-
>   drivers/block/drbd/drbd_int.h       |    3 +--
>   drivers/md/bcache/super.c           |    2 +-
>   drivers/md/bcache/util.h            |    4 ----
>   drivers/md/bcache/writeback.c       |    2 +-
>   drivers/md/dm-bufio.c               |    2 +-
>   drivers/md/dm-cache-metadata.c      |    2 +-
>   drivers/md/dm-cache-target.c        |    2 +-
>   drivers/md/dm-clone-target.c        |    2 +-
>   drivers/md/dm-dust.c                |    5 ++---
>   drivers/md/dm-ebs-target.c          |    2 +-
>   drivers/md/dm-era-target.c          |    2 +-
>   drivers/md/dm-exception-store.h     |    2 +-
>   drivers/md/dm-flakey.c              |    3 +--
>   drivers/md/dm-integrity.c           |    6 +++---
>   drivers/md/dm-linear.c              |    3 +--
>   drivers/md/dm-log-writes.c          |    4 ++--
>   drivers/md/dm-log.c                 |    2 +-
>   drivers/md/dm-mpath.c               |    2 +-
>   drivers/md/dm-raid.c                |    6 +++---
>   drivers/md/dm-switch.c              |    2 +-
>   drivers/md/dm-table.c               |    3 +--
>   drivers/md/dm-thin-metadata.c       |    2 +-
>   drivers/md/dm-thin.c                |    2 +-
>   drivers/md/dm-verity-target.c       |    3 +--
>   drivers/md/dm-writecache.c          |    2 +-
>   drivers/md/dm-zoned-target.c        |    2 +-
>   drivers/md/md.c                     |   26 +++++++++++---------------
>   drivers/mtd/devices/block2mtd.c     |    5 +++--
>   drivers/nvme/target/io-cmd-bdev.c   |    4 ++--
>   drivers/target/target_core_iblock.c |    5 +++--
>   fs/affs/super.c                     |    2 +-
>   fs/btrfs/dev-replace.c              |    2 +-
>   fs/btrfs/disk-io.c                  |    3 ++-
>   fs/btrfs/ioctl.c                    |    4 ++--
>   fs/btrfs/volumes.c                  |    7 ++++---
>   fs/buffer.c                         |    4 ++--
>   fs/cramfs/inode.c                   |    2 +-
>   fs/ext4/super.c                     |    2 +-
>   fs/fat/inode.c                      |    5 +----
>   fs/hfs/mdb.c                        |    2 +-
>   fs/hfsplus/wrapper.c                |    2 +-
>   fs/jfs/resize.c                     |    5 ++---
>   fs/jfs/super.c                      |    5 ++---
>   fs/nfs/blocklayout/dev.c            |    4 ++--
>   fs/nilfs2/ioctl.c                   |    2 +-
>   fs/nilfs2/super.c                   |    2 +-
>   fs/nilfs2/the_nilfs.c               |    3 ++-
>   fs/ntfs/super.c                     |    8 +++-----
>   fs/ntfs3/super.c                    |    3 +--
>   fs/pstore/blk.c                     |    4 ++--
>   fs/reiserfs/super.c                 |    7 ++-----
>   fs/squashfs/super.c                 |    5 +++--
>   fs/udf/lowlevel.c                   |    5 ++---
>   fs/udf/super.c                      |    9 +++------
>   include/linux/genhd.h               |    6 ++++++
>   56 files changed, 100 insertions(+), 117 deletions(-)
> 


^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 07/29] target/iblock: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 07/29] target/iblock: " Christoph Hellwig
@ 2021-10-13  9:31   ` Bodo Stroesser
  2021-10-13 22:37   ` Chaitanya Kulkarni
  1 sibling, 0 replies; 76+ messages in thread
From: Bodo Stroesser @ 2021-10-13  9:31 UTC (permalink / raw)
  To: Christoph Hellwig, 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On 13.10.21 07:10, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   drivers/target/target_core_iblock.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c
> index 31df20abe141f..ab7f5678ebc44 100644
> --- a/drivers/target/target_core_iblock.c
> +++ b/drivers/target/target_core_iblock.c
> @@ -232,8 +232,9 @@ static unsigned long long iblock_emulate_read_cap_with_block_size(
>   	struct block_device *bd,
>   	struct request_queue *q)
>   {
> -	unsigned long long blocks_long = (div_u64(i_size_read(bd->bd_inode),
> -					bdev_logical_block_size(bd)) - 1);
> +	loff_t size = bdev_nr_sectors(bd) << SECTOR_SHIFT;
> +	unsigned long long blocks_long =
> +		div_u64(size, bdev_logical_block_size(bd)) - 1;
>   	u32 block_size = bdev_logical_block_size(bd);

To enhance readability, would it make sense to shift the new lines
behind "u32 block_size = ...", so block_size can be used in div_u64
instead of using bdev_logical_block_size twice?

>   
>   	if (block_size == dev->dev_attrib.block_size)
> 

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 09/29] fs: simplify init_page_buffers
  2021-10-13  5:10 ` [PATCH 09/29] fs: simplify init_page_buffers Christoph Hellwig
  2021-10-13  6:14   ` Kees Cook
@ 2021-10-13 10:42   ` Jan Kara
  1 sibling, 0 replies; 76+ messages in thread
From: Jan Kara @ 2021-10-13 10:42 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed 13-10-21 07:10:22, Christoph Hellwig wrote:
> No need to convert from bdev to inode and back.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 08/29] fs: use bdev_nr_sectors instead of open coding it in blkdev_max_block
  2021-10-13  5:10 ` [PATCH 08/29] fs: use bdev_nr_sectors instead of open coding it in blkdev_max_block Christoph Hellwig
@ 2021-10-13 10:42   ` Jan Kara
  2021-10-13 22:35   ` Chaitanya Kulkarni
  1 sibling, 0 replies; 76+ messages in thread
From: Jan Kara @ 2021-10-13 10:42 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed 13-10-21 07:10:21, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 21/29] reiserfs: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 21/29] reiserfs: " Christoph Hellwig
@ 2021-10-13 10:43   ` Jan Kara
  0 siblings, 0 replies; 76+ messages in thread
From: Jan Kara @ 2021-10-13 10:43 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed 13-10-21 07:10:34, Christoph Hellwig wrote:
> Use the proper helper to read the block device size and remove two
> cargo culted checks that can't be false.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/reiserfs/super.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
> index 58481f8d63d5b..6c9681e2809f0 100644
> --- a/fs/reiserfs/super.c
> +++ b/fs/reiserfs/super.c
> @@ -1986,8 +1986,7 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
>  	 * smaller than the filesystem. If the check fails then abort and
>  	 * scream, because bad stuff will happen otherwise.
>  	 */
> -	if (s->s_bdev && s->s_bdev->bd_inode
> -	    && i_size_read(s->s_bdev->bd_inode) <
> +	if ((bdev_nr_sectors(s->s_bdev) << SECTOR_SHIFT) <
>  	    sb_block_count(rs) * sb_blocksize(rs)) {
>  		SWARN(silent, s, "", "Filesystem cannot be "
>  		      "mounted because it is bigger than the device");
> -- 
> 2.30.2
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 23/29] block: use bdev_nr_sectors instead of open coding it in blkdev_fallocate
  2021-10-13  5:10 ` [PATCH 23/29] block: use bdev_nr_sectors instead of open coding it in blkdev_fallocate Christoph Hellwig
@ 2021-10-13 10:44   ` Jan Kara
  2021-10-13 22:34   ` Chaitanya Kulkarni
  1 sibling, 0 replies; 76+ messages in thread
From: Jan Kara @ 2021-10-13 10:44 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed 13-10-21 07:10:36, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 28/29] reiserfs: use sb_bdev_nr_blocks
  2021-10-13  5:10 ` [PATCH 28/29] reiserfs: " Christoph Hellwig
  2021-10-13  6:33   ` Kees Cook
@ 2021-10-13 10:46   ` Jan Kara
  1 sibling, 0 replies; 76+ messages in thread
From: Jan Kara @ 2021-10-13 10:46 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed 13-10-21 07:10:41, Christoph Hellwig wrote:
> Use the sb_bdev_nr_blocks helper instead of open coding it.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 25/29] ext4: use sb_bdev_nr_blocks
  2021-10-13  5:10 ` [PATCH 25/29] ext4: use sb_bdev_nr_blocks Christoph Hellwig
  2021-10-13  6:29   ` Kees Cook
  2021-10-13  6:30   ` Kees Cook
@ 2021-10-13 10:46   ` Jan Kara
  2021-10-13 15:51   ` Theodore Ts'o
  3 siblings, 0 replies; 76+ messages in thread
From: Jan Kara @ 2021-10-13 10:46 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed 13-10-21 07:10:38, Christoph Hellwig wrote:
> Use the sb_bdev_nr_blocks helper instead of open coding it.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 29/29] udf: use sb_bdev_nr_blocks
  2021-10-13  5:10 ` [PATCH 29/29] udf: " Christoph Hellwig
  2021-10-13  6:34   ` Kees Cook
@ 2021-10-13 10:47   ` Jan Kara
  1 sibling, 0 replies; 76+ messages in thread
From: Jan Kara @ 2021-10-13 10:47 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed 13-10-21 07:10:42, Christoph Hellwig wrote:
> Use the sb_bdev_nr_blocks helper instead of open coding it.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 16/29] jfs: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 16/29] jfs: " Christoph Hellwig
@ 2021-10-13 14:13   ` Dave Kleikamp
  0 siblings, 0 replies; 76+ messages in thread
From: Dave Kleikamp @ 2021-10-13 14:13 UTC (permalink / raw)
  To: Christoph Hellwig, Jens Axboe
  Cc: Coly Li, Mike Snitzer, Song Liu, David Sterba, Josef Bacik,
	Theodore Ts'o, OGAWA Hirofumi, Ryusuke Konishi,
	Anton Altaparmakov, Konstantin Komarov, Kees Cook,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On 10/13/21 12:10AM, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Acked-by: Dave Kleikamp <dave.kleikamp@oracle.com>

> ---
>   fs/jfs/resize.c | 2 +-
>   fs/jfs/super.c  | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/jfs/resize.c b/fs/jfs/resize.c
> index bde787c354fcc..51a8b22e71030 100644
> --- a/fs/jfs/resize.c
> +++ b/fs/jfs/resize.c
> @@ -199,7 +199,7 @@ int jfs_extendfs(struct super_block *sb, s64 newLVSize, int newLogSize)
>   	txQuiesce(sb);
>   
>   	/* Reset size of direct inode */
> -	sbi->direct_inode->i_size =  i_size_read(sb->s_bdev->bd_inode);
> +	sbi->direct_inode->i_size = bdev_nr_sectors(sb->s_bdev) << SECTOR_SHIFT;
>   
>   	if (sbi->mntflag & JFS_INLINELOG) {
>   		/*
> diff --git a/fs/jfs/super.c b/fs/jfs/super.c
> index 9030aeaf0f886..992870160903d 100644
> --- a/fs/jfs/super.c
> +++ b/fs/jfs/super.c
> @@ -551,7 +551,7 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
>   		ret = -ENOMEM;
>   		goto out_unload;
>   	}
> -	inode->i_size = i_size_read(sb->s_bdev->bd_inode);
> +	inode->i_size = bdev_nr_sectors(sb->s_bdev) << SECTOR_SHIFT;
>   	inode->i_mapping->a_ops = &jfs_metapage_aops;
>   	inode_fake_hash(inode);
>   	mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
> 

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 25/29] ext4: use sb_bdev_nr_blocks
  2021-10-13  5:10 ` [PATCH 25/29] ext4: use sb_bdev_nr_blocks Christoph Hellwig
                     ` (2 preceding siblings ...)
  2021-10-13 10:46   ` Jan Kara
@ 2021-10-13 15:51   ` Theodore Ts'o
  3 siblings, 0 replies; 76+ messages in thread
From: Theodore Ts'o @ 2021-10-13 15:51 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, OGAWA Hirofumi, Dave Kleikamp, Ryusuke Konishi,
	Anton Altaparmakov, Konstantin Komarov, Kees Cook,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:38AM +0200, Christoph Hellwig wrote:
> Use the sb_bdev_nr_blocks helper instead of open coding it.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Acked-by: Theodore Ts'o <tytso@mit.edu>

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 03/29] dm: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 03/29] dm: " Christoph Hellwig
  2021-10-13  6:10   ` Kees Cook
@ 2021-10-13 16:43   ` Mike Snitzer
  1 sibling, 0 replies; 76+ messages in thread
From: Mike Snitzer @ 2021-10-13 16:43 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, David Sterba, Josef Bacik,
	Theodore Ts'o, OGAWA Hirofumi, Ryusuke Konishi,
	Anton Altaparmakov, Konstantin Komarov, Kees Cook,
	Phillip Lougher, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13 2021 at  1:10P -0400,
Christoph Hellwig <hch@lst.de> wrote:

> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Acked-by: Mike Snitzer <snitzer@redhat.com>


^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 22/29] squashfs: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 22/29] squashfs: " Christoph Hellwig
@ 2021-10-13 19:37   ` Phillip Lougher
  0 siblings, 0 replies; 76+ messages in thread
From: Phillip Lougher @ 2021-10-13 19:37 UTC (permalink / raw)
  To: Christoph Hellwig, 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, Jan Kara, linux-block, dm-devel, drbd-dev,
	linux-bcache, linux-raid, linux-mtd, linux-nvme, linux-scsi,
	target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On 13/10/2021 06:10, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Acked-by: Phillip Lougher <phillip@squashfs.org.uk>

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 04/29] md: use bdev_nr_sectors instead of open coding it
  2021-10-13  6:12   ` Kees Cook
@ 2021-10-13 21:14     ` Song Liu
  0 siblings, 0 replies; 76+ messages in thread
From: Song Liu @ 2021-10-13 21:14 UTC (permalink / raw)
  To: Kees Cook
  Cc: Christoph Hellwig, Jens Axboe, Coly Li, Mike Snitzer,
	David Sterba, Josef Bacik, Theodore Ts'o, OGAWA Hirofumi,
	Dave Kleikamp, Ryusuke Konishi, Anton Altaparmakov,
	Konstantin Komarov, Phillip Lougher, Jan Kara, linux-block,
	dm-devel, drbd-dev, linux-bcache, linux-raid, linux-mtd,
	linux-nvme, linux-scsi, target-devel, Linux-Fsdevel, linux-btrfs,
	linux-ext4, jfs-discussion, linux-nfs, linux-nilfs,
	linux-ntfs-dev, ntfs3, reiserfs-devel

On Tue, Oct 12, 2021 at 11:12 PM Kees Cook <keescook@chromium.org> wrote:
>
> On Wed, Oct 13, 2021 at 07:10:17AM +0200, Christoph Hellwig wrote:
> > Use the proper helper to read the block device size.
> >
> > Signed-off-by: Christoph Hellwig <hch@lst.de>
>
> I think it might make sense, as you suggest earlier, to add a "bytes"
> helper. This is the first user in the series needing:
>
>         bdev_nr_sectors(...bdev) << SECTOR_SHIFT
>
> Reviewed-by: Kees Cook <keescook@chromium.org>

Acked-by: Song Liu <song@kernel.org>

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 06/29] nvmet: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 06/29] nvmet: " Christoph Hellwig
@ 2021-10-13 22:33   ` Chaitanya Kulkarni
  0 siblings, 0 replies; 76+ messages in thread
From: Chaitanya Kulkarni @ 2021-10-13 22:33 UTC (permalink / raw)
  To: Christoph Hellwig, 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On 10/12/2021 10:10 PM, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 02/29] drbd: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 02/29] drbd: use bdev_nr_sectors instead of open coding it Christoph Hellwig
  2021-10-13  6:09   ` Kees Cook
@ 2021-10-13 22:33   ` Chaitanya Kulkarni
  1 sibling, 0 replies; 76+ messages in thread
From: Chaitanya Kulkarni @ 2021-10-13 22:33 UTC (permalink / raw)
  To: Christoph Hellwig, 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On 10/12/2021 10:10 PM, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 23/29] block: use bdev_nr_sectors instead of open coding it in blkdev_fallocate
  2021-10-13  5:10 ` [PATCH 23/29] block: use bdev_nr_sectors instead of open coding it in blkdev_fallocate Christoph Hellwig
  2021-10-13 10:44   ` Jan Kara
@ 2021-10-13 22:34   ` Chaitanya Kulkarni
  1 sibling, 0 replies; 76+ messages in thread
From: Chaitanya Kulkarni @ 2021-10-13 22:34 UTC (permalink / raw)
  To: Christoph Hellwig, 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On 10/12/2021 10:10 PM, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 08/29] fs: use bdev_nr_sectors instead of open coding it in blkdev_max_block
  2021-10-13  5:10 ` [PATCH 08/29] fs: use bdev_nr_sectors instead of open coding it in blkdev_max_block Christoph Hellwig
  2021-10-13 10:42   ` Jan Kara
@ 2021-10-13 22:35   ` Chaitanya Kulkarni
  1 sibling, 0 replies; 76+ messages in thread
From: Chaitanya Kulkarni @ 2021-10-13 22:35 UTC (permalink / raw)
  To: Christoph Hellwig, 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On 10/12/2021 10:10 PM, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---


Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 11/29] btrfs: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 11/29] btrfs: " Christoph Hellwig
  2021-10-13  7:08   ` Anand Jain
@ 2021-10-13 22:36   ` Chaitanya Kulkarni
  2021-10-14  2:44   ` Keith Busch
  2 siblings, 0 replies; 76+ messages in thread
From: Chaitanya Kulkarni @ 2021-10-13 22:36 UTC (permalink / raw)
  To: Christoph Hellwig, 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On 10/12/2021 10:10 PM, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>


Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 07/29] target/iblock: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 07/29] target/iblock: " Christoph Hellwig
  2021-10-13  9:31   ` Bodo Stroesser
@ 2021-10-13 22:37   ` Chaitanya Kulkarni
  1 sibling, 0 replies; 76+ messages in thread
From: Chaitanya Kulkarni @ 2021-10-13 22:37 UTC (permalink / raw)
  To: Christoph Hellwig, 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On 10/12/2021 10:10 PM, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---

Bodo's comment is good for the code reliability.

Either way, looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 11/29] btrfs: use bdev_nr_sectors instead of open coding it
  2021-10-13  5:10 ` [PATCH 11/29] btrfs: " Christoph Hellwig
  2021-10-13  7:08   ` Anand Jain
  2021-10-13 22:36   ` Chaitanya Kulkarni
@ 2021-10-14  2:44   ` Keith Busch
  2 siblings, 0 replies; 76+ messages in thread
From: Keith Busch @ 2021-10-14  2:44 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, 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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:24AM +0200, Christoph Hellwig wrote:
> Use the proper helper to read the block device size.

Just IMO, this patch looks like it wants a new bdev_nr_bytes() helper
instead of using the double shifting sectors back to bytes.

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: don't use ->bd_inode to access the block device size
  2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
                   ` (30 preceding siblings ...)
  2021-10-13  7:14 ` Anand Jain
@ 2021-10-14  6:28 ` Christoph Hellwig
  2021-10-14  9:32   ` Anton Altaparmakov
  31 siblings, 1 reply; 76+ messages in thread
From: Christoph Hellwig @ 2021-10-14  6:28 UTC (permalink / raw)
  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, dm-devel,
	drbd-dev, linux-bcache, linux-raid, linux-mtd, linux-nvme,
	linux-scsi, target-devel, linux-fsdevel, linux-btrfs, linux-ext4,
	jfs-discussion, linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3,
	reiserfs-devel

On Wed, Oct 13, 2021 at 07:10:13AM +0200, Christoph Hellwig wrote:
> I wondered about adding a helper for looking at the size in byte units
> to avoid the SECTOR_SHIFT shifts in various places.  But given that
> I could not come up with a good name and block devices fundamentally
> work in sector size granularity I decided against that.

So it seems like the biggest review feedback is that we should have
such a helper.  I think the bdev_size name is the worst as size does
not imply a particular unit.  bdev_nr_bytes is a little better but I'm
not too happy.  Any other suggestions or strong opinions?

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: don't use ->bd_inode to access the block device size
  2021-10-14  6:28 ` Christoph Hellwig
@ 2021-10-14  9:32   ` Anton Altaparmakov
  2021-10-14 13:13     ` Dave Kleikamp
  0 siblings, 1 reply; 76+ messages in thread
From: Anton Altaparmakov @ 2021-10-14  9:32 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Dave Kleikamp,
	Ryusuke Konishi, Konstantin Komarov, Kees Cook, Phillip Lougher,
	Jan Kara, linux-block, dm-devel, drbd-dev, linux-bcache,
	linux-raid, linux-mtd, linux-nvme, linux-scsi, target-devel,
	linux-fsdevel, linux-btrfs, linux-ext4, jfs-discussion,
	linux-nfs, linux-nilfs, linux-ntfs-dev, ntfs3, reiserfs-devel

Hi Christoph,

> On 14 Oct 2021, at 07:28, Christoph Hellwig <hch@lst.de> wrote:
> 
> On Wed, Oct 13, 2021 at 07:10:13AM +0200, Christoph Hellwig wrote:
>> I wondered about adding a helper for looking at the size in byte units
>> to avoid the SECTOR_SHIFT shifts in various places.  But given that
>> I could not come up with a good name and block devices fundamentally
>> work in sector size granularity I decided against that.
> 
> So it seems like the biggest review feedback is that we should have
> such a helper.  I think the bdev_size name is the worst as size does
> not imply a particular unit.  bdev_nr_bytes is a little better but I'm
> not too happy.  Any other suggestions or strong opinions?

bdev_byte_size() would seem to address your concerns?

bdev_nr_bytes() would work though - it is analogous to bdev_nr_sectors() after all.

No strong opinion here but I do agree with you that bdev_size() is a bad choice for sure.  It is bound to cause bugs down the line when people forget what unit it is in.

Best regards,

	Anton
-- 
Anton Altaparmakov <anton at tuxera.com> (replace at with @)
Lead in File System Development, Tuxera Inc., http://www.tuxera.com/
Linux NTFS maintainer


^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: don't use ->bd_inode to access the block device size
  2021-10-14  9:32   ` Anton Altaparmakov
@ 2021-10-14 13:13     ` Dave Kleikamp
  2021-10-14 15:14       ` Kees Cook
  0 siblings, 1 reply; 76+ messages in thread
From: Dave Kleikamp @ 2021-10-14 13:13 UTC (permalink / raw)
  To: Anton Altaparmakov, Christoph Hellwig
  Cc: Jens Axboe, Coly Li, Mike Snitzer, Song Liu, David Sterba,
	Josef Bacik, Theodore Ts'o, OGAWA Hirofumi, Ryusuke Konishi,
	Konstantin Komarov, Kees Cook, Phillip Lougher, Jan Kara,
	linux-block, dm-devel, drbd-dev, linux-bcache, linux-raid,
	linux-mtd, linux-nvme, linux-scsi, target-devel, linux-fsdevel,
	linux-btrfs, linux-ext4, jfs-discussion, linux-nfs, linux-nilfs,
	linux-ntfs-dev, ntfs3, reiserfs-devel

On 10/14/21 4:32AM, Anton Altaparmakov wrote:
> Hi Christoph,
> 
>> On 14 Oct 2021, at 07:28, Christoph Hellwig <hch@lst.de> wrote:
>>
>> On Wed, Oct 13, 2021 at 07:10:13AM +0200, Christoph Hellwig wrote:
>>> I wondered about adding a helper for looking at the size in byte units
>>> to avoid the SECTOR_SHIFT shifts in various places.  But given that
>>> I could not come up with a good name and block devices fundamentally
>>> work in sector size granularity I decided against that.
>>
>> So it seems like the biggest review feedback is that we should have
>> such a helper.  I think the bdev_size name is the worst as size does
>> not imply a particular unit.  bdev_nr_bytes is a little better but I'm
>> not too happy.  Any other suggestions or strong opinions?
> 
> bdev_byte_size() would seem to address your concerns?
> 
> bdev_nr_bytes() would work though - it is analogous to bdev_nr_sectors() after all.
> 
> No strong opinion here but I do agree with you that bdev_size() is a bad choice for sure.  It is bound to cause bugs down the line when people forget what unit it is in.

I don't really mind bdev_size since it's analogous to i_size, but 
bdev_nr_bytes seems good to me.

Shaggy

> Best regards,
> 
> 	Anton
> 

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: don't use ->bd_inode to access the block device size
  2021-10-14 13:13     ` Dave Kleikamp
@ 2021-10-14 15:14       ` Kees Cook
  2021-10-14 15:35         ` Wol
  0 siblings, 1 reply; 76+ messages in thread
From: Kees Cook @ 2021-10-14 15:14 UTC (permalink / raw)
  To: Dave Kleikamp
  Cc: Anton Altaparmakov, Christoph Hellwig, Jens Axboe, Coly Li,
	Mike Snitzer, Song Liu, David Sterba, Josef Bacik,
	Theodore Ts'o, OGAWA Hirofumi, Ryusuke Konishi,
	Konstantin Komarov, Phillip Lougher, Jan Kara, linux-block,
	dm-devel, drbd-dev, linux-bcache, linux-raid, linux-mtd,
	linux-nvme, linux-scsi, target-devel, linux-fsdevel, linux-btrfs,
	linux-ext4, jfs-discussion, linux-nfs, linux-nilfs,
	linux-ntfs-dev, ntfs3, reiserfs-devel

On Thu, Oct 14, 2021 at 08:13:59AM -0500, Dave Kleikamp wrote:
> On 10/14/21 4:32AM, Anton Altaparmakov wrote:
> > Hi Christoph,
> > 
> > > On 14 Oct 2021, at 07:28, Christoph Hellwig <hch@lst.de> wrote:
> > > 
> > > On Wed, Oct 13, 2021 at 07:10:13AM +0200, Christoph Hellwig wrote:
> > > > I wondered about adding a helper for looking at the size in byte units
> > > > to avoid the SECTOR_SHIFT shifts in various places.  But given that
> > > > I could not come up with a good name and block devices fundamentally
> > > > work in sector size granularity I decided against that.
> > > 
> > > So it seems like the biggest review feedback is that we should have
> > > such a helper.  I think the bdev_size name is the worst as size does
> > > not imply a particular unit.  bdev_nr_bytes is a little better but I'm
> > > not too happy.  Any other suggestions or strong opinions?
> > 
> > bdev_byte_size() would seem to address your concerns?
> > 
> > bdev_nr_bytes() would work though - it is analogous to bdev_nr_sectors() after all.
> > 
> > No strong opinion here but I do agree with you that bdev_size() is a bad choice for sure.  It is bound to cause bugs down the line when people forget what unit it is in.
> 
> I don't really mind bdev_size since it's analogous to i_size, but
> bdev_nr_bytes seems good to me.

I much prefer bdev_nr_bytes(), as "size" has no units.

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: don't use ->bd_inode to access the block device size
  2021-10-14 15:14       ` Kees Cook
@ 2021-10-14 15:35         ` Wol
  0 siblings, 0 replies; 76+ messages in thread
From: Wol @ 2021-10-14 15:35 UTC (permalink / raw)
  To: Kees Cook, Dave Kleikamp
  Cc: linux-block, dm-devel, drbd-dev, linux-bcache, linux-raid,
	linux-mtd, linux-nvme, linux-scsi, target-devel, linux-fsdevel,
	linux-btrfs, linux-ext4, jfs-discussion, linux-nfs, linux-nilfs,
	linux-ntfs-dev, ntfs3, reiserfs-devel

On 14/10/2021 16:14, Kees Cook wrote:
>> I don't really mind bdev_size since it's analogous to i_size, but
>> bdev_nr_bytes seems good to me.

> I much prefer bdev_nr_bytes(), as "size" has no units.

Does it mean size IN bytes, or size OF A byte? :-)

Cheers,
Wol

^ permalink raw reply	[flat|nested] 76+ messages in thread

end of thread, other threads:[~2021-10-14 17:04 UTC | newest]

Thread overview: 76+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-13  5:10 don't use ->bd_inode to access the block device size Christoph Hellwig
2021-10-13  5:10 ` [PATCH 01/29] bcache: remove bdev_sectors Christoph Hellwig
2021-10-13  5:21   ` Coly Li
2021-10-13  6:09   ` Kees Cook
2021-10-13  5:10 ` [PATCH 02/29] drbd: use bdev_nr_sectors instead of open coding it Christoph Hellwig
2021-10-13  6:09   ` Kees Cook
2021-10-13 22:33   ` Chaitanya Kulkarni
2021-10-13  5:10 ` [PATCH 03/29] dm: " Christoph Hellwig
2021-10-13  6:10   ` Kees Cook
2021-10-13 16:43   ` Mike Snitzer
2021-10-13  5:10 ` [PATCH 04/29] md: " Christoph Hellwig
2021-10-13  6:12   ` Kees Cook
2021-10-13 21:14     ` Song Liu
2021-10-13  5:10 ` [PATCH 05/29] mtd/block2mtd: " Christoph Hellwig
2021-10-13  5:10 ` [PATCH 06/29] nvmet: " Christoph Hellwig
2021-10-13 22:33   ` Chaitanya Kulkarni
2021-10-13  5:10 ` [PATCH 07/29] target/iblock: " Christoph Hellwig
2021-10-13  9:31   ` Bodo Stroesser
2021-10-13 22:37   ` Chaitanya Kulkarni
2021-10-13  5:10 ` [PATCH 08/29] fs: use bdev_nr_sectors instead of open coding it in blkdev_max_block Christoph Hellwig
2021-10-13 10:42   ` Jan Kara
2021-10-13 22:35   ` Chaitanya Kulkarni
2021-10-13  5:10 ` [PATCH 09/29] fs: simplify init_page_buffers Christoph Hellwig
2021-10-13  6:14   ` Kees Cook
2021-10-13 10:42   ` Jan Kara
2021-10-13  5:10 ` [PATCH 10/29] affs: use bdev_nr_sectors instead of open coding it Christoph Hellwig
2021-10-13  6:14   ` Kees Cook
2021-10-13  5:10 ` [PATCH 11/29] btrfs: " Christoph Hellwig
2021-10-13  7:08   ` Anand Jain
2021-10-13 22:36   ` Chaitanya Kulkarni
2021-10-14  2:44   ` Keith Busch
2021-10-13  5:10 ` [PATCH 12/29] cramfs: " Christoph Hellwig
2021-10-13  6:16   ` Kees Cook
2021-10-13  5:10 ` [PATCH 13/29] fat: " Christoph Hellwig
2021-10-13  6:16   ` Kees Cook
2021-10-13  5:10 ` [PATCH 14/29] hfs: " Christoph Hellwig
2021-10-13  6:16   ` Kees Cook
2021-10-13  5:10 ` [PATCH 15/29] hfsplus: " Christoph Hellwig
2021-10-13  6:16   ` Kees Cook
2021-10-13  5:10 ` [PATCH 16/29] jfs: " Christoph Hellwig
2021-10-13 14:13   ` Dave Kleikamp
2021-10-13  5:10 ` [PATCH 17/29] nfs/blocklayout: " Christoph Hellwig
2021-10-13  5:10 ` [PATCH 18/29] nilfs2: " Christoph Hellwig
2021-10-13  5:10 ` [PATCH 19/29] ntfs3: " Christoph Hellwig
2021-10-13  5:10 ` [PATCH 20/29] pstore/blk: " Christoph Hellwig
2021-10-13  5:10 ` [PATCH 21/29] reiserfs: " Christoph Hellwig
2021-10-13 10:43   ` Jan Kara
2021-10-13  5:10 ` [PATCH 22/29] squashfs: " Christoph Hellwig
2021-10-13 19:37   ` Phillip Lougher
2021-10-13  5:10 ` [PATCH 23/29] block: use bdev_nr_sectors instead of open coding it in blkdev_fallocate Christoph Hellwig
2021-10-13 10:44   ` Jan Kara
2021-10-13 22:34   ` Chaitanya Kulkarni
2021-10-13  5:10 ` [PATCH 24/29] block: add a sb_bdev_nr_blocks helper Christoph Hellwig
2021-10-13  6:27   ` Kees Cook
2021-10-13  5:10 ` [PATCH 25/29] ext4: use sb_bdev_nr_blocks Christoph Hellwig
2021-10-13  6:29   ` Kees Cook
2021-10-13  6:30   ` Kees Cook
2021-10-13 10:46   ` Jan Kara
2021-10-13 15:51   ` Theodore Ts'o
2021-10-13  5:10 ` [PATCH 26/29] jfs: " Christoph Hellwig
2021-10-13  6:31   ` Kees Cook
2021-10-13  5:10 ` [PATCH 27/29] ntfs: " Christoph Hellwig
2021-10-13  6:33   ` Kees Cook
2021-10-13  5:10 ` [PATCH 28/29] reiserfs: " Christoph Hellwig
2021-10-13  6:33   ` Kees Cook
2021-10-13 10:46   ` Jan Kara
2021-10-13  5:10 ` [PATCH 29/29] udf: " Christoph Hellwig
2021-10-13  6:34   ` Kees Cook
2021-10-13 10:47   ` Jan Kara
2021-10-13  6:39 ` don't use ->bd_inode to access the block device size Kees Cook
2021-10-13  7:14 ` Anand Jain
2021-10-14  6:28 ` Christoph Hellwig
2021-10-14  9:32   ` Anton Altaparmakov
2021-10-14 13:13     ` Dave Kleikamp
2021-10-14 15:14       ` Kees Cook
2021-10-14 15:35         ` Wol

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).