Skip to content

Commit d6b6dff

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 fe4549b commit d6b6dff

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

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 block_device *bdev;
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
@@ -592,10 +592,7 @@ static int blk_add_partitions(struct gendisk *disk)
592592
struct parsed_partitions *state;
593593
int ret = -EAGAIN, p;
594594

595-
if (disk->flags & GENHD_FL_NO_PART)
596-
return 0;
597-
598-
if (test_bit(GD_SUPPRESS_PART_SCAN, &disk->state))
595+
if (!disk_has_partscan(disk))
599596
return 0;
600597

601598
state = check_partition(disk);

include/linux/blkdev.h

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

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

0 commit comments

Comments
 (0)