]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Monitor: add option to specify rebuild increments
authorZdenek Behan <rain@matfyz.cz>
Mon, 19 Oct 2009 02:13:58 +0000 (13:13 +1100)
committerNeilBrown <neilb@suse.de>
Mon, 19 Oct 2009 02:13:58 +0000 (13:13 +1100)
ie. the percent increments after which RebuildNN event is generated

This is particulary useful when using --program option, rather than
(only) syslog for alerts.

Signed-off-by: Zdenek Behan <rain@matfyz.cz>
Signed-off-by: NeilBrown <neilb@suse.de>
Monitor.c
ReadMe.c
mdadm.8
mdadm.c
mdadm.h

index af486d709c63d2a96d23803c47c3e7078ab71143..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 &&
index 90b4dafcb8a0331ff405574a936ded5f93ff36fe..3e53e57a4182eec60bfcc712ed4527cd9e33767e 100644 (file)
--- a/ReadMe.c
+++ b/ReadMe.c
@@ -176,6 +176,7 @@ struct option long_options[] = {
     {"mail",      1, 0, 'm'},
     {"program",   1, 0, 'p'},
     {"alert",     1, 0, 'p'},
+    {"increment", 1, 0, 'r'},
     {"delay",     1, 0, 'd'},
     {"daemonise", 0, 0, 'f'},
     {"daemonize", 0, 0, 'f'},
@@ -495,6 +496,7 @@ char Help_monitor[] =
 "  --mail=       -m   : Address to mail alerts of failure to\n"
 "  --program=    -p   : Program to run when an event is detected\n"
 "  --alert=           : same as --program\n"
+"  --increment=  -r   : Report RebuildNN events in the given increment. default=20\n"
 "  --delay=      -d   : seconds of delay between polling state. default=60\n"
 "  --config=     -c   : specify a different config file\n"
 "  --scan        -s   : find mail-address/program in config file\n"
diff --git a/mdadm.8 b/mdadm.8
index 7f19918ffdbe6c95c27f5662f8512dc0ef4d9ab8..36dbf90f01c87f47925ec1976f891e02354b05c1 100644 (file)
--- a/mdadm.8
+++ b/mdadm.8
@@ -1220,6 +1220,12 @@ reduce this as the kernel alerts
 .I mdadm
 immediately when there is any change.
 
+.TP
+.BR \-r ", " \-\-increment
+Give a percentage increment.
+.I mdadm
+will generate RebuildNN events with the given percentage increment.
+
 .TP
 .BR \-f ", " \-\-daemonise
 Tell
@@ -1818,8 +1824,10 @@ An md array started reconstruction. (syslog priority: Warning)
 .BI Rebuild NN
 Where
 .I NN
-is 20, 40, 60, or 80, this indicates that rebuild has passed that many
-percentage of the total. (syslog priority: Warning)
+is a two-digit number (ie. 05, 48). This indicates that rebuild
+has passed that many percent of the total. The events are generated
+with fixed increment since 0. Increment size may be specified with
+a commandline option (default is 20). (syslog priority: Warning)
 
 .TP
 .B RebuildFinished
diff --git a/mdadm.c b/mdadm.c
index 6f43dc316d3d432f96d628af0461c90987d2a53d..df48117d13900b19bbe6c08dba67543420dc746b 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -89,6 +89,7 @@ int main(int argc, char *argv[])
        int require_homehost = 1;
        char *mailaddr = NULL;
        char *program = NULL;
+       int increments = 20;
        int delay = 0;
        int daemonise = 0;
        char *pidfile = NULL;
@@ -698,6 +699,14 @@ int main(int argc, char *argv[])
                                program = optarg;
                        continue;
 
+               case O(MONITOR,'r'): /* rebuild increments */
+                       increments = atoi(optarg);
+                       if (increments>99 || increments<1) {
+                               fprintf(stderr, Name ": please specify positive integer between 1 and 99 as rebuild increments.\n");
+                               exit(2);
+                       }
+                       continue;
+
                case O(MONITOR,'d'): /* delay in seconds */
                case O(GROW, 'd'):
                case O(BUILD,'d'): /* delay for bitmap updates */
@@ -1377,7 +1386,7 @@ int main(int argc, char *argv[])
                }
                rv= Monitor(devlist, mailaddr, program,
                            delay?delay:60, daemonise, scan, oneshot,
-                           dosyslog, test, pidfile);
+                           dosyslog, test, pidfile, increments);
                break;
 
        case GROW:
diff --git a/mdadm.h b/mdadm.h
index ffa5f5390678548b5f76f0c17973417ff66328e7..2e2275c56fb2f5aac5d892337c035e5f197f6549 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -749,7 +749,7 @@ extern int Examine(mddev_dev_t devlist, int brief, int export, int scan,
 extern 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);
 
 extern int Kill(char *dev, int force, int quiet, int noexcl);
 extern int Wait(char *dev);