[PATCH -next 09/13] md: convert to use hot_add_rdev() to hot add one rdev

From: Yu Kuai
Date: Thu Aug 03 2023 - 09:28:32 EST


From: Yu Kuai <yukuai3@xxxxxxxxxx>

Replace remove_and_add_spares() with hot_add_rdev() in
check_sb_changes(), also handle the case that hot add rdev failed.

Signed-off-by: Yu Kuai <yukuai3@xxxxxxxxxx>
---
drivers/md/md.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index de7399769c8d..1dc26bb1e096 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -9773,13 +9773,20 @@ static void check_sb_changes(struct mddev *mddev, struct md_rdev *rdev)
!(le32_to_cpu(sb->feature_map) &
MD_FEATURE_RESHAPE_ACTIVE)) {
rdev2->saved_raid_disk = role;
- ret = remove_and_add_spares(mddev, rdev2);
- pr_info("Activated spare: %pg\n",
- rdev2->bdev);
- /* wakeup mddev->thread here, so array could
- * perform resync with the new activated disk */
- set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
- md_wakeup_thread(mddev->thread);
+ if (!test_bit(MD_RECOVERY_RUNNING,
+ &mddev->recovery) &&
+ hot_add_rdev(rdev2)) {
+ pr_info("Activated spare: %pg\n",
+ rdev2->bdev);
+ /*
+ * wakeup mddev->thread here, so array
+ * could perform resync with the new
+ * activated disk.
+ */
+ set_bit(MD_RECOVERY_NEEDED,
+ &mddev->recovery);
+ md_wakeup_thread(mddev->thread);
+ }
}
/* device faulty
* We just want to do the minimum to mark the disk
--
2.39.2