]> www.infradead.org Git - users/hch/block.git/commitdiff
block: take bd_mutex around delete_partitions in del_gendisk
authorChristoph Hellwig <hch@lst.de>
Tue, 30 Mar 2021 05:43:46 +0000 (07:43 +0200)
committerChristoph Hellwig <hch@lst.de>
Tue, 30 Mar 2021 05:44:40 +0000 (07:44 +0200)
There is nothing preventing an ioctl from trying do delete partition
concurrenly with del_gendisk, so take bd_mutex to serialize against that.

Signed-off-by: Christoph Hellwig <hch@lst.de>
block/genhd.c
block/partitions/core.c

index 8303ec67fd70991ed7c5fdcc289cefac5bae0faa..e3f3c2321773f9aee56fc320ab41bee6bf4331d9 100644 (file)
@@ -680,7 +680,11 @@ void del_gendisk(struct gendisk *disk)
         * disk is marked as dead (GENHD_FL_UP cleared).
         */
        down_write(&bdev_lookup_sem);
+
+       mutex_lock(&disk->part0->bd_mutex);
        blk_drop_partitions(disk);
+       mutex_unlock(&disk->part0->bd_mutex);
+
        fsync_bdev(disk->part0);
        __invalidate_device(disk->part0, true);
 
index 6ba7b28b5afa58c56ec4ba059b4b7ba5c7eec13a..fbc38e178c631f88ceaffed84b2a4f07a579e7b4 100644 (file)
@@ -531,6 +531,8 @@ void blk_drop_partitions(struct gendisk *disk)
        struct disk_part_iter piter;
        struct block_device *part;
 
+       lockdep_assert_held(&disk->part0->bd_mutex);
+
        disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
        while ((part = disk_part_iter_next(&piter)))
                delete_partition(part);