]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Monitor.c
Monitor: set err on arrays not in mdstat
[thirdparty/mdadm.git] / Monitor.c
index 0f0adb54502186095c0463cf0818d70fb95b19fc..c4256815f74c3c2b49ef08f4179bf142575bf526 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
@@ -38,7 +38,7 @@ static void alert(char *event, char *dev, char *disc, char *mailaddr, char *mail
  * At least it isn't MD_SB_DISKS.
  */
 #define MaxDisks 384
-int Monitor(mddev_dev_t devlist,
+int Monitor(struct mddev_dev *devlist,
            char *mailaddr, char *alert_cmd,
            int period, int daemonise, int scan, int oneshot,
            int dosyslog, int test, char* pidfile, int increments)
@@ -150,7 +150,7 @@ int Monitor(mddev_dev_t devlist,
        }
 
        if (devlist == NULL) {
-               mddev_ident_t mdlist = conf_get_ident(NULL);
+               struct mddev_ident *mdlist = conf_get_ident(NULL);
                for (; mdlist; mdlist=mdlist->next) {
                        struct state *st;
                        if (mdlist->devname == NULL)
@@ -180,9 +180,9 @@ int Monitor(mddev_dev_t devlist,
                        statelist = st;
                }
        } else {
-               mddev_dev_t dv;
+               struct mddev_dev *dv;
                for (dv=devlist ; dv; dv=dv->next) {
-                       mddev_ident_t mdlist = conf_get_ident(dv->devname);
+                       struct mddev_ident *mdlist = conf_get_ident(dv->devname);
                        struct state *st = malloc(sizeof *st);
                        if (st == NULL)
                                continue;
@@ -271,6 +271,14 @@ int Monitor(mddev_dev_t devlist,
                                        mse = mse2;
                                }
 
+                       if (!mse) {
+                               /* duplicated array in statelist
+                                * or re-created after reading mdstat*/
+                               st->err = 1;
+                               close(fd);
+                               continue;
+                       }
+                       /* this array is in /proc/mdstat */
                        if (array.utime == 0)
                                /* external arrays don't update utime */
                                array.utime = time(0);
@@ -287,7 +295,6 @@ int Monitor(mddev_dev_t devlist,
                                continue;
                        }
                        if (st->utime == 0 && /* new array */
-                           mse &&      /* is in /proc/mdstat */
                            mse->pattern && strchr(mse->pattern, '_') /* degraded */
                                )
                                alert("DegradedArray", dev, NULL, mailaddr, mailfrom, alert_cmd, dosyslog);
@@ -296,12 +303,10 @@ int Monitor(mddev_dev_t devlist,
                            st->expected_spares > 0 &&
                            array.spare_disks < st->expected_spares)
                                alert("SparesMissing", dev, NULL, mailaddr, mailfrom, alert_cmd, dosyslog);
-                       if (mse &&
-                           st->percent == -1 &&
+                       if (st->percent == -1 &&
                            mse->percent >= 0)
                                alert("RebuildStarted", dev, NULL, mailaddr, mailfrom, alert_cmd, dosyslog);
-                       if (mse &&
-                           st->percent >= 0 &&
+                       if (st->percent >= 0 &&
                            mse->percent >= 0 &&
                            (mse->percent / increments) > (st->percent / increments)) {
                                char percentalert[15]; // "RebuildNN" (10 chars) or "RebuildStarted" (15 chars)
@@ -315,8 +320,7 @@ int Monitor(mddev_dev_t devlist,
                                      dev, NULL, mailaddr, mailfrom, alert_cmd, dosyslog);
                        }
 
-                       if (mse &&
-                           mse->percent == -1 &&
+                       if (mse->percent == -1 &&
                            st->percent >= 0) {
                                /* Rebuild/sync/whatever just finished.
                                 * If there is a number in /mismatch_cnt,
@@ -333,10 +337,7 @@ int Monitor(mddev_dev_t devlist,
                                if (sra)
                                        free(sra);
                        }
-
-                       if (mse)
-                               st->percent = mse->percent;
-
+                       st->percent = mse->percent;
 
                        for (i=0; i<MaxDisks && i <= array.raid_disks + array.nr_disks;
                             i++) {
@@ -481,7 +482,7 @@ int Monitor(mddev_dev_t devlist,
                                                        }
                                                }
                                                if (dev > 0) {
-                                                       struct mddev_dev_s devlist;
+                                                       struct mddev_dev devlist;
                                                        char devname[20];
                                                        devlist.next = NULL;
                                                        devlist.used = 0;