Skip to content

Commit

Permalink
block: move bd_part_count to struct gendisk
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Hannes Reinecke <[email protected]>
Reviewed-by: Ming Lei <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Christoph Hellwig authored and axboe committed Jun 1, 2021
1 parent c8276b9 commit ab4b570
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion block/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static int blkdev_reread_part(struct block_device *bdev, fmode_t mode)
return -EINVAL;
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
if (bdev->bd_part_count)
if (bdev->bd_disk->open_partitions)
return -EBUSY;

/*
Expand Down
6 changes: 3 additions & 3 deletions fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ int bdev_disk_changed(struct block_device *bdev, bool invalidate)
return -ENXIO;

rescan:
if (bdev->bd_part_count)
if (disk->open_partitions)
return -EBUSY;
sync_blockdev(bdev);
invalidate_bdev(bdev);
Expand Down Expand Up @@ -1348,7 +1348,7 @@ static int blkdev_get_part(struct block_device *part, fmode_t mode)
if (!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);
Expand All @@ -1370,7 +1370,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);
}
Expand Down
3 changes: 0 additions & 3 deletions include/linux/blk_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/linux/genhd.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ struct gendisk {
#define GD_QUEUE_REF 2

struct mutex open_mutex; /* open/close mutex */
unsigned open_partitions; /* number of open partitions */

struct kobject *slave_dir;

Expand Down

0 comments on commit ab4b570

Please sign in to comment.