[PATCH -next 08/13] md: convert to use hot_remove_rdev() to hot remove one rdev

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Yu Kuai <yukuai3@xxxxxxxxxx>

There are no functional changes, prepare to cleanup
remove_and_add_spares().

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

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 3903bdfe5293..de7399769c8d 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -85,6 +85,7 @@ static struct workqueue_struct *md_wq;
 static struct workqueue_struct *md_misc_wq;
 struct workqueue_struct *md_bitmap_wq;
 
+static bool hot_remove_rdev(struct md_rdev *rdev);
 static int remove_and_add_spares(struct mddev *mddev,
 				 struct md_rdev *this);
 static void mddev_detach(struct mddev *mddev);
@@ -2887,9 +2888,13 @@ static int remove_rdev(struct md_rdev *rdev)
 {
 	struct mddev *mddev = rdev->mddev;
 
+	if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
+		return -EBUSY;
+
 	if (mddev->pers) {
 		clear_bit(Blocked, &rdev->flags);
-		remove_and_add_spares(mddev, rdev);
+		if (!hot_remove_rdev(rdev))
+			return -EBUSY;
 	}
 
 	if (rdev->raid_disk >= 0)
@@ -3133,8 +3138,8 @@ slot_store(struct md_rdev *rdev, const char *buf, size_t len)
 		if (rdev->mddev->pers->hot_remove_disk == NULL)
 			return -EINVAL;
 		clear_bit(Blocked, &rdev->flags);
-		remove_and_add_spares(rdev->mddev, rdev);
-		if (rdev->raid_disk >= 0)
+		if (test_bit(MD_RECOVERY_RUNNING, &rdev->mddev->recovery) ||
+		    !hot_remove_rdev(rdev))
 			return -EBUSY;
 		set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery);
 		md_wakeup_thread(rdev->mddev->thread);
@@ -6931,6 +6936,9 @@ static int hot_remove_disk(struct mddev *mddev, dev_t dev)
 	if (!mddev->pers)
 		return -ENODEV;
 
+	if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
+		return -EBUSY;
+
 	rdev = find_rdev(mddev, dev);
 	if (!rdev)
 		return -ENXIO;
@@ -6939,9 +6947,7 @@ static int hot_remove_disk(struct mddev *mddev, dev_t dev)
 		goto kick_rdev;
 
 	clear_bit(Blocked, &rdev->flags);
-	remove_and_add_spares(mddev, rdev);
-
-	if (rdev->raid_disk >= 0)
+	if (!hot_remove_rdev(rdev))
 		goto busy;
 
 kick_rdev:
-- 
2.39.2




[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux