Skip to contentSkip to conversation

block: Don't reread partitions of disk which already mouted.

PATCH New majianpeng 1 participant 1 message Sep 29, 2013 Block layer

lore
Share & tools
lore

majianpeng

author
#0 lore raw

PATCH 1/1 block: Don't reread partitions of disk which already mouted.

If reread partitions of disk, the paths are:
blkdev_ioctl->blkdev_reread_part->rescan_partitions->drop_partitions ->invalidate_partition->__invalidate_device
In func __invalidate_device, if disk already mounted, it will do shrink_dcache_sb and invalidate_inodes.
This operation will effect the fs.
So add a judgement before doing rescan_partiontions to judge disk whether mounted.

---
 block/ioctl.c | 8 ++++++++
 1 file changed, 8 insertions(+)
block/ioctl.c +8 -0
index a31d91d..374af7e 100644
@@ -154,11 +154,19 @@ static int blkdev_reread_part(struct block_device *bdev)
 {
 	struct gendisk *disk = bdev->bd_disk;
 	int res;
+	struct super_block *sb;
 
 	if (!disk_part_scan_enabled(disk) || bdev != bdev->bd_contains)
 		return -EINVAL;
 	if (!capable(CAP_SYS_ADMIN))
 		return -EACCES;
+
+	sb = get_super(bdev);
+	if (sb) {
+		drop_super(sb);
+		return -EBUSY;
+	}
+
 	if (!mutex_trylock(&bdev->bd_mutex))
 		return -EBUSY;
 	res = rescan_partitions(disk, bdev);
Signature · 2 lines
1.8.4
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ¥Šwÿº{.nÇ+‰·¥Š{±þG«�éÿŠ{ayºʇڙë,j­¢f£¢·hš�ï�êÿ‘êçz_è®(­éšŽŠÝ¢j"�ú¶m§ÿÿ¾«þG«�éÿ¢¸?™¨è­Ú&£ø§~�á¶iO•æ¬z·švØ^¶m§ÿÿÃÿ¶ìÿ¢¸?–I¥