linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] md/raid5:Choose to replacing or recoverying when  raid degraded and had a want_replacement disk at the same time.
@ 2012-06-05  7:32 majianpeng
  2012-06-06  1:28 ` NeilBrown
  0 siblings, 1 reply; 6+ messages in thread
From: majianpeng @ 2012-06-05  7:32 UTC (permalink / raw)
  To: Neil Brown; +Cc: linux-raid

In Commit 7bfec5f35c68121e7b1849f3f4166dd96c8da5b3:
"if there is a spare and a want_replacement device, start replacement."
But it did not consider the raid was degraded at the same time.
When we add spare disk in order to recovery, unless raid was ok and then
started replacement or vice versa.

Signed-off-by: majianpeng <majianpeng@gmail.com>
---
 drivers/md/raid5.c |   48 +++++++++++++++++++++++++++++-------------------
 1 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index d267672..f74c9a5 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -5447,6 +5447,8 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)
 	struct disk_info *p;
 	int first = 0;
 	int last = conf->raid_disks - 1;
+	int null_disk = -1;
+	int wantreplace_disk = -1;
 
 	if (mddev->recovery_disabled == conf->recovery_disabled)
 		return -EBUSY;
@@ -5468,27 +5470,35 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)
 		disk = rdev->saved_raid_disk;
 	else
 		disk = first;
-	for ( ; disk <= last ; disk++) {
+	for ( ; disk <= last; disk++) {
 		p = conf->disks + disk;
-		if (p->rdev == NULL) {
-			clear_bit(In_sync, &rdev->flags);
-			rdev->raid_disk = disk;
-			err = 0;
-			if (rdev->saved_raid_disk != disk)
-				conf->fullsync = 1;
-			rcu_assign_pointer(p->rdev, rdev);
-			break;
-		}
-		if (test_bit(WantReplacement, &p->rdev->flags) &&
-		    p->replacement == NULL) {
-			clear_bit(In_sync, &rdev->flags);
-			set_bit(Replacement, &rdev->flags);
-			rdev->raid_disk = disk;
-			err = 0;
+		if (p->rdev == NULL && null_disk == -1)
+			null_disk = disk;
+		else if (p->rdev != NULL &&
+			test_bit(WantReplacement, &p->rdev->flags) &&
+			p->replacement == NULL &&
+			wantreplace_disk == -1)
+			wantreplace_disk = disk;
+	}
+
+	if (null_disk != -1 && (rdev->raid_disk < 0 ||
+			wantreplace_disk == -1)) {
+		p = conf->disks + null_disk;
+		clear_bit(In_sync, &rdev->flags);
+		rdev->raid_disk = null_disk;
+		err = 0;
+		if (rdev->saved_raid_disk != null_disk)
 			conf->fullsync = 1;
-			rcu_assign_pointer(p->replacement, rdev);
-			break;
-		}
+		rcu_assign_pointer(p->rdev, rdev);
+	} else if (wantreplace_disk != -1 && (rdev->raid_disk >= 0 ||
+				null_disk == -1)) {
+		p = conf->disks + wantreplace_disk;
+		clear_bit(In_sync, &rdev->flags);
+		set_bit(Replacement, &rdev->flags);
+		rdev->raid_disk = wantreplace_disk;
+		err = 0;
+		conf->fullsync = 1;
+		rcu_assign_pointer(p->replacement, rdev);
 	}
 	print_raid5_conf(conf);
 	return err;
-- 
1.7.5.4



--------------
majianpeng

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-06-27  3:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-05  7:32 [PATCH] md/raid5:Choose to replacing or recoverying when raid degraded and had a want_replacement disk at the same time majianpeng
2012-06-06  1:28 ` NeilBrown
2012-06-06  3:24   ` majianpeng
2012-06-06  3:55     ` NeilBrown
2012-06-06  5:06       ` majianpeng
2012-06-27  3:47         ` NeilBrown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).