diff mbox series

[2/2] block: fix a race between del_gendisk and BLKRRPART

Message ID 20210512165050.628550-3-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [1/2] block: prevent block device lookups at the beginning of del_gendisk | expand

Commit Message

Christoph Hellwig May 12, 2021, 4:50 p.m. UTC
From: Gulam Mohamed <gulam.mohamed@oracle.com>

When BLKRRPART is called concurrently with del_gendisk, the partitions
rescan can create a stale partition that will never be be cleaned up.

Fix this by checking the the disk is up before rescanning partitions
while under bd_mutex.

Signed-off-by: Gulam Mohamed <gulam.mohamed@oracle.com>
[hch: split from a larger patch]
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/block_dev.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/fs/block_dev.c b/fs/block_dev.c
index de1a760da62d..577f112c3818 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1244,6 +1244,9 @@  int bdev_disk_changed(struct block_device *bdev, bool invalidate)
 
 	lockdep_assert_held(&bdev->bd_mutex);
 
+	if (!(disk->flags & GENHD_FL_UP))
+		return -ENXIO;
+
 rescan:
 	if (bdev->bd_part_count)
 		return -EBUSY;