Skip to content

Commit 140ce28

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: add a disk_has_partscan helper
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>
1 parent d048757 commit 140ce28

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 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
@@ -230,6 +230,19 @@ static inline unsigned int disk_openers(struct gendisk *disk)
230230
return atomic_read(&disk->part0->bd_openers);
231231
}
232232

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

0 commit comments

Comments
 (0)