Skip to contentSkip to conversation

block: clear GD_NEED_PART_SCAN later in bdev_disk_changed

PATCH Applied [email protected] 3 participants 3 messages Mar 23, 2021 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: clear GD_NEED_PART_SCAN later in bdev_disk_changed

From: Chris Chiu <[email protected]>

The GD_NEED_PART_SCAN is set by bdev_check_media_change to initiate a partition scan while removing a block device. It should be cleared after blk_drop_paritions because blk_drop_paritions could return -EBUSY and then the consequence __blkdev_get has no chance to do delete_partition if GD_NEED_PART_SCAN already cleared.

It causes some problems on some card readers. Ex. Realtek card reader 0bda:0328 and 0bda:0158. The device node of the partition will not disappear after the memory card removed. Thus the user applications can not update the device mapping correctly.

---
 fs/block_dev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/block_dev.c +2 -2
index 92ed7d5df677..28d583fcdc2c 100644
@@ -1240,13 +1240,13 @@ int bdev_disk_changed(struct block_device *bdev, bool invalidate)
 
 	lockdep_assert_held(&bdev->bd_mutex);
 
-	clear_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
-
 rescan:
 	ret = blk_drop_partitions(bdev);
 	if (ret)
 		return ret;
 
+	clear_bit(GD_NEED_PART_SCAN, &disk->state);
+
 	/*
 	 * Historically we only set the capacity to zero for devices that
 	 * support partitions (independ of actually having partitions created).
Signature · 1 line
2.20.1
Applied
#2 lore raw
In reply to [email protected]
Quoted 8 lines · On 3/23/21 2:52 AM, [email protected] wrote:

From: Chris Chiu <[email protected]>

The GD_NEED_PART_SCAN is set by bdev_check_media_change to initiate a partition scan while removing a block device. It should be cleared after blk_drop_paritions because blk_drop_paritions could return -EBUSY and then the consequence __blkdev_get has no chance to do delete_partition if GD_NEED_PART_SCAN already cleared.

Quoted 4 lines

It causes some problems on some card readers. Ex. Realtek card reader 0bda:0328 and 0bda:0158. The device node of the partition will not disappear after the memory card removed. Thus the user applications can not update the device mapping correctly.

Applied, thanks.

Signature · 1 line
Jens Axboe