]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Monitor.c
Having single function to read mdmon pid file.
[thirdparty/mdadm.git] / Monitor.c
index a0651e4393275e0c49af6088f54b60e38d5292f3..b0802f868043474a14e807f8005de3ca04d387aa 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 &&
@@ -480,16 +480,25 @@ int Monitor(mddev_dev_t devlist,
                                                        }
                                                }
                                                if (dev > 0) {
-                                                       if (ioctl(fd2, HOT_REMOVE_DISK,
-                                                                 (unsigned long)dev) == 0) {
-                                                               if (ioctl(fd1, HOT_ADD_DISK,
-                                                                         (unsigned long)dev) == 0) {
+                                                       struct mddev_dev_s devlist;
+                                                       char devname[20];
+                                                       devlist.next = NULL;
+                                                       devlist.used = 0;
+                                                       devlist.re_add = 0;
+                                                       devlist.writemostly = 0;
+                                                       devlist.devname = devname;
+                                                       sprintf(devname, "%d:%d", major(dev), minor(dev));
+
+                                                       devlist.disposition = 'r';
+                                                       if (Manage_subdevs(st2->devname, fd2, &devlist, -1) == 0) {
+                                                               devlist.disposition = 'a';
+                                                               if (Manage_subdevs(st->devname, fd1, &devlist, -1) == 0) {
                                                                        alert("MoveSpare", st->devname, st2->devname, mailaddr, mailfrom, alert_cmd, dosyslog);
                                                                        close(fd1);
                                                                        close(fd2);
                                                                        break;
                                                                }
-                                                               else ioctl(fd2, HOT_ADD_DISK, (unsigned long) dev);
+                                                               else Manage_subdevs(st2->devname, fd2, &devlist, -1);
                                                        }
                                                }
                                                close(fd1);
@@ -572,7 +581,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);
                }
 
        }