mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-07-16 22:29:37 +02:00
block: add a disk_has_partscan helper
commit 140ce28dd3
upstream.
Add a helper to check if partition scanning is enabled instead of
open coding the check in a few places. This now always checks for
the hidden flag even if all but one of the callers are never reachable
for hidden gendisks.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20240502130033.1958492-2-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
fe4549b1d6
commit
d6b6dfff6c
|
@ -345,9 +345,7 @@ int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode)
|
||||||
struct block_device *bdev;
|
struct block_device *bdev;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (disk->flags & (GENHD_FL_NO_PART | GENHD_FL_HIDDEN))
|
if (!disk_has_partscan(disk))
|
||||||
return -EINVAL;
|
|
||||||
if (test_bit(GD_SUPPRESS_PART_SCAN, &disk->state))
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (disk->open_partitions)
|
if (disk->open_partitions)
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
@ -503,8 +501,7 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
|
||||||
goto out_unregister_bdi;
|
goto out_unregister_bdi;
|
||||||
|
|
||||||
/* Make sure the first partition scan will be proceed */
|
/* Make sure the first partition scan will be proceed */
|
||||||
if (get_capacity(disk) && !(disk->flags & GENHD_FL_NO_PART) &&
|
if (get_capacity(disk) && disk_has_partscan(disk))
|
||||||
!test_bit(GD_SUPPRESS_PART_SCAN, &disk->state))
|
|
||||||
set_bit(GD_NEED_PART_SCAN, &disk->state);
|
set_bit(GD_NEED_PART_SCAN, &disk->state);
|
||||||
|
|
||||||
bdev_add(disk->part0, ddev->devt);
|
bdev_add(disk->part0, ddev->devt);
|
||||||
|
|
|
@ -592,10 +592,7 @@ static int blk_add_partitions(struct gendisk *disk)
|
||||||
struct parsed_partitions *state;
|
struct parsed_partitions *state;
|
||||||
int ret = -EAGAIN, p;
|
int ret = -EAGAIN, p;
|
||||||
|
|
||||||
if (disk->flags & GENHD_FL_NO_PART)
|
if (!disk_has_partscan(disk))
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (test_bit(GD_SUPPRESS_PART_SCAN, &disk->state))
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
state = check_partition(disk);
|
state = check_partition(disk);
|
||||||
|
|
|
@ -229,6 +229,19 @@ static inline unsigned int disk_openers(struct gendisk *disk)
|
||||||
return atomic_read(&disk->part0->bd_openers);
|
return atomic_read(&disk->part0->bd_openers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* disk_has_partscan - return %true if partition scanning is enabled on a disk
|
||||||
|
* @disk: disk to check
|
||||||
|
*
|
||||||
|
* Returns %true if partitions scanning is enabled for @disk, or %false if
|
||||||
|
* partition scanning is disabled either permanently or temporarily.
|
||||||
|
*/
|
||||||
|
static inline bool disk_has_partscan(struct gendisk *disk)
|
||||||
|
{
|
||||||
|
return !(disk->flags & (GENHD_FL_NO_PART | GENHD_FL_HIDDEN)) &&
|
||||||
|
!test_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The gendisk is refcounted by the part0 block_device, and the bd_device
|
* The gendisk is refcounted by the part0 block_device, and the bd_device
|
||||||
* therein is also used for device model presentation in sysfs.
|
* therein is also used for device model presentation in sysfs.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user