Blob Blame History Raw
From: Christoph Hellwig <hch@lst.de>
Date: Fri, 26 Jun 2020 10:01:55 +0200
Subject: [PATCH] block: remove the bd_block_size field from struct
Git-commit: 6b7b181b67aa8177e57732723106a0411570a86d
Patch-mainline: v5.9-rc1
References: bsc#1175995,jsc#SLE-15608
 block_device

We can trivially calculate the block size from the inodes i_blkbits
variable.  Use that instead of keeping two redundant copies of the
information in slightly different formats.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Acked-by: Hannes Reinecke <hare@suse.com>
[dwagner: dropped set_init_blocksize recalculation, gets reverted by
          8dc932d3e8af ("Revert "block: simplify set_init_blocksize
	  " to regain lost performance")]
Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 fs/block_dev.c            |    5 +----
 include/linux/blk_types.h |    1 -
 include/linux/blkdev.h    |    2 +-
 3 files changed, 2 insertions(+), 6 deletions(-)

--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -113,7 +113,6 @@ static void set_init_blocksize(struct bl
 			break;
 		bsize <<= 1;
 	}
-	bdev->bd_block_size = bsize;
 	bdev->bd_inode->i_blkbits = blksize_bits(bsize);
 }
 
@@ -128,9 +127,8 @@ int set_blocksize(struct block_device *b
 		return -EINVAL;
 
 	/* Don't change the size if it is same as current */
-	if (bdev->bd_block_size != size) {
+	if (bdev->bd_inode->i_blkbits != blksize_bits(size)) {
 		sync_blockdev(bdev);
-		bdev->bd_block_size = size;
 		bdev->bd_inode->i_blkbits = blksize_bits(size);
 		kill_bdev(bdev);
 	}
@@ -898,7 +896,6 @@ struct block_device *bdget(dev_t dev)
 		bdev->bd_contains = NULL;
 		bdev->bd_super = NULL;
 		bdev->bd_inode = inode;
-		bdev->bd_block_size = i_blocksize(inode);
 		bdev->bd_part_count = 0;
 		bdev->bd_invalidated = 0;
 		inode->i_mode = S_IFBLK;
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -33,7 +33,6 @@ struct block_device {
 	struct list_head	bd_holder_disks;
 #endif
 	struct block_device *	bd_contains;
-	unsigned		bd_block_size;
 	u8			bd_partno;
 	struct hd_struct *	bd_part;
 	/* number of times partitions within this device have been opened. */
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1543,7 +1543,7 @@ static inline unsigned int blksize_bits(
 
 static inline unsigned int block_size(struct block_device *bdev)
 {
-	return bdev->bd_block_size;
+	return 1 << bdev->bd_inode->i_blkbits;
 }
 
 int kblockd_schedule_work(struct work_struct *work);