[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240206085511.2841555-10-linan666@huaweicloud.com>
Date: Tue, 6 Feb 2024 16:55:11 +0800
From: linan666@...weicloud.com
To: song@...nel.org,
mariusz.tkaczyk@...ux.intel.com,
shli@...com,
neilb@...e.com
Cc: linux-raid@...r.kernel.org,
linux-kernel@...r.kernel.org,
linan666@...weicloud.com,
yukuai3@...wei.com,
yi.zhang@...wei.com,
houtao1@...wei.com,
yangerkun@...wei.com
Subject: [PATCH v6 9/9] md: check mddev->pers before calling md_set_readonly()
From: Li Nan <linan122@...wei.com>
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: Li Nan <linan122@...wei.com>
---
drivers/md/md.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index adb821626d66..987851db98c1 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -6412,6 +6412,7 @@ void md_stop(struct mddev *mddev)
EXPORT_SYMBOL_GPL(md_stop);
+/* ensure 'mddev->pers' exist before calling md_set_readonly() */
static int md_set_readonly(struct mddev *mddev)
{
int err = 0;
@@ -6451,20 +6452,18 @@ static int md_set_readonly(struct mddev *mddev)
err = -EBUSY;
goto out;
}
- if (mddev->pers) {
- __md_stop_writes(mddev);
+ __md_stop_writes(mddev);
- err = -ENXIO;
- if (mddev->ro == MD_RDONLY)
- goto out;
- mddev->ro = MD_RDONLY;
- set_disk_ro(mddev->gendisk, 1);
- clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
- set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
- md_wakeup_thread(mddev->thread);
- sysfs_notify_dirent_safe(mddev->sysfs_state);
- err = 0;
- }
+ err = -ENXIO;
+ if (mddev->ro == MD_RDONLY)
+ goto out;
+ mddev->ro = MD_RDONLY;
+ set_disk_ro(mddev->gendisk, 1);
+ clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
+ set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
+ md_wakeup_thread(mddev->thread);
+ sysfs_notify_dirent_safe(mddev->sysfs_state);
+ err = 0;
out:
return err;
}
@@ -7752,7 +7751,8 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode,
goto unlock;
case STOP_ARRAY_RO:
- err = md_set_readonly(mddev);
+ if (mddev->pers)
+ err = md_set_readonly(mddev);
goto unlock;
case HOT_REMOVE_DISK:
--
2.39.2
Powered by blists - more mailing lists