From: Jan Kara jack@suse.cz
mainline inclusion from mainline-v6.7-rc1 commit 9f0f5a30d34cb92257e94a042b8e86d9a680e416 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8KPBR CVE: NA
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h...
-------------------------------------------
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: Song Liu song@kernel.org Acked-by: Christoph Hellwig hch@lst.de Acked-by: Christian Brauner brauner@kernel.org Signed-off-by: Jan Kara jack@suse.cz Link: https://lore.kernel.org/r/20230927093442.25915-11-jack@suse.cz Signed-off-by: Christian Brauner brauner@kernel.org Signed-off-by: Li Lingfeng lilingfeng3@huawei.com --- drivers/md/md.c | 23 ++++++++--------------- drivers/md/md.h | 4 +--- 2 files changed, 9 insertions(+), 18 deletions(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c index a104a025084d..839e79e567ee 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -2452,8 +2452,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, - test_bit(Holder, &rdev->flags) ? rdev : &claim_rdev); + bdev_release(rdev->bdev_handle); rdev->bdev = NULL; kobject_put(&rdev->kobj); } @@ -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) { struct md_rdev *rdev; - struct md_rdev *holder; sector_t size; int err;
@@ -3648,21 +3646,16 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe if (err) goto out_clear_rdev;
- if (super_format == -2) { - holder = &claim_rdev; - } else { - holder = rdev; - 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)) { + 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_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);
@@ -3693,7 +3686,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, holder); + 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 7c9c13abd7ca..274e7d61d19f 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; @@ -211,9 +212,6 @@ enum flag_bits { * check if there is collision between raid1 * 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,