linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Jens Axboe <axboe@kernel.dk>, Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>,
	linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 3/8] block: grab a device model reference in blkdev_get_no_open
Date: Thu, 22 Jul 2021 10:47:08 +0800	[thread overview]
Message-ID: <YPjcLDXYKbN1yl22@T590> (raw)
In-Reply-To: <20210721153523.103818-4-hch@lst.de>

On Wed, Jul 21, 2021 at 05:35:18PM +0200, Christoph Hellwig wrote:
> Opening a block device needs to ensure it is fully present instead of
> just the allocated memory.  Switch from an inode reference as obtained
> by bdget to a full device model reference.
> 
> In fact we should not use inode references for anything in the block
> layer.  There are three users left, two can be trivially removed
> and the third (xen-blkfront) is a complete mess that needs more
> attention.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/block_dev.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/block_dev.c b/fs/block_dev.c
> index 9ef4f1fc2cb0..24a6970f3623 100644
> --- a/fs/block_dev.c
> +++ b/fs/block_dev.c
> @@ -1342,9 +1342,16 @@ struct block_device *blkdev_get_no_open(dev_t dev)
>  		goto bdput;
>  	if ((disk->flags & (GENHD_FL_UP | GENHD_FL_HIDDEN)) != GENHD_FL_UP)
>  		goto put_disk;
> -	if (!try_module_get(bdev->bd_disk->fops->owner))
> +	if (!try_module_get(disk->fops->owner))
>  		goto put_disk;
> +
> +	/* switch to a device model reference instead of the inode one: */
> +	if (!kobject_get_unless_zero(&bdev->bd_device.kobj))

If bdev->bd_device.kobj is grabbed in every open, getting disk reference might
be moved into add_partition, and drop it in part_release(). Then we can avoid
extra disk reference in open/close().

Not mention two disk references are actually grabbed in case of opening disk.

Thanks,
Ming


  reply	other threads:[~2021-07-22  2:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-21 15:35 fixes and cleanups for block_device refcounting Christoph Hellwig
2021-07-21 15:35 ` [PATCH 1/8] block: delay freeing the gendisk Christoph Hellwig
2021-07-22  2:05   ` Ming Lei
2021-07-21 15:35 ` [PATCH 2/8] block: assert the locking state in delete_partition Christoph Hellwig
2021-07-22  2:06   ` Ming Lei
2021-07-21 15:35 ` [PATCH 3/8] block: grab a device model reference in blkdev_get_no_open Christoph Hellwig
2021-07-22  2:47   ` Ming Lei [this message]
2021-07-21 15:35 ` [PATCH 4/8] block: don't grab a reference to the whole device in blkdev_get_part Christoph Hellwig
2021-07-21 15:35 ` [PATCH 5/8] btrfs: no need to grab a reference to disk->part0 Christoph Hellwig
2021-07-21 16:15   ` David Sterba
2021-07-21 15:35 ` [PATCH 6/8] loop: don't grab a reference to the block device Christoph Hellwig
2021-07-21 15:35 ` [PATCH 7/8] block: remove bdgrab Christoph Hellwig
2021-07-21 15:35 ` [PATCH 8/8] block: remove bdget/bdput Christoph Hellwig
2021-07-21 20:52 ` fixes and cleanups for block_device refcounting Josef Bacik

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=YPjcLDXYKbN1yl22@T590 \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=dsterba@suse.com \
    --cc=hch@lst.de \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /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).