[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230803132426.2688608-7-yukuai1@huaweicloud.com>
Date: Thu, 3 Aug 2023 21:24:19 +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 06/13] md: factor out a helper hot_add_rdev() from remove_and_add_spares()
From: Yu Kuai <yukuai3@...wei.com>
There are no functional changes, just to make the code simpler and
prepare to refactoer remove_and_add_spares().
Signed-off-by: Yu Kuai <yukuai3@...wei.com>
---
drivers/md/md.c | 34 ++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 74ee31f2706b..77c48f7b605c 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -9196,6 +9196,26 @@ static bool hot_remove_rdev(struct md_rdev *rdev)
return true;
}
+static bool hot_add_rdev(struct md_rdev *rdev)
+{
+ struct mddev *mddev;
+
+ if (!rdev_addable(rdev))
+ return false;
+
+ if (!test_bit(Journal, &rdev->flags))
+ rdev->recovery_offset = 0;
+
+ mddev = rdev->mddev;
+ if (mddev->pers->hot_add_disk(mddev, rdev))
+ return false;
+
+ sysfs_link_rdev(mddev, rdev);
+ md_new_event();
+ set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
+ return true;
+}
+
static int remove_and_add_spares(struct mddev *mddev,
struct md_rdev *this)
{
@@ -9222,18 +9242,8 @@ static int remove_and_add_spares(struct mddev *mddev,
continue;
if (rdev_is_spare(rdev))
spares++;
- if (!rdev_addable(rdev))
- continue;
- if (!test_bit(Journal, &rdev->flags))
- rdev->recovery_offset = 0;
- if (mddev->pers->hot_add_disk(mddev, rdev) == 0) {
- /* failure here is OK */
- sysfs_link_rdev(mddev, rdev);
- if (!test_bit(Journal, &rdev->flags))
- spares++;
- md_new_event();
- set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
- }
+ if (hot_add_rdev(rdev) && !test_bit(Journal, &rdev->flags))
+ spares++;
}
no_add:
if (removed)
--
2.39.2
Powered by blists - more mailing lists