]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Monitor.c
Detail: clean up handing of the 'info' we load from superblock.
[thirdparty/mdadm.git] / Monitor.c
index f6fd95cdfa9401c9bef67bdefd3403f8a3a5e852..7af36abd72fdfc6a3aeb4073a16bce89e4b17332 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
 static void alert(char *event, char *dev, char *disc, char *mailaddr, char *mailfrom,
                  char *cmd, int dosyslog);
 
-static char *percentalerts[] = {
-       "RebuildStarted",
-       "Rebuild20",
-       "Rebuild40",
-       "Rebuild60",
-       "Rebuild80",
-};
-
 /* The largest number of disks current arrays can manage is 384
  * This really should be dynamically, but that will have to wait
  * At least it isn't MD_SB_DISKS.
@@ -49,7 +41,7 @@ static char *percentalerts[] = {
 int Monitor(mddev_dev_t devlist,
            char *mailaddr, char *alert_cmd,
            int period, int daemonise, int scan, int oneshot,
-           int dosyslog, int test, char* pidfile)
+           int dosyslog, int test, char* pidfile, int increments)
 {
        /*
         * Every few seconds, scan every md device looking for changes
@@ -77,8 +69,8 @@ int Monitor(mddev_dev_t devlist,
         *      An active device had a reverse transition
         *    RebuildStarted
         *      percent went from -1 to +ve
-        *    Rebuild20 Rebuild40 Rebuild60 Rebuild80
-        *      percent went from below to not-below that number
+        *    RebuildNN
+        *      percent went from below to not-below NN%
         *    DeviceDisappeared
         *      Couldn't access a device which was previously visible
         *
@@ -311,9 +303,17 @@ int Monitor(mddev_dev_t devlist,
                        if (mse &&
                            st->percent >= 0 &&
                            mse->percent >= 0 &&
-                           (mse->percent / 20) > (st->percent / 20))
-                               alert(percentalerts[mse->percent/20],
+                           (mse->percent / increments) > (st->percent / increments)) {
+                               char percentalert[15]; // "RebuildNN" (10 chars) or "RebuildStarted" (15 chars)
+
+                               if((mse->percent / increments) == 0)
+                                       snprintf(percentalert, sizeof(percentalert), "RebuildStarted");
+                               else
+                                       snprintf(percentalert, sizeof(percentalert), "Rebuild%02d", mse->percent);
+
+                               alert(percentalert,
                                      dev, NULL, mailaddr, mailfrom, alert_cmd, dosyslog);
+                       }
 
                        if (mse &&
                            mse->percent == -1 &&
@@ -391,6 +391,7 @@ int Monitor(mddev_dev_t devlist,
                                                )
                                                alert("FailSpare", dev, dv, mailaddr, mailfrom, alert_cmd, dosyslog);
                                        else if (i < (unsigned)array.raid_disks &&
+                                                ! (newstate & (1<<MD_DISK_REMOVED)) &&
                                                 (((st->devstate[i]&change)&(1<<MD_DISK_FAULTY)) ||
                                                  ((newstate&change)&(1<<MD_DISK_ACTIVE)) ||
                                                  ((newstate&change)&(1<<MD_DISK_SYNC)))
@@ -490,15 +491,15 @@ int Monitor(mddev_dev_t devlist,
                                                        sprintf(devname, "%d:%d", major(dev), minor(dev));
 
                                                        devlist.disposition = 'r';
-                                                       if (Manage_subdevs(st2->devname, fd2, &devlist, -1) == 0) {
+                                                       if (Manage_subdevs(st2->devname, fd2, &devlist, -1, 0) == 0) {
                                                                devlist.disposition = 'a';
-                                                               if (Manage_subdevs(st->devname, fd1, &devlist, -1) == 0) {
+                                                               if (Manage_subdevs(st->devname, fd1, &devlist, -1, 0) == 0) {
                                                                        alert("MoveSpare", st->devname, st2->devname, mailaddr, mailfrom, alert_cmd, dosyslog);
                                                                        close(fd1);
                                                                        close(fd2);
                                                                        break;
                                                                }
-                                                               else Manage_subdevs(st2->devname, fd2, &devlist, -1);
+                                                               else Manage_subdevs(st2->devname, fd2, &devlist, -1, 0);
                                                        }
                                                }
                                                close(fd1);
@@ -581,7 +582,7 @@ static void alert(char *event, char *dev, char *disc, char *mailaddr, char *mail
                                        n=fwrite(buf, 1, n, mp); /* yes, i don't care about the result */
                                fclose(mdstat);
                        }
-                       fclose(mp);
+                       pclose(mp);
                }
 
        }