]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Monitor: fix inconsistencies in values for ->percent
authorNeilBrown <neilb@suse.de>
Mon, 4 Jun 2012 02:31:40 +0000 (12:31 +1000)
committerNeilBrown <neilb@suse.de>
Mon, 4 Jun 2012 02:31:40 +0000 (12:31 +1000)
->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>
Detail.c
Monitor.c
mdadm.h
mdstat.c

index abe8e2f1f89adc16029c04d7da3c04fb9f4695c4..7d5fc27a717ac681e00c648776accb1f52ca4fd1 100644 (file)
--- a/Detail.c
+++ b/Detail.c
@@ -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);
index 12b85f33c926ab50524007194ca3c4a1d3907f32..d9295b5275371a5916631280f5f9133a66295730 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
@@ -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 &&
diff --git a/mdadm.h b/mdadm.h
index 4946d4eac3d74233bfa479b2542fee0bb56bd5aa..4cf34ab1cfa3b28f592de004132c47e521477530 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -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
index 6ead24c4a7a1d52682655e243f0a0bf803cd7bf0..17405601bd650ba251cd5de65c27352961a5aebd 100644 (file)
--- a/mdstat.c
+++ b/mdstat.c
@@ -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] == '%') {