From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>,
Naohiro Aota <naohiro.aota@wdc.com>,
linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org
Subject: [PATCH 03/10] block: unhash the block device inodes earlier
Date: Sat, 24 Jul 2021 09:12:42 +0200 [thread overview]
Message-ID: <20210724071249.1284585-4-hch@lst.de> (raw)
In-Reply-To: <20210724071249.1284585-1-hch@lst.de>
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(-)
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);
}
--
2.30.2
next prev parent reply other threads:[~2021-07-24 7:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-24 7:12 fixes and cleanups for block_device refcounting v3 Christoph Hellwig
2021-07-24 7:12 ` [PATCH 01/10] block: delay freeing the gendisk Christoph Hellwig
2021-07-24 7:12 ` [PATCH 02/10] block: assert the locking state in delete_partition Christoph Hellwig
2021-07-24 7:12 ` Christoph Hellwig [this message]
2021-07-26 10:15 ` [PATCH 03/10] block: unhash the block device inodes earlier Ming Lei
2021-07-24 7:12 ` [PATCH 04/10] block: remove the GENHD_FL_UP check in blkdev_get_no_open Christoph Hellwig
2021-07-26 10:16 ` Ming Lei
2021-07-24 7:12 ` [PATCH 05/10] block: allocate bd_meta_info later in add_partitions Christoph Hellwig
2021-07-24 7:12 ` [PATCH 06/10] block: change the refcounting for partitions Christoph Hellwig
2021-07-26 2:20 ` Damien Le Moal
2021-07-26 10:17 ` Ming Lei
2021-07-24 7:12 ` [PATCH 07/10] btrfs: store a block_device in struct btrfs_ordered_extent Christoph Hellwig
2021-07-24 7:12 ` [PATCH 08/10] loop: don't grab a reference to the block device Christoph Hellwig
2021-07-24 7:12 ` [PATCH 09/10] block: remove bdgrab Christoph Hellwig
2021-07-24 7:12 ` [PATCH 10/10] block: remove bdput Christoph Hellwig
2021-07-24 7:22 ` fixes and cleanups for block_device refcounting v3 Christoph Hellwig
2021-07-24 16:06 ` Jens Axboe
2021-07-24 16:54 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210724071249.1284585-4-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=naohiro.aota@wdc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).