+ if (a->check_degraded) {
+ struct metadata_update *updates = NULL;
+ struct mdinfo *newdev;
+ struct active_array *newa;
+ wait_update_handled();
+ a->check_degraded = 0;
+
+ /* The array may not be degraded, this is just a good time
+ * to check.
+ */
+ newdev = a->container->ss->activate_spare(a, &updates);
+ if (newdev) {
+ struct mdinfo *d;
+ /* Cool, we can add a device or several. */
+ newa = duplicate_aa(a);
+ /* suspend recovery - maybe not needed */
+
+ /* Add device to array and set offset/size/slot.
+ * and open files for each newdev */
+ for (d = newdev; d ; d = d->next) {
+ struct mdinfo *newd;
+ if (sysfs_add_disk(&newa->info, d) < 0)
+ continue;
+ newd = newa->info.devs;
+ newd->state_fd = sysfs_open(a->devnum,
+ newd->sys_name,
+ "state");
+ newd->prev_state
+ = read_dev_state(newd->state_fd);
+ newd->curr_state = newd->prev_state;
+ }
+ queue_metadata_update(updates);
+ replace_array(a->container, a, newa);
+ sysfs_set_str(&a->info, NULL, "sync_action", "repair");
+ }
+ }