]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Monitor.c
Replace sysarray with mdinfo
[thirdparty/mdadm.git] / Monitor.c
index ece6abb78f637010d32314260bd10e38629a4e47..6b0c760b94e45f5c64dd08c35ffc1aa1732709fc 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
 #include       "md_p.h"
 #include       "md_u.h"
 #include       <sys/wait.h>
-#include       <sys/signal.h>
-#include       <values.h>
+#include       <signal.h>
+#include       <limits.h>
 #include       <syslog.h>
 
 static void alert(char *event, char *dev, char *disc, char *mailaddr, char *mailfrom,
                  char *cmd, int dosyslog);
 
-static char *percentalerts[] = { 
+static char *percentalerts[] = {
        "RebuildStarted",
        "Rebuild20",
        "Rebuild40",
@@ -172,7 +172,7 @@ int Monitor(mddev_dev_t devlist,
                        st->utime = 0;
                        st->next = statelist;
                        st->err = 0;
-                       st->devnum = MAXINT;
+                       st->devnum = INT_MAX;
                        st->percent = -2;
                        st->expected_spares = mdlist->spare_disks;
                        if (mdlist->spare_group)
@@ -192,7 +192,7 @@ int Monitor(mddev_dev_t devlist,
                        st->utime = 0;
                        st->next = statelist;
                        st->err = 0;
-                       st->devnum = MAXINT;
+                       st->devnum = INT_MAX;
                        st->percent = -2;
                        st->expected_spares = -1;
                        st->spare_group = NULL;
@@ -234,6 +234,7 @@ int Monitor(mddev_dev_t devlist,
 */                             st->err=1;
                                continue;
                        }
+                       fcntl(fd, F_SETFD, FD_CLOEXEC);
                        if (ioctl(fd, GET_ARRAY_INFO, &array)<0) {
                                if (!st->err)
                                        alert("DeviceDisappeared", dev, NULL,
@@ -244,8 +245,10 @@ int Monitor(mddev_dev_t devlist,
                                close(fd);
                                continue;
                        }
-                       if (array.level != 1 && array.level != 5 && array.level != -4 &&
-                               array.level != 6 && array.level != 10) {
+                       /* It's much easier to list what array levels can't
+                        * have a device disappear than all of them that can
+                        */
+                       if (array.level == 0 || array.level == -1) {
                                if (!st->err)
                                        alert("DeviceDisappeared", dev, "Wrong-Level",
                                              mailaddr, mailfrom, alert_cmd, dosyslog);
@@ -253,7 +256,7 @@ int Monitor(mddev_dev_t devlist,
                                close(fd);
                                continue;
                        }
-                       if (st->devnum == MAXINT) {
+                       if (st->devnum == INT_MAX) {
                                struct stat stb;
                                if (fstat(fd, &stb) == 0 &&
                                    (S_IFMT&stb.st_mode)==S_IFBLK) {
@@ -266,7 +269,7 @@ int Monitor(mddev_dev_t devlist,
 
                        for (mse2 = mdstat ; mse2 ; mse2=mse2->next)
                                if (mse2->devnum == st->devnum) {
-                                       mse2->devnum = MAXINT; /* flag it as "used" */
+                                       mse2->devnum = INT_MAX; /* flag it as "used" */
                                        mse = mse2;
                                }
 
@@ -288,11 +291,11 @@ int Monitor(mddev_dev_t devlist,
                                alert("DegradedArray", dev, NULL, mailaddr, mailfrom, alert_cmd, dosyslog);
 
                        if (st->utime == 0 && /* new array */
-                           st->expected_spares > 0 && 
-                           array.spare_disks < st->expected_spares) 
+                           st->expected_spares > 0 &&
+                           array.spare_disks < st->expected_spares)
                                alert("SparesMissing", dev, NULL, mailaddr, mailfrom, alert_cmd, dosyslog);
                        if (mse &&
-                           st->percent == -1 && 
+                           st->percent == -1 &&
                            mse->percent >= 0)
                                alert("RebuildStarted", dev, NULL, mailaddr, mailfrom, alert_cmd, dosyslog);
                        if (mse &&
@@ -309,7 +312,7 @@ int Monitor(mddev_dev_t devlist,
                                 * If there is a number in /mismatch_cnt,
                                 * we should report that.
                                 */
-                               struct sysarray *sra =
+                               struct mdinfo *sra =
                                       sysfs_read(-1, st->devnum, GET_MISMATCH);
                                if (sra && sra->mismatch_cnt > 0) {
                                        char cnt[40];
@@ -328,6 +331,7 @@ int Monitor(mddev_dev_t devlist,
                        for (i=0; i<MaxDisks && i <= array.raid_disks + array.nr_disks;
                             i++) {
                                mdu_disk_info_t disc;
+                               disc.number = i;
                                if (ioctl(fd, GET_DISK_INFO, &disc) >= 0) {
                                        info[i].state = disc.state;
                                        info[i].major = disc.major;
@@ -397,11 +401,10 @@ int Monitor(mddev_dev_t devlist,
                /* now check if there are any new devices found in mdstat */
                if (scan) {
                        struct mdstat_ent *mse;
-                       for (mse=mdstat; mse; mse=mse->next) 
-                               if (mse->devnum != MAXINT &&
-                                   (strcmp(mse->level, "raid1")==0 ||
-                                    strcmp(mse->level, "raid5")==0 ||
-                                    strcmp(mse->level, "multipath")==0)
+                       for (mse=mdstat; mse; mse=mse->next)
+                               if (mse->devnum != INT_MAX &&
+                                   (strcmp(mse->level, "raid0")!=0 &&
+                                    strcmp(mse->level, "linear")!=0)
                                        ) {
                                        struct state *st = malloc(sizeof *st);
                                        mdu_array_info_t array;
@@ -464,7 +467,7 @@ int Monitor(mddev_dev_t devlist,
                                                        }
                                                }
                                                if (dev > 0) {
-                                                       if (ioctl(fd2, HOT_REMOVE_DISK, 
+                                                       if (ioctl(fd2, HOT_REMOVE_DISK,
                                                                  (unsigned long)dev) == 0) {
                                                                if (ioctl(fd1, HOT_ADD_DISK,
                                                                          (unsigned long)dev) == 0) {
@@ -501,7 +504,7 @@ static void alert(char *event, char *dev, char *disc, char *mailaddr, char *mail
 
        if (!cmd && !mailaddr) {
                time_t now = time(0);
-              
+
                printf("%1.15s: %s on %s %s\n", ctime(&now)+4, event, dev, disc?disc:"unknown device");
        }
        if (cmd) {
@@ -517,8 +520,8 @@ static void alert(char *event, char *dev, char *disc, char *mailaddr, char *mail
                        exit(2);
                }
        }
-       if (mailaddr && 
-           (strncmp(event, "Fail", 4)==0 || 
+       if (mailaddr &&
+           (strncmp(event, "Fail", 4)==0 ||
             strncmp(event, "Test", 4)==0 ||
             strncmp(event, "Spares", 6)==0 ||
             strncmp(event, "Degrade", 7)==0)) {