Skip to contentSkip to conversation

block: Set inode of block_device size to zero when delete gendisk.

PATCH Superseded majianpeng 1 participant 1 message Sep 11, 2013

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

majianpeng

author
#0 lore raw

PATCH 1/2 block: Set inode of block_device size to zero when delete gendisk.

When remove gendisk, set the size of inode of block_device to zero. This is mainly let the vfs know disk removed.

---
 block/genhd.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
block/genhd.c +14 -0
index dadf42b..c3a54b4 100644
@@ -634,6 +634,7 @@ void del_gendisk(struct gendisk *disk)
 {
 	struct disk_part_iter piter;
 	struct hd_struct *part;
+	struct block_device *bdev;
 
 	disk_del_events(disk);
 
@@ -655,6 +656,19 @@ void del_gendisk(struct gendisk *disk)
 	blk_unregister_queue(disk);
 	blk_unregister_region(disk_devt(disk), disk->minors);
 
+	/*
+	 * When used buffer-mode on raw blockdevice,the disk removed.
+	 * But the vfs don't know.So tell the vfs size of disk became zero,
+	 * the buffer write  can return
+	 */
+	bdev = bdget_disk(disk, 0);
+	if (bdev) {
+		mutex_lock(&bdev->bd_inode->i_mutex);
+		i_size_write(bdev->bd_inode, 0);
+		mutex_unlock(&bdev->bd_inode->i_mutex);
+		bdput(bdev);
+	}
+
 	part_stat_set_all(&disk->part0, 0);
 	disk->part0.stamp = 0;
 
Signature · 1 line
1.8.4-rc0