block: always remove partitions from blk_drop_partitions()
PATCH 1/1 block: always remove partitions from blk_drop_partitions()
In theory, when GENHD_FL_NO_PART_SCAN is set, no partitions can be created on one disk. However, ioctl(BLKPG, BLKPG_ADD_PARTITION) doesn't check GENHD_FL_NO_PART_SCAN, so partitions still can be added even though GENHD_FL_NO_PART_SCAN is set.
So far blk_drop_partitions() only removes partitions when disk_part_scan_enabled() return true. This way can make ghost partition on loop device after changing/clearing FD in case that PARTSCAN is disabled, such as partitions can be added via 'parted' on loop disk even though GENHD_FL_NO_PART_SCAN is set.
Fix this issue by always removing partitions in blk_drop_partitions(), and this way is correct because the current code supposes that no partitions can be added in case of GENHD_FL_NO_PART_SCAN.
--- block/partitions/core.c | 2 -- 1 file changed, 2 deletions(-)
block/partitions/core.c +0 -2
@@ -619,8 +619,6 @@ int blk_drop_partitions(struct block_device *bdev)struct disk_part_iter piter;struct hd_struct *part; -if (!disk_part_scan_enabled (bdev->bd_disk)) -return 0 ;if (bdev->bd_part_count)return -EBUSY ;
Signature · 1 line
2.25.2
Quoted 5 lines · Ming Lei
In theory, when
GENHD_FL_NO_PART_SCANis set, no partitions can be created on one disk. However,ioctl(BLKPG, BLKPG_ADD_PARTITION)doesn't checkGENHD_FL_NO_PART_SCAN, so partitions still can be added even thoughGENHD_FL_NO_PART_SCANis set.
Quoted 8 lines
So far
blk_drop_partitions()only removes partitions whendisk_part_scan_enabled()return true. This way can make ghost partition on loop device after changing/clearing FD in case that PARTSCAN is disabled, such as partitions can be added via 'parted' on loop disk even thoughGENHD_FL_NO_PART_SCANis set.Fix this issue by always removing partitions in
blk_drop_partitions(), and this way is correct because the current code supposes that no partitions can be added in case ofGENHD_FL_NO_PART_SCAN.
The changelog has a few overly long lines.
Otherwise:
Quoted 5 lines · Ming Lei
In theory, when
GENHD_FL_NO_PART_SCANis set, no partitions can be created on one disk. However,ioctl(BLKPG, BLKPG_ADD_PARTITION)doesn't checkGENHD_FL_NO_PART_SCAN, so partitions still can be added even thoughGENHD_FL_NO_PART_SCANis set.
Quoted 8 lines
So far
blk_drop_partitions()only removes partitions whendisk_part_scan_enabled()return true. This way can make ghost partition on loop device after changing/clearing FD in case that PARTSCAN is disabled, such as partitions can be added via 'parted' on loop disk even thoughGENHD_FL_NO_PART_SCANis set.Fix this issue by always removing partitions in
blk_drop_partitions(), and this way is correct because the current code supposes that no partitions can be added in case ofGENHD_FL_NO_PART_SCAN.
Applied, thanks.
Signature · 1 line
Jens Axboe