All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Christoph Hellwig <hch@lst.de>, Song Liu <song@kernel.org>
Cc: Logan Gunthorpe <logang@deltatee.com>,
	linux-raid@vger.kernel.org, linux-block@vger.kernel.org
Subject: Re: [PATCH 10/10] md: simplify md_open
Date: Mon, 18 Jul 2022 09:19:03 +0200	[thread overview]
Message-ID: <dc52a1b9-f007-e42b-0ef0-0de2387aa2f5@suse.de> (raw)
In-Reply-To: <20220718063410.338626-11-hch@lst.de>

On 7/18/22 08:34, Christoph Hellwig wrote:
> Now that devices are on the all_mddevs list until the gendisk is freed,
> there can't be any duplicates.  Remove the global list lookup and just
> grab a reference.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   drivers/md/md.c | 42 +++++++++++++++---------------------------
>   1 file changed, 15 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 08cf21ad4c2d7..9b1e61b4bac8b 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -7785,45 +7785,33 @@ static int md_set_read_only(struct block_device *bdev, bool ro)
>   
>   static int md_open(struct block_device *bdev, fmode_t mode)
>   {
> -	/*
> -	 * Succeed if we can lock the mddev, which confirms that
> -	 * it isn't being stopped right now.
> -	 */
> -	struct mddev *mddev = mddev_find(bdev->bd_dev);
> +	struct mddev *mddev;
>   	int err;
>   
> +	spin_lock(&all_mddevs_lock);
> +	mddev = mddev_get(bdev->bd_disk->private_data);
> +	spin_unlock(&all_mddevs_lock);
>   	if (!mddev)
>   		return -ENODEV;
>   
> -	if (mddev->gendisk != bdev->bd_disk) {
> -		/* we are racing with mddev_put which is discarding this
> -		 * bd_disk.
> -		 */
> -		mddev_put(mddev);
> -		/* Wait until bdev->bd_disk is definitely gone */
> -		if (work_pending(&mddev->del_work))
> -			flush_workqueue(md_misc_wq);
> -		return -EBUSY;
> -	}
> -	BUG_ON(mddev != bdev->bd_disk->private_data);
> -
> -	if ((err = mutex_lock_interruptible(&mddev->open_mutex)))
> +	err = mutex_lock_interruptible(&mddev->open_mutex);
> +	if (err)
>   		goto out;
>   
> -	if (test_bit(MD_CLOSING, &mddev->flags)) {
> -		mutex_unlock(&mddev->open_mutex);
> -		err = -ENODEV;
> -		goto out;
> -	}
> +	err = -ENODEV;
> +	if (test_bit(MD_CLOSING, &mddev->flags))
> +		goto out_unlock;
>   
> -	err = 0;
>   	atomic_inc(&mddev->openers);
>   	mutex_unlock(&mddev->open_mutex);
>   
>   	bdev_check_media_change(bdev);
> - out:
> -	if (err)
> -		mddev_put(mddev);
> +	return 0;
> +
> +out_unlock:
> +	mutex_unlock(&mddev->open_mutex);
> +out:
> +	mddev_put(mddev);
>   	return err;
>   }
>   

Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes


  reply	other threads:[~2022-07-18  7:19 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-18  6:34 fix md disk_name lifetime problems v3 Christoph Hellwig
2022-07-18  6:34 ` [PATCH 01/10] md: fix mddev->kobj lifetime Christoph Hellwig
2022-07-18  6:55   ` Hannes Reinecke
2022-07-18 19:48   ` Logan Gunthorpe
2022-07-18  6:34 ` [PATCH 02/10] md: fix error handling in md_alloc Christoph Hellwig
2022-07-18  7:00   ` Hannes Reinecke
2022-07-18 19:48   ` Logan Gunthorpe
2022-07-18  6:34 ` [PATCH 03/10] md: implement ->free_disk Christoph Hellwig
2022-07-18  7:01   ` Hannes Reinecke
2022-07-18 20:01   ` Logan Gunthorpe
2022-07-18  6:34 ` [PATCH 04/10] md: rename md_free to md_kobj_release Christoph Hellwig
2022-07-18  7:01   ` Hannes Reinecke
2022-07-18 20:02   ` Logan Gunthorpe
2022-07-18  6:34 ` [PATCH 05/10] md: factor out the rdev overlaps check from rdev_size_store Christoph Hellwig
2022-07-18  7:02   ` Hannes Reinecke
2022-07-18 20:02   ` Logan Gunthorpe
2022-07-18  6:34 ` [PATCH 06/10] md: stop using for_each_mddev in md_do_sync Christoph Hellwig
2022-07-18  7:03   ` Hannes Reinecke
2022-07-18 20:02   ` Logan Gunthorpe
2022-07-18  6:34 ` [PATCH 07/10] md: stop using for_each_mddev in md_notify_reboot Christoph Hellwig
2022-07-18  7:05   ` Hannes Reinecke
2022-07-18 20:03   ` Logan Gunthorpe
2022-07-18  6:34 ` [PATCH 08/10] md: stop using for_each_mddev in md_exit Christoph Hellwig
2022-07-18  7:10   ` Hannes Reinecke
2022-07-19  7:03     ` Christoph Hellwig
2022-07-19  7:06       ` Hannes Reinecke
2022-07-18 20:03   ` Logan Gunthorpe
2022-07-18  6:34 ` [PATCH 09/10] md: only delete entries from all_mddevs when the disk is freed Christoph Hellwig
2022-07-18  7:17   ` Hannes Reinecke
2022-07-18 18:20     ` Song Liu
2022-07-19  5:06       ` Christoph Hellwig
2022-07-19  6:28         ` Song Liu
2022-07-19  7:00         ` Hannes Reinecke
2022-07-19  7:14     ` Christoph Hellwig
2022-07-19  7:59       ` Hannes Reinecke
2022-07-18  6:34 ` [PATCH 10/10] md: simplify md_open Christoph Hellwig
2022-07-18  7:19   ` Hannes Reinecke [this message]
2022-07-19  9:18 fix md disk_name lifetime problems v4 Christoph Hellwig
2022-07-19  9:18 ` [PATCH 10/10] md: simplify md_open 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=dc52a1b9-f007-e42b-0ef0-0de2387aa2f5@suse.de \
    --to=hare@suse.de \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=logang@deltatee.com \
    --cc=song@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.