diff mbox series

[13/15] block: move bd_part_count to struct gendisk

Message ID 20210330161727.2297292-14-hch@lst.de
State New
Headers show
Series [01/15] md: remove the code to flush an old instance in md_open | expand

Commit Message

Christoph Hellwig March 30, 2021, 4:17 p.m. UTC
The bd_part_count value only makes sense for whole devices, so move it
to struct gendisk and give it a more descriptive name.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/partitions/core.c   | 2 +-
 fs/block_dev.c            | 4 ++--
 include/linux/blk_types.h | 3 ---
 include/linux/genhd.h     | 1 +
 4 files changed, 4 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/block/partitions/core.c b/block/partitions/core.c
index 60388a41ff92a3..162b9b35c53171 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -527,7 +527,7 @@  int blk_drop_partitions(struct block_device *bdev)
 	struct disk_part_iter piter;
 	struct block_device *part;
 
-	if (bdev->bd_part_count)
+	if (bdev->bd_disk->open_partitions)
 		return -EBUSY;
 
 	sync_blockdev(bdev);
diff --git a/fs/block_dev.c b/fs/block_dev.c
index ade5a180ff62d3..6d7e3bd7cb7ce3 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1339,7 +1339,7 @@  static int blkdev_get_part(struct block_device *part, fmode_t mode)
 	if (!(disk->flags & GENHD_FL_UP) || !bdev_nr_sectors(part))
 		goto out_blkdev_put;
 
-	whole->bd_part_count++;
+	disk->open_partitions++;
 	set_init_blocksize(part);
 	if (part->bd_bdi == &noop_backing_dev_info)
 		part->bd_bdi = bdi_get(disk->queue->backing_dev_info);
@@ -1361,7 +1361,7 @@  static void blkdev_put_part(struct block_device *part, fmode_t mode)
 	if (--part->bd_openers)
 		return;
 	blkdev_flush_mapping(part);
-	whole->bd_part_count--;
+	whole->bd_disk->open_partitions--;
 	blkdev_put_whole(whole, mode);
 	bdput(whole);
 }
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index a09660671fa47e..fd3860d18d7ed7 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -39,9 +39,6 @@  struct block_device {
 #endif
 	struct kobject		*bd_holder_dir;
 	u8			bd_partno;
-	/* number of times partitions within this device have been opened. */
-	unsigned		bd_part_count;
-
 	spinlock_t		bd_size_lock; /* for bd_inode->i_size updates */
 	struct gendisk *	bd_disk;
 	struct backing_dev_info *bd_bdi;
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 02ea04144ece7b..146d2dafdccd58 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -155,6 +155,7 @@  struct gendisk {
 #define GD_READ_ONLY			1
 
 	struct mutex open_mutex;	/* open/close mutex */
+	unsigned open_partitions;	/* number of open partitions */
 
 	struct kobject *slave_dir;