Skip to content

Commit 59e0727

Browse files
Christoph Hellwiggregkh
authored andcommitted
block: add a disk_has_partscan helper
commit 140ce28 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>
1 parent 50ef147 commit 59e0727

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

block/genhd.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,7 @@ int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode)
345345
struct file *file;
346346
int ret = 0;
347347

348-
if (disk->flags & (GENHD_FL_NO_PART | GENHD_FL_HIDDEN))
349-
return -EINVAL;
350-
if (test_bit(GD_SUPPRESS_PART_SCAN, &disk->state))
348+
if (!disk_has_partscan(disk))
351349
return -EINVAL;
352350
if (disk->open_partitions)
353351
return -EBUSY;
@@ -503,8 +501,7 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
503501
goto out_unregister_bdi;
504502

505503
/* Make sure the first partition scan will be proceed */
506-
if (get_capacity(disk) && !(disk->flags & GENHD_FL_NO_PART) &&
507-
!test_bit(GD_SUPPRESS_PART_SCAN, &disk->state))
504+
if (get_capacity(disk) && disk_has_partscan(disk))
508505
set_bit(GD_NEED_PART_SCAN, &disk->state);
509506

510507
bdev_add(disk->part0, ddev->devt);

block/partitions/core.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,7 @@ static int blk_add_partitions(struct gendisk *disk)
573573
struct parsed_partitions *state;
574574
int ret = -EAGAIN, p;
575575

576-
if (disk->flags & GENHD_FL_NO_PART)
577-
return 0;
578-
579-
if (test_bit(GD_SUPPRESS_PART_SCAN, &disk->state))
576+
if (!disk_has_partscan(disk))
580577
return 0;
581578

582579
state = check_partition(disk);

include/linux/blkdev.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,19 @@ static inline unsigned int disk_openers(struct gendisk *disk)
233233
return atomic_read(&disk->part0->bd_openers);
234234
}
235235

236+
/**
237+
* disk_has_partscan - return %true if partition scanning is enabled on a disk
238+
* @disk: disk to check
239+
*
240+
* Returns %true if partitions scanning is enabled for @disk, or %false if
241+
* partition scanning is disabled either permanently or temporarily.
242+
*/
243+
static inline bool disk_has_partscan(struct gendisk *disk)
244+
{
245+
return !(disk->flags & (GENHD_FL_NO_PART | GENHD_FL_HIDDEN)) &&
246+
!test_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
247+
}
248+
236249
/*
237250
* The gendisk is refcounted by the part0 block_device, and the bd_device
238251
* therein is also used for device model presentation in sysfs.

0 commit comments

Comments
 (0)