[PATCH -next 02/13] md: factor out a helper rdev_removeable() from remove_and_add_spares()
From: Yu Kuai
Date: Thu Aug 03 2023 - 09:27:38 EST
From: Yu Kuai <yukuai3@xxxxxxxxxx>
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@xxxxxxxxxx>
---
drivers/md/md.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index cd7ac1dee3b8..0d84754027ec 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -9149,6 +9149,14 @@ void md_do_sync(struct md_thread *thread)
}
EXPORT_SYMBOL_GPL(md_do_sync);
+static bool rdev_removeable(struct md_rdev *rdev)
+{
+ return rdev->raid_disk >= 0 && !test_bit(Blocked, &rdev->flags) &&
+ !test_bit(In_sync, &rdev->flags) &&
+ !test_bit(Journal, &rdev->flags) &&
+ !atomic_read(&rdev->nr_pending);
+}
+
static int remove_and_add_spares(struct mddev *mddev,
struct md_rdev *this)
{
@@ -9161,19 +9169,12 @@ static int remove_and_add_spares(struct mddev *mddev,
return 0;
rdev_for_each(rdev, mddev) {
- if ((this == NULL || rdev == this) &&
- rdev->raid_disk >= 0 &&
- !test_bit(Blocked, &rdev->flags) &&
- !test_bit(In_sync, &rdev->flags) &&
- !test_bit(Journal, &rdev->flags) &&
- atomic_read(&rdev->nr_pending)==0) {
- if (mddev->pers->hot_remove_disk(
- mddev, rdev) == 0) {
- sysfs_unlink_rdev(mddev, rdev);
- rdev->saved_raid_disk = rdev->raid_disk;
- rdev->raid_disk = -1;
- removed++;
- }
+ if ((this == NULL || rdev == this) && rdev_removeable(rdev) &&
+ !mddev->pers->hot_remove_disk(mddev, rdev)) {
+ sysfs_unlink_rdev(mddev, rdev);
+ rdev->saved_raid_disk = rdev->raid_disk;
+ rdev->raid_disk = -1;
+ removed++;
}
}
--
2.39.2