Skip to content

Commit

Permalink
block: take bd_mutex around delete_partitions in del_gendisk
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Christoph Hellwig authored and axboe committed Apr 8, 2021
1 parent d3c4a43 commit c76f48e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions block/partitions/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c76f48e

Please sign in to comment.