* sync_action was 'resync' and becomes 'idle' and resync_start becomes
* MaxSector
* Notify metadata that sync is complete.
- * "Deal with Degraded"
*
* recovery completes
* sync_action changes from 'recover' to 'idle'
* Check each device state and mark metadata if 'faulty' or 'in_sync'.
- * "Deal with Degraded"
- *
- * deal with degraded array
- * We only do this when first noticing the array is degraded.
- * This can be when we first see the array, when sync completes or
- * when recovery completes.
- *
- * Check if number of failed devices suggests recovery is needed, and
- * skip if not.
- * Ask metadata for a spare device
- * Add device as not in_sync and give a role
- * Update metadata.
- * Start recovery.
*
* deal with resync
* This only happens on finding a new array... mdadm will have set
static int read_and_act(struct active_array *a)
{
- int check_degraded;
+ int check_degraded = 0;
int deactivate = 0;
struct mdinfo *mdi;
a->curr_action = read_action(a->action_fd);
for (mdi = a->info.devs; mdi ; mdi = mdi->next) {
mdi->next_state = 0;
- if (mdi->state_fd > 0)
+ if (mdi->state_fd >= 0)
mdi->curr_state = read_dev_state(mdi->state_fd);
}
}
}
-
for (mdi = a->info.devs ; mdi ; mdi = mdi->next) {
if (mdi->curr_state & DS_FAULTY) {
a->container->ss->set_disk(a, mdi->disk.raid_disk,
}
}
- if (check_degraded) {
- // FIXME;
- }
-
a->container->ss->sync_metadata(a->container);
/* Effect state changes in the array */
if (a->next_action != bad_action)
write_attr(sync_actions[a->next_action], a->action_fd);
for (mdi = a->info.devs; mdi ; mdi = mdi->next) {
- if (mdi->next_state == DS_REMOVE && mdi->state_fd > 0) {
- int remove_err;
+ if (mdi->next_state == DS_REMOVE && mdi->state_fd >= 0) {
+ int remove_result;
write_attr("-blocked", mdi->state_fd);
/* the kernel may not be able to immediately remove the
* disk, we can simply wait until the next event to try
* again.
*/
- remove_err = write_attr("remove", mdi->state_fd);
- if (!remove_err) {
+ remove_result = write_attr("remove", mdi->state_fd);
+ if (remove_result > 0) {
close(mdi->state_fd);
mdi->state_fd = -1;
}
mdi->next_state = 0;
}
+ if (check_degraded) {
+ /* manager will do the actual check */
+ a->check_degraded = 1;
+ signal_manager();
+ }
+
if (deactivate)
a->container = NULL;
*ap = (*ap)->next;
discard_this = a->replaces;
a->replaces = NULL;
+ /* FIXME check if device->state_fd need to be cleared?*/
signal_manager();
}
if (a->container)