[PATCH -next 07/13] md: factor out a helper remove_rdev() from state_store()
From: Yu Kuai
Date: Thu Aug 03 2023 - 09:27:55 EST
From: Yu Kuai <yukuai3@xxxxxxxxxx>
state_store() is a very big function already, factor out a helper to
prevent that following changes will make state_store() more complicated.
There are no functional changes.
Signed-off-by: Yu Kuai <yukuai3@xxxxxxxxxx>
---
drivers/md/md.c | 50 +++++++++++++++++++++++++++++--------------------
1 file changed, 30 insertions(+), 20 deletions(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 77c48f7b605c..3903bdfe5293 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -2883,6 +2883,35 @@ state_show(struct md_rdev *rdev, char *page)
return len+sprintf(page+len, "\n");
}
+static int remove_rdev(struct md_rdev *rdev)
+{
+ struct mddev *mddev = rdev->mddev;
+
+ if (mddev->pers) {
+ clear_bit(Blocked, &rdev->flags);
+ remove_and_add_spares(mddev, rdev);
+ }
+
+ if (rdev->raid_disk >= 0)
+ return -EBUSY;
+
+ if (mddev_is_clustered(mddev)) {
+ int err = md_cluster_ops->remove_disk(mddev, rdev);
+
+ if (err)
+ return err;
+ }
+
+ md_kick_rdev_from_array(rdev);
+ if (mddev->pers) {
+ set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
+ md_wakeup_thread(mddev->thread);
+ }
+ md_new_event();
+
+ return 0;
+}
+
static ssize_t
state_store(struct md_rdev *rdev, const char *buf, size_t len)
{
@@ -2913,26 +2942,7 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len)
else
err = 0;
} else if (cmd_match(buf, "remove")) {
- if (rdev->mddev->pers) {
- clear_bit(Blocked, &rdev->flags);
- remove_and_add_spares(rdev->mddev, rdev);
- }
- if (rdev->raid_disk >= 0)
- err = -EBUSY;
- else {
- err = 0;
- if (mddev_is_clustered(mddev))
- err = md_cluster_ops->remove_disk(mddev, rdev);
-
- if (err == 0) {
- md_kick_rdev_from_array(rdev);
- if (mddev->pers) {
- set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
- md_wakeup_thread(mddev->thread);
- }
- md_new_event();
- }
- }
+ err = remove_rdev(rdev);
} else if (cmd_match(buf, "writemostly")) {
set_bit(WriteMostly, &rdev->flags);
mddev_create_serial_pool(rdev->mddev, rdev, false);
--
2.39.2