Commit e9b0a155 authored by Li Nan's avatar Li Nan Committed by Song Liu

md: check mddev->pers before calling md_set_readonly()

If 'mddev->pers' is NULL, there is nothing to do in md_set_readonly().
Except for md_ioctl(), the other two callers of md_set_readonly() have
already checked 'mddev->pers'. To simplify the code, move the check of
'mddev->pers' to the caller.
Signed-off-by: default avatarLi Nan <linan122@huawei.com>
Signed-off-by: default avatarSong Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20240226031444.3606764-10-linan666@huaweicloud.com
parent 650b2e69
...@@ -6420,6 +6420,7 @@ void md_stop(struct mddev *mddev) ...@@ -6420,6 +6420,7 @@ void md_stop(struct mddev *mddev)
EXPORT_SYMBOL_GPL(md_stop); EXPORT_SYMBOL_GPL(md_stop);
/* ensure 'mddev->pers' exist before calling md_set_readonly() */
static int md_set_readonly(struct mddev *mddev) static int md_set_readonly(struct mddev *mddev)
{ {
int err = 0; int err = 0;
...@@ -6444,20 +6445,18 @@ static int md_set_readonly(struct mddev *mddev) ...@@ -6444,20 +6445,18 @@ static int md_set_readonly(struct mddev *mddev)
goto out; goto out;
} }
if (mddev->pers) { __md_stop_writes(mddev);
__md_stop_writes(mddev);
if (mddev->ro == MD_RDONLY) {
err = -ENXIO;
goto out;
}
mddev->ro = MD_RDONLY; if (mddev->ro == MD_RDONLY) {
set_disk_ro(mddev->gendisk, 1); err = -ENXIO;
goto out;
} }
mddev->ro = MD_RDONLY;
set_disk_ro(mddev->gendisk, 1);
out: out:
if ((mddev->pers && !err) || did_freeze) { if (!err || did_freeze) {
clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
sysfs_notify_dirent_safe(mddev->sysfs_state); sysfs_notify_dirent_safe(mddev->sysfs_state);
...@@ -7730,7 +7729,8 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, ...@@ -7730,7 +7729,8 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode,
goto unlock; goto unlock;
case STOP_ARRAY_RO: case STOP_ARRAY_RO:
err = md_set_readonly(mddev); if (mddev->pers)
err = md_set_readonly(mddev);
goto unlock; goto unlock;
case HOT_REMOVE_DISK: case HOT_REMOVE_DISK:
......
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