Commit d7a47838 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

md: check for NULL ->meta_bdev before calling bdev_read_only

->meta_bdev is optional and not set for most arrays.  Add a
rdev_read_only helper that calls bdev_read_only for both devices
in a safe way.

Fixes: 6f0d9689 ("block: remove the NULL bdev check in bdev_read_only")
Reported-by: default avatarGuoqing Jiang <guoqing.jiang@cloud.ionos.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent f7bf5e24
...@@ -2399,6 +2399,12 @@ int md_integrity_add_rdev(struct md_rdev *rdev, struct mddev *mddev) ...@@ -2399,6 +2399,12 @@ int md_integrity_add_rdev(struct md_rdev *rdev, struct mddev *mddev)
} }
EXPORT_SYMBOL(md_integrity_add_rdev); EXPORT_SYMBOL(md_integrity_add_rdev);
static bool rdev_read_only(struct md_rdev *rdev)
{
return bdev_read_only(rdev->bdev) ||
(rdev->meta_bdev && bdev_read_only(rdev->meta_bdev));
}
static int bind_rdev_to_array(struct md_rdev *rdev, struct mddev *mddev) static int bind_rdev_to_array(struct md_rdev *rdev, struct mddev *mddev)
{ {
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
...@@ -2408,8 +2414,7 @@ static int bind_rdev_to_array(struct md_rdev *rdev, struct mddev *mddev) ...@@ -2408,8 +2414,7 @@ static int bind_rdev_to_array(struct md_rdev *rdev, struct mddev *mddev)
if (find_rdev(mddev, rdev->bdev->bd_dev)) if (find_rdev(mddev, rdev->bdev->bd_dev))
return -EEXIST; return -EEXIST;
if ((bdev_read_only(rdev->bdev) || bdev_read_only(rdev->meta_bdev)) && if (rdev_read_only(rdev) && mddev->pers)
mddev->pers)
return -EROFS; return -EROFS;
/* make sure rdev->sectors exceeds mddev->dev_sectors */ /* make sure rdev->sectors exceeds mddev->dev_sectors */
...@@ -5843,9 +5848,7 @@ int md_run(struct mddev *mddev) ...@@ -5843,9 +5848,7 @@ int md_run(struct mddev *mddev)
continue; continue;
sync_blockdev(rdev->bdev); sync_blockdev(rdev->bdev);
invalidate_bdev(rdev->bdev); invalidate_bdev(rdev->bdev);
if (mddev->ro != 1 && if (mddev->ro != 1 && rdev_read_only(rdev)) {
(bdev_read_only(rdev->bdev) ||
bdev_read_only(rdev->meta_bdev))) {
mddev->ro = 1; mddev->ro = 1;
if (mddev->gendisk) if (mddev->gendisk)
set_disk_ro(mddev->gendisk, 1); set_disk_ro(mddev->gendisk, 1);
......
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