Commit 9f0f5a30 authored by Jan Kara's avatar Jan Kara Committed by Christian Brauner

md: Convert to bdev_open_by_dev()

Convert md to use bdev_open_by_dev() and pass the handle around. We also
don't need the 'Holder' flag anymore so remove it.

CC: linux-raid@vger.kernel.org
CC: Song Liu <song@kernel.org>
Acked-by: default avatarSong Liu <song@kernel.org>
Acked-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarChristian Brauner <brauner@kernel.org>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20230927093442.25915-11-jack@suse.czSigned-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent c2fce61f
...@@ -2452,8 +2452,7 @@ static void export_rdev(struct md_rdev *rdev, struct mddev *mddev) ...@@ -2452,8 +2452,7 @@ static void export_rdev(struct md_rdev *rdev, struct mddev *mddev)
if (test_bit(AutoDetected, &rdev->flags)) if (test_bit(AutoDetected, &rdev->flags))
md_autodetect_dev(rdev->bdev->bd_dev); md_autodetect_dev(rdev->bdev->bd_dev);
#endif #endif
blkdev_put(rdev->bdev, bdev_release(rdev->bdev_handle);
test_bit(Holder, &rdev->flags) ? rdev : &claim_rdev);
rdev->bdev = NULL; rdev->bdev = NULL;
kobject_put(&rdev->kobj); kobject_put(&rdev->kobj);
} }
...@@ -3633,7 +3632,6 @@ EXPORT_SYMBOL_GPL(md_rdev_init); ...@@ -3633,7 +3632,6 @@ EXPORT_SYMBOL_GPL(md_rdev_init);
static struct md_rdev *md_import_device(dev_t newdev, int super_format, int super_minor) static struct md_rdev *md_import_device(dev_t newdev, int super_format, int super_minor)
{ {
struct md_rdev *rdev; struct md_rdev *rdev;
struct md_rdev *holder;
sector_t size; sector_t size;
int err; int err;
...@@ -3648,21 +3646,16 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe ...@@ -3648,21 +3646,16 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
if (err) if (err)
goto out_clear_rdev; goto out_clear_rdev;
if (super_format == -2) { rdev->bdev_handle = bdev_open_by_dev(newdev,
holder = &claim_rdev; BLK_OPEN_READ | BLK_OPEN_WRITE,
} else { super_format == -2 ? &claim_rdev : rdev, NULL);
holder = rdev; if (IS_ERR(rdev->bdev_handle)) {
set_bit(Holder, &rdev->flags);
}
rdev->bdev = blkdev_get_by_dev(newdev, BLK_OPEN_READ | BLK_OPEN_WRITE,
holder, NULL);
if (IS_ERR(rdev->bdev)) {
pr_warn("md: could not open device unknown-block(%u,%u).\n", pr_warn("md: could not open device unknown-block(%u,%u).\n",
MAJOR(newdev), MINOR(newdev)); MAJOR(newdev), MINOR(newdev));
err = PTR_ERR(rdev->bdev); err = PTR_ERR(rdev->bdev_handle);
goto out_clear_rdev; goto out_clear_rdev;
} }
rdev->bdev = rdev->bdev_handle->bdev;
kobject_init(&rdev->kobj, &rdev_ktype); kobject_init(&rdev->kobj, &rdev_ktype);
...@@ -3693,7 +3686,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe ...@@ -3693,7 +3686,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
return rdev; return rdev;
out_blkdev_put: out_blkdev_put:
blkdev_put(rdev->bdev, holder); bdev_release(rdev->bdev_handle);
out_clear_rdev: out_clear_rdev:
md_rdev_clear(rdev); md_rdev_clear(rdev);
out_free_rdev: out_free_rdev:
......
...@@ -59,6 +59,7 @@ struct md_rdev { ...@@ -59,6 +59,7 @@ struct md_rdev {
*/ */
struct block_device *meta_bdev; struct block_device *meta_bdev;
struct block_device *bdev; /* block device handle */ struct block_device *bdev; /* block device handle */
struct bdev_handle *bdev_handle; /* Handle from open for bdev */
struct page *sb_page, *bb_page; struct page *sb_page, *bb_page;
int sb_loaded; int sb_loaded;
...@@ -211,9 +212,6 @@ enum flag_bits { ...@@ -211,9 +212,6 @@ enum flag_bits {
* check if there is collision between raid1 * check if there is collision between raid1
* serial bios. * serial bios.
*/ */
Holder, /* rdev is used as holder while opening
* underlying disk exclusively.
*/
}; };
static inline int is_badblock(struct md_rdev *rdev, sector_t s, int sectors, static inline int is_badblock(struct md_rdev *rdev, sector_t s, int sectors,
......
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