[PATCH 05/11] block: take bd_mutex around delete_partitions in del_gendisk

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <hch@xxxxxx>
---
 block/genhd.c           | 4 ++++
 block/partitions/core.c | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/block/genhd.c b/block/genhd.c
index 8303ec67fd7099..e3f3c2321773f9 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -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);
 
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 536f7c5bb0b6d2..9fbaec466b516d 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -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);
-- 
2.30.1




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Kernel Development]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Info]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Linux Media]     [Device Mapper]

  Powered by Linux