Commit 5b26804b authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

md: simplify md_open

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: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Reviewed-by: default avatarLogan Gunthorpe <logang@deltatee.com>
Signed-off-by: default avatarSong Liu <song@kernel.org>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 12a6caf2
...@@ -7783,45 +7783,33 @@ static int md_set_read_only(struct block_device *bdev, bool ro) ...@@ -7783,45 +7783,33 @@ static int md_set_read_only(struct block_device *bdev, bool ro)
static int md_open(struct block_device *bdev, fmode_t mode) static int md_open(struct block_device *bdev, fmode_t mode)
{ {
/* struct mddev *mddev;
* 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);
int err; int err;
spin_lock(&all_mddevs_lock);
mddev = mddev_get(bdev->bd_disk->private_data);
spin_unlock(&all_mddevs_lock);
if (!mddev) if (!mddev)
return -ENODEV; return -ENODEV;
if (mddev->gendisk != bdev->bd_disk) { err = mutex_lock_interruptible(&mddev->open_mutex);
/* we are racing with mddev_put which is discarding this if (err)
* 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)))
goto out; goto out;
if (test_bit(MD_CLOSING, &mddev->flags)) { err = -ENODEV;
mutex_unlock(&mddev->open_mutex); if (test_bit(MD_CLOSING, &mddev->flags))
err = -ENODEV; goto out_unlock;
goto out;
}
err = 0;
atomic_inc(&mddev->openers); atomic_inc(&mddev->openers);
mutex_unlock(&mddev->open_mutex); mutex_unlock(&mddev->open_mutex);
bdev_check_media_change(bdev); bdev_check_media_change(bdev);
out: return 0;
if (err)
mddev_put(mddev); out_unlock:
mutex_unlock(&mddev->open_mutex);
out:
mddev_put(mddev);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment