Skip to content

Commit c76f48e

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: take bd_mutex around delete_partitions in del_gendisk
There is nothing preventing an ioctl from trying do delete partition concurrenly with del_gendisk, so take open_mutex to serialize against that. Signed-off-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent d3c4a43 commit c76f48e

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

block/genhd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,11 @@ void del_gendisk(struct gendisk *disk)
680680
* disk is marked as dead (GENHD_FL_UP cleared).
681681
*/
682682
down_write(&bdev_lookup_sem);
683+
684+
mutex_lock(&disk->part0->bd_mutex);
683685
blk_drop_partitions(disk);
686+
mutex_unlock(&disk->part0->bd_mutex);
687+
684688
fsync_bdev(disk->part0);
685689
__invalidate_device(disk->part0, true);
686690

block/partitions/core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ void blk_drop_partitions(struct gendisk *disk)
531531
struct disk_part_iter piter;
532532
struct block_device *part;
533533

534+
lockdep_assert_held(&disk->part0->bd_mutex);
535+
534536
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
535537
while ((part = disk_part_iter_next(&piter)))
536538
delete_partition(part);

0 commit comments

Comments
 (0)