diff mbox series

[11/29] md: Convert to bdev_open_by_dev()

Message ID 20230811110504.27514-11-jack@suse.cz (mailing list archive)
State New, archived
Headers show
Series block: Make blkdev_get_by_*() return handle | expand

Commit Message

Jan Kara Aug. 11, 2023, 11:04 a.m. UTC
Convert md to use bdev_open_by_dev() and pass the handle around.

CC: linux-raid@vger.kernel.org
CC: Song Liu <song@kernel.org>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 drivers/md/md.c | 12 +++++++-----
 drivers/md/md.h |  1 +
 2 files changed, 8 insertions(+), 5 deletions(-)

Comments

Song Liu Aug. 13, 2023, 3:54 p.m. UTC | #1
On Fri, Aug 11, 2023 at 3:05 PM Jan Kara <jack@suse.cz> wrote:
[...]
> diff --git a/drivers/md/md.h b/drivers/md/md.h
> index 1aef86bf3fc3..e8108845157b 100644
> --- a/drivers/md/md.h
> +++ b/drivers/md/md.h
> @@ -59,6 +59,7 @@ struct md_rdev {
>          */
>         struct block_device *meta_bdev;
>         struct block_device *bdev;      /* block device handle */
> +       struct bdev_handle *bdev_handle;        /* Handle from open for bdev */

With bdev_handle, we should eventually get rid of md_rdev->bdev.
But that can be done in a separate patch.

Acked-by: Song Liu <song@kernel.org>

>
>         struct page     *sb_page, *bb_page;
>         int             sb_loaded;
> --
> 2.35.3
>
Jan Kara Aug. 14, 2023, 1:37 p.m. UTC | #2
On Sun 13-08-23 19:54:56, Song Liu wrote:
> On Fri, Aug 11, 2023 at 3:05 PM Jan Kara <jack@suse.cz> wrote:
> [...]
> > diff --git a/drivers/md/md.h b/drivers/md/md.h
> > index 1aef86bf3fc3..e8108845157b 100644
> > --- a/drivers/md/md.h
> > +++ b/drivers/md/md.h
> > @@ -59,6 +59,7 @@ struct md_rdev {
> >          */
> >         struct block_device *meta_bdev;
> >         struct block_device *bdev;      /* block device handle */
> > +       struct bdev_handle *bdev_handle;        /* Handle from open for bdev */
> 
> With bdev_handle, we should eventually get rid of md_rdev->bdev.
> But that can be done in a separate patch.

Yeah, we can do that. But in the case of md it would cause a relatively
large amount of churn so at least for this series I've stayed with the
minimal solution.

> Acked-by: Song Liu <song@kernel.org>

Thanks!

								Honza
diff mbox series

Patch

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 78be7811a89f..20d6cefda3e8 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -2450,7 +2450,7 @@  static void export_rdev(struct md_rdev *rdev, struct mddev *mddev)
 	if (test_bit(AutoDetected, &rdev->flags))
 		md_autodetect_dev(rdev->bdev->bd_dev);
 #endif
-	blkdev_put(rdev->bdev, mddev->external ? &claim_rdev : rdev);
+	bdev_release(rdev->bdev_handle);
 	rdev->bdev = NULL;
 	kobject_put(&rdev->kobj);
 }
@@ -3644,14 +3644,16 @@  static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
 	if (err)
 		goto out_clear_rdev;
 
-	rdev->bdev = blkdev_get_by_dev(newdev, BLK_OPEN_READ | BLK_OPEN_WRITE,
+	rdev->bdev_handle = bdev_open_by_dev(newdev,
+			BLK_OPEN_READ | BLK_OPEN_WRITE,
 			super_format == -2 ? &claim_rdev : rdev, NULL);
-	if (IS_ERR(rdev->bdev)) {
+	if (IS_ERR(rdev->bdev_handle)) {
 		pr_warn("md: could not open device unknown-block(%u,%u).\n",
 			MAJOR(newdev), MINOR(newdev));
-		err = PTR_ERR(rdev->bdev);
+		err = PTR_ERR(rdev->bdev_handle);
 		goto out_clear_rdev;
 	}
+	rdev->bdev = rdev->bdev_handle->bdev;
 
 	kobject_init(&rdev->kobj, &rdev_ktype);
 
@@ -3682,7 +3684,7 @@  static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
 	return rdev;
 
 out_blkdev_put:
-	blkdev_put(rdev->bdev, super_format == -2 ? &claim_rdev : rdev);
+	bdev_release(rdev->bdev_handle);
 out_clear_rdev:
 	md_rdev_clear(rdev);
 out_free_rdev:
diff --git a/drivers/md/md.h b/drivers/md/md.h
index 1aef86bf3fc3..e8108845157b 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -59,6 +59,7 @@  struct md_rdev {
 	 */
 	struct block_device *meta_bdev;
 	struct block_device *bdev;	/* block device handle */
+	struct bdev_handle *bdev_handle;	/* Handle from open for bdev */
 
 	struct page	*sb_page, *bb_page;
 	int		sb_loaded;