Monitor: fix inconsistencies in values for ->percent

->percent sometimes stores negative values recording states
like 'pending' or 'delayed'.
The value '-2' means both 'delayed' and in Monitor, 'unknown'.
Also, '-1' has a meaning but not #define.

So change the #defines to be prefixed with "RESYNC_", instead
of "PROCESS_", add new "_NONE" and "_UNKNOWN", and use correct
value in each location.

Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
NeilBrown 2012-06-04 12:31:40 +10:00
parent b0599bda13
commit 9dad51d418
4 changed files with 19 additions and 17 deletions

View File

@ -374,11 +374,11 @@ int Detail(char *dev, int brief, int export, int test, char *homehost, char *pre
printf(" State : %s%s%s%s%s%s \n",
(array.state&(1<<MD_SB_CLEAN))?"clean":"active", st,
(!e || (e->percent < 0 && e->percent != PROCESS_PENDING &&
e->percent != PROCESS_DELAYED)) ? "" : sync_action[e->resync],
(!e || (e->percent < 0 && e->percent != RESYNC_PENDING &&
e->percent != RESYNC_DELAYED)) ? "" : sync_action[e->resync],
larray_size ? "": ", Not Started",
e->percent == PROCESS_DELAYED ? " (DELAYED)": "",
e->percent == PROCESS_PENDING ? " (PENDING)": "");
e->percent == RESYNC_DELAYED ? " (DELAYED)": "",
e->percent == RESYNC_PENDING ? " (PENDING)": "");
}
if (array.raid_disks)
printf(" Active Devices : %d\n", array.active_disks);

View File

@ -178,7 +178,7 @@ int Monitor(struct mddev_dev *devlist,
}
st->next = statelist;
st->devnum = INT_MAX;
st->percent = -2;
st->percent = RESYNC_UNKNOWN;
st->expected_spares = mdlist->spare_disks;
if (mdlist->spare_group)
st->spare_group = strdup(mdlist->spare_group);
@ -194,7 +194,7 @@ int Monitor(struct mddev_dev *devlist,
st->devname = strdup(dv->devname);
st->next = statelist;
st->devnum = INT_MAX;
st->percent = -2;
st->percent = RESYNC_UNKNOWN;
st->expected_spares = -1;
if (mdlist) {
st->expected_spares = mdlist->spare_disks;
@ -536,7 +536,7 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
st->expected_spares > 0 &&
array.spare_disks < st->expected_spares)
alert("SparesMissing", dev, NULL, ainfo);
if (st->percent == -1 &&
if (st->percent < 0 && st->percent != RESYNC_UNKNOWN &&
mse->percent >= 0)
alert("RebuildStarted", dev, NULL, ainfo);
if (st->percent >= 0 &&
@ -552,7 +552,7 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
alert(percentalert, dev, NULL, ainfo);
}
if (mse->percent == -1 &&
if (mse->percent == RESYNC_NONE &&
st->percent >= 0) {
/* Rebuild/sync/whatever just finished.
* If there is a number in /mismatch_cnt,
@ -702,7 +702,7 @@ static int add_new_arrays(struct mdstat_ent *mdstat, struct state **statelist,
st->next = *statelist;
st->err = 1;
st->devnum = mse->devnum;
st->percent = -2;
st->percent = RESYNC_UNKNOWN;
st->expected_spares = -1;
if (mse->metadata_version &&
strncmp(mse->metadata_version, "external:", 9) == 0 &&

View File

@ -1393,8 +1393,10 @@ static inline int xasprintf(char **strp, const char *fmt, ...) {
#define PATH_MAX 4096
#endif
#define PROCESS_DELAYED -2
#define PROCESS_PENDING -3
#define RESYNC_NONE -1
#define RESYNC_DELAYED -2
#define RESYNC_PENDING -3
#define RESYNC_UNKNOWN -4
/* When using "GET_DISK_INFO" it isn't certain how high
* we need to check. So we impose an absolute limit of

View File

@ -185,7 +185,7 @@ struct mdstat_ent *mdstat_read(int hold, int start)
}
ent->dev = ent->level = ent->pattern= NULL;
ent->next = NULL;
ent->percent = -1;
ent->percent = RESYNC_NONE;
ent->active = -1;
ent->resync = 0;
ent->metadata_version = NULL;
@ -240,7 +240,7 @@ struct mdstat_ent *mdstat_read(int hold, int start)
ent->pattern = strdup(w+1);
if (ent->pattern[l-2]==']')
ent->pattern[l-2] = '\0';
} else if (ent->percent == -1 &&
} else if (ent->percent == RESYNC_NONE &&
strncmp(w, "re", 2)== 0 &&
w[l-1] == '%' &&
(eq=strchr(w, '=')) != NULL ) {
@ -251,7 +251,7 @@ struct mdstat_ent *mdstat_read(int hold, int start)
ent->resync = 2;
else
ent->resync = 0;
} else if (ent->percent == -1 &&
} else if (ent->percent == RESYNC_NONE &&
(w[0] == 'r' || w[0] == 'c')) {
if (strncmp(w, "resync", 4)==0)
ent->resync = 1;
@ -263,10 +263,10 @@ struct mdstat_ent *mdstat_read(int hold, int start)
ent->resync = 3;
if (l > 8 && strcmp(w+l-8, "=DELAYED") == 0)
ent->percent = PROCESS_DELAYED;
ent->percent = RESYNC_DELAYED;
if (l > 8 && strcmp(w+l-8, "=PENDING") == 0)
ent->percent = PROCESS_PENDING;
} else if (ent->percent == -1 &&
ent->percent = RESYNC_PENDING;
} else if (ent->percent == RESYNC_NONE &&
w[0] >= '0' &&
w[0] <= '9' &&
w[l-1] == '%') {