diff mbox series

[03/10] block: unhash the block device inodes earlier

Message ID 20210724071249.1284585-4-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [01/10] block: delay freeing the gendisk | expand

Commit Message

Christoph Hellwig July 24, 2021, 7:12 a.m. UTC
Unhash the block device inodes as early as possible.  This ensures that
the inode and thus block_device an't be found in the inode hash as soon
as we start deleting the disk, instead of finding it and rejecting it
later because GENHD_FL_UP is cleared.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/genhd.c           | 8 ++------
 block/partitions/core.c | 8 ++------
 2 files changed, 4 insertions(+), 12 deletions(-)

Comments

Ming Lei July 26, 2021, 10:15 a.m. UTC | #1
On Sat, Jul 24, 2021 at 09:12:42AM +0200, Christoph Hellwig wrote:
> Unhash the block device inodes as early as possible.  This ensures that
> the inode and thus block_device an't be found in the inode hash as soon
> as we start deleting the disk, instead of finding it and rejecting it
> later because GENHD_FL_UP is cleared.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Ming Lei <ming.lei@redhat.com>
diff mbox series

Patch

diff --git a/block/genhd.c b/block/genhd.c
index 298ee78c1bda..7b4beadaa694 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -581,6 +581,8 @@  void del_gendisk(struct gendisk *disk)
 	if (WARN_ON_ONCE(!disk->queue))
 		return;
 
+	remove_inode_hash(disk->part0->bd_inode);
+
 	blk_integrity_del(disk);
 	disk_del_events(disk);
 
@@ -592,12 +594,6 @@  void del_gendisk(struct gendisk *disk)
 	fsync_bdev(disk->part0);
 	__invalidate_device(disk->part0, true);
 
-	/*
-	 * Unhash the bdev inode for this device so that it can't be looked
-	 * up any more even if openers still hold references to it.
-	 */
-	remove_inode_hash(disk->part0->bd_inode);
-
 	set_capacity(disk, 0);
 
 	if (!(disk->flags & GENHD_FL_HIDDEN)) {
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 9902b1635b7d..4540232e68f9 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -285,6 +285,8 @@  static void delete_partition(struct block_device *part)
 {
 	lockdep_assert_held(&part->bd_disk->open_mutex);
 
+	remove_inode_hash(part->bd_inode);
+
 	fsync_bdev(part);
 	__invalidate_device(part, true);
 
@@ -292,12 +294,6 @@  static void delete_partition(struct block_device *part)
 	kobject_put(part->bd_holder_dir);
 	device_del(&part->bd_device);
 
-	/*
-	 * Remove the block device from the inode hash, so that it cannot be
-	 * looked up any more even when openers still hold references.
-	 */
-	remove_inode_hash(part->bd_inode);
-
 	put_device(&part->bd_device);
 }