]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
md/raid5: If there is a spare and a replaceable device, start replacement.
authorNeilBrown <neilb@suse.de>
Fri, 9 Dec 2011 03:27:05 +0000 (14:27 +1100)
committerNeilBrown <neilb@suse.de>
Fri, 9 Dec 2011 03:27:05 +0000 (14:27 +1100)
When attempting to add a spare to a RAID[456] array, also consider
adding it as a replacement for a replaceable device.

This requires that common md code attempt hot_add even when the array
is not formally degraded.

Signed-off-by: NeilBrown <neilb@suse.de>
drivers/md/md.c
drivers/md/raid5.c

index 3e753886bcccf0add7610e98959a642d96dc3eec..ebb9d8d2c1acb7bb6f5d1cf1fbf9617a1a2bcf23 100644 (file)
@@ -7392,25 +7392,23 @@ static int remove_and_add_spares(struct mddev *mddev)
                        }
                }
 
-       if (mddev->degraded) {
-               list_for_each_entry(rdev, &mddev->disks, same_set) {
-                       if (rdev->raid_disk >= 0 &&
-                           !test_bit(In_sync, &rdev->flags) &&
-                           !test_bit(Faulty, &rdev->flags))
+       list_for_each_entry(rdev, &mddev->disks, same_set) {
+               if (rdev->raid_disk >= 0 &&
+                   !test_bit(In_sync, &rdev->flags) &&
+                   !test_bit(Faulty, &rdev->flags))
+                       spares++;
+               if (rdev->raid_disk < 0
+                   && !test_bit(Faulty, &rdev->flags)) {
+                       rdev->recovery_offset = 0;
+                       if (mddev->pers->
+                           hot_add_disk(mddev, rdev) == 0) {
+                               if (sysfs_link_rdev(mddev, rdev))
+                                       /* failure here is OK */;
                                spares++;
-                       if (rdev->raid_disk < 0
-                           && !test_bit(Faulty, &rdev->flags)) {
-                               rdev->recovery_offset = 0;
-                               if (mddev->pers->
-                                   hot_add_disk(mddev, rdev) == 0) {
-                                       if (sysfs_link_rdev(mddev, rdev))
-                                               /* failure here is OK */;
-                                       spares++;
-                                       md_new_event(mddev);
-                                       set_bit(MD_CHANGE_DEVS, &mddev->flags);
-                               } else
-                                       break;
-                       }
+                               md_new_event(mddev);
+                               set_bit(MD_CHANGE_DEVS, &mddev->flags);
+                       } else
+                               break;
                }
        }
        return spares;
index 9546cd8606526ca809dcd049901c3a4201e4d674..cecacc6577e281c457c60a24b9810c264f744b7d 100644 (file)
@@ -5362,8 +5362,9 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)
                disk = rdev->saved_raid_disk;
        else
                disk = first;
-       for ( ; disk <= last ; disk++)
-               if ((p=conf->disks + disk)->rdev == NULL) {
+       for ( ; disk <= last ; disk++) {
+               p = conf->disks + disk;
+               if (p->rdev == NULL) {
                        clear_bit(In_sync, &rdev->flags);
                        rdev->raid_disk = disk;
                        err = 0;
@@ -5372,6 +5373,17 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)
                        rcu_assign_pointer(p->rdev, rdev);
                        break;
                }
+               if (test_bit(Replaceable, &p->rdev->flags) &&
+                   p->replacement == NULL) {
+                       clear_bit(In_sync, &rdev->flags);
+                       set_bit(Replacement, &rdev->flags);
+                       rdev->raid_disk = disk;
+                       err = 0;
+                       conf->fullsync = 1;
+                       rcu_assign_pointer(p->replacement, rdev);
+                       break;
+               }
+       }
        print_raid5_conf(conf);
        return err;
 }