linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Christoph Hellwig <hch@lst.de>
Cc: Christian Brauner <brauner@kernel.org>,
	Al Viro <viro@zeniv.linux.org.uk>, Jens Axboe <axboe@kernel.dk>,
	Jan Kara <jack@suse.cz>, Denis Efremov <efremov@linux.com>,
	linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 2/5] block: WARN_ON_ONCE() when we remove active partitions
Date: Thu, 19 Oct 2023 10:31:07 +0200	[thread overview]
Message-ID: <20231019083107.mm7tcgv6of6pszac@quack3> (raw)
In-Reply-To: <20231017184823.1383356-3-hch@lst.de>

On Tue 17-10-23 20:48:20, Christoph Hellwig wrote:
> From: Christian Brauner <brauner@kernel.org>
> 
> The logic for disk->open_partitions is:
> 
> blkdev_get_by_*()
> -> bdev_is_partition()
>    -> blkdev_get_part()
>       -> blkdev_get_whole() // bdev_whole->bd_openers++
>       -> if (part->bd_openers == 0)
>                  disk->open_partitions++
>          part->bd_openers
> 
> In other words, when we first claim/open a partition we increment
> disk->open_partitions and only when all part->bd_openers are closed will
> disk->open_partitions be zero. That should mean that
> disk->open_partitions is always > 0 as long as there's anyone that
> has an open partition.
> 
> So the check for disk->open_partitions should meand that we can never
> remove an active partition that has a holder and holder ops set. Assert
> that in the code. The main disk isn't removed so that check doesn't work
> for disk->part0 which is what we want. After all we only care about
> partition not about the main disk.
> 
> Signed-off-by: Christian Brauner <brauner@kernel.org>

Looks good to me. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  block/partitions/core.c | 30 +++++++++++++++++-------------
>  1 file changed, 17 insertions(+), 13 deletions(-)
> 
> diff --git a/block/partitions/core.c b/block/partitions/core.c
> index b0585536b407a5..f47ffcfdfcec22 100644
> --- a/block/partitions/core.c
> +++ b/block/partitions/core.c
> @@ -274,17 +274,6 @@ void drop_partition(struct block_device *part)
>  	put_device(&part->bd_device);
>  }
>  
> -static void delete_partition(struct block_device *part)
> -{
> -	/*
> -	 * 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);
> -	bdev_mark_dead(part, false);
> -	drop_partition(part);
> -}
> -
>  static ssize_t whole_disk_show(struct device *dev,
>  			       struct device_attribute *attr, char *buf)
>  {
> @@ -674,8 +663,23 @@ int bdev_disk_changed(struct gendisk *disk, bool invalidate)
>  	sync_blockdev(disk->part0);
>  	invalidate_bdev(disk->part0);
>  
> -	xa_for_each_start(&disk->part_tbl, idx, part, 1)
> -		delete_partition(part);
> +	xa_for_each_start(&disk->part_tbl, idx, part, 1) {
> +		/*
> +		 * 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);
> +
> +		/*
> +		 * If @disk->open_partitions isn't elevated but there's
> +		 * still an active holder of that block device things
> +		 * are broken.
> +		 */
> +		WARN_ON_ONCE(atomic_read(&part->bd_openers));
> +		invalidate_bdev(part);
> +		drop_partition(part);
> +	}
>  	clear_bit(GD_NEED_PART_SCAN, &disk->state);
>  
>  	/*
> -- 
> 2.39.2
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  parent reply	other threads:[~2023-10-19  8:31 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-17 18:48 don't take s_umount under open_mutex Christoph Hellwig
2023-10-17 18:48 ` [PATCH 1/5] block: simplify bdev_del_partition() Christoph Hellwig
2023-10-18  2:33   ` Ming Lei
2023-10-17 18:48 ` [PATCH 2/5] block: WARN_ON_ONCE() when we remove active partitions Christoph Hellwig
2023-10-18  2:36   ` Ming Lei
2023-10-19  8:31   ` Jan Kara [this message]
2023-10-17 18:48 ` [PATCH 3/5] block: move bdev_mark_dead out of disk_check_media_change Christoph Hellwig
2023-10-18  3:16   ` Ming Lei
2023-10-18  6:46     ` Christoph Hellwig
2023-10-18  9:15       ` Ming Lei
2023-10-18 12:10         ` Christoph Hellwig
2023-10-18  9:24   ` Christian Brauner
2023-10-19  5:57     ` Christoph Hellwig
2023-10-19  7:24       ` Christian Brauner
2023-10-19  8:34   ` Jan Kara
2023-10-17 18:48 ` [PATCH 4/5] block: assert that we're not holding open_mutex over blk_report_disk_dead Christoph Hellwig
2023-10-18  3:18   ` Ming Lei
2023-10-19  8:43   ` Jan Kara
2023-10-17 18:48 ` [PATCH 5/5] fs: assert that open_mutex isn't held over holder ops Christoph Hellwig
2023-10-18  9:53   ` Ming Lei
2023-10-19  8:43   ` Jan Kara
2023-10-19  9:35 ` don't take s_umount under open_mutex Christian Brauner
2023-10-19 11:27   ` Jens Axboe

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=20231019083107.mm7tcgv6of6pszac@quack3 \
    --to=jack@suse.cz \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=efremov@linux.com \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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).