[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230803132426.2688608-8-yukuai1@huaweicloud.com>
Date: Thu, 3 Aug 2023 21:24:20 +0800
From: Yu Kuai <yukuai1@...weicloud.com>
To: song@...nel.org, xni@...hat.com
Cc: linux-raid@...r.kernel.org, linux-kernel@...r.kernel.org,
yukuai3@...wei.com, yukuai1@...weicloud.com, yi.zhang@...wei.com,
yangerkun@...wei.com
Subject: [PATCH -next 07/13] md: factor out a helper remove_rdev() from state_store()
From: Yu Kuai <yukuai3@...wei.com>
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@...wei.com>
---
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
Powered by blists - more mailing lists