Skip to content

Commit 181bb9c

Browse files
amateurcowaxboe
authored andcommitted
block: remove redundant GD_NEED_PART_SCAN in add_disk_final()
add_disk_final() sets GD_NEED_PART_SCAN before calling bdev_add(), then calls disk_scan_partitions() which sets the flag itself. The early set is redundant and introduces a race. Between bdev_add() and disk_scan_partitions(), concurrent openers (multipathd, blkid, LVM) see the flag in blkdev_get_whole() and trigger bdev_disk_changed(). When disk_scan_partitions() then runs, it calls bdev_disk_changed() again, dropping the partitions the concurrent opener already created before re-adding them, which can result in transient partition disappearances. The race is observable by inserting an msleep() between bdev_add() and disk_scan_partitions() while running concurrent open() calls during device bind. Without artificial delay, it manifests under scheduling pressure during boot on systems with aggressive device scanners (multipathd, systemd-udevd). Therefore, do not set GD_NEED_PART_SCAN in add_disk_final(). Other GD_NEED_PART_SCAN consumers (blkdev_get_whole(), sd_need_revalidate()) should not be affected as the flag is set internally by disk_scan_partitions(). The retry-on-next-open intention from commit e5cfefa ("block: fix scan partition for exclusively open device again") should also not be affected as the early return paths in disk_scan_partitions() should be unreachable at device registration time (bd_holder is NULL and open_partitions is zero). Fixes: e5cfefa ("block: fix scan partition for exclusively open device again") Cc: stable@vger.kernel.org Signed-off-by: Connor Williamson <connordw@amazon.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://patch.msgid.link/20260615130715.53693-1-connordw@amazon.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent bd910a7 commit 181bb9c

1 file changed

Lines changed: 0 additions & 4 deletions

File tree

block/genhd.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,6 @@ static void add_disk_final(struct gendisk *disk)
407407
struct device *ddev = disk_to_dev(disk);
408408

409409
if (!(disk->flags & GENHD_FL_HIDDEN)) {
410-
/* Make sure the first partition scan will be proceed */
411-
if (get_capacity(disk) && disk_has_partscan(disk))
412-
set_bit(GD_NEED_PART_SCAN, &disk->state);
413-
414410
bdev_add(disk->part0, ddev->devt);
415411
if (get_capacity(disk))
416412
disk_scan_partitions(disk, BLK_OPEN_READ);

0 commit comments

Comments
 (0)