]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm: added --no-sharing option for Monitor mode
authorAnna Czarnowska <anna.czarnowska@intel.com>
Mon, 22 Nov 2010 09:58:06 +0000 (20:58 +1100)
committerNeilBrown <neilb@suse.de>
Mon, 22 Nov 2010 09:58:06 +0000 (20:58 +1100)
--no-sharing option disables moving spares between arrays/containers.
Without the option spares are moved if needed according to config rules.
We only allow one process moving spares started with --scan option.
If there is such process running and another instance of Monitor
is starting without --scan, then we issue a warning but allow it
to continue.

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Monitor.c
ReadMe.c
mdadm.c
mdadm.h

index c4256815f74c3c2b49ef08f4179bf142575bf526..2f43b125d02918d3d4b97fbad77e088a40895052 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
@@ -41,7 +41,8 @@ static void alert(char *event, char *dev, char *disc, char *mailaddr, char *mail
 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)
+           int dosyslog, int test, char *pidfile, int increments,
+           int share)
 {
        /*
         * Every few seconds, scan every md device looking for changes
@@ -149,6 +150,45 @@ int Monitor(struct mddev_dev *devlist,
                setsid();
        }
 
+       if (share) {
+               int pid, rv;
+               FILE *fp;
+               char dir[20];
+               struct stat buf;
+               fp = fopen("/var/run/mdadm/autorebuild.pid", "r");
+               if (fp) {
+                       fscanf(fp, "%d", &pid);
+                       sprintf(dir, "/proc/%d", pid);
+                       rv = stat(dir, &buf);
+                       if (rv != -1) {
+                               if (scan) {
+                                       fprintf(stderr, Name ": Only one "
+                                               "autorebuild process allowed"
+                                               " in scan mode, aborting\n");
+                                       fclose(fp);
+                                       return 1;
+                               } else {
+                                       fprintf(stderr, Name ": Warning: One"
+                                               " autorebuild process already"
+                                               " running.");
+                               }
+                       }
+                       fclose(fp);
+               }
+               if (scan) {
+                       fp = fopen("/var/run/mdadm/autorebuild.pid", "w");
+                       if (!fp)
+                               fprintf(stderr, Name ": Cannot create"
+                                       " autorebuild.pid "
+                                       "file\n");
+                       else {
+                               pid = getpid();
+                               fprintf(fp, "%d\n", pid);
+                               fclose(fp);
+                       }
+               }
+       }
+
        if (devlist == NULL) {
                struct mddev_ident *mdlist = conf_get_ident(NULL);
                for (; mdlist; mdlist=mdlist->next) {
@@ -453,7 +493,7 @@ int Monitor(struct mddev_dev *devlist,
                 * Look for another array with spare > 0 and active == raid and same spare_group
                 *  if found, choose a device and hotremove/hotadd
                 */
-               for (st = statelist; st; st=st->next)
+               if (share) for (st = statelist; st; st=st->next)
                        if (st->active < st->raid &&
                            st->spare == 0 &&
                            st->spare_group != NULL) {
index 07abdb7d11ecd2693165116456c8b4c423a9e5db..54a1998620fc48f1b8ac2de4fcf2a4b4774cb683 100644 (file)
--- a/ReadMe.c
+++ b/ReadMe.c
@@ -185,6 +185,8 @@ struct option long_options[] = {
     {"oneshot",   0, 0, '1'},
     {"pid-file",  1, 0, 'i'},
     {"syslog",    0, 0, 'y'},
+    {"no-sharing", 0, 0, NoSharing},
+
     /* For Grow */
     {"backup-file", 1,0, BackupFile},
     {"array-size", 1, 0, 'Z'},
diff --git a/mdadm.c b/mdadm.c
index 0eef6bc80738a6d0e3cd7447cf41b9de00171c2c..07460c6adc061e1b907ce1b77201eee1e3d1858c 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -96,6 +96,7 @@ int main(int argc, char *argv[])
        int daemonise = 0;
        char *pidfile = NULL;
        int oneshot = 0;
+       int spare_sharing = 1;
        struct supertype *ss = NULL;
        int writemostly = 0;
        int re_add = 0;
@@ -228,6 +229,7 @@ int main(int argc, char *argv[])
                                subarray = optarg;
                        }
                case 'K': if (!mode) newmode = MISC; break;
+               case NoSharing: newmode = MONITOR; break;
                }
                if (mode && newmode == mode) {
                        /* everybody happy ! */
@@ -777,7 +779,9 @@ int main(int argc, char *argv[])
                        openlog("mdadm", LOG_PID, SYSLOG_FACILITY);
                        dosyslog = 1;
                        continue;
-
+               case O(MONITOR, NoSharing):
+                       spare_sharing = 0;
+                       continue;
                        /* now the general management options.  Some are applicable
                         * to other modes. None have arguments.
                         */
@@ -1494,7 +1498,7 @@ int main(int argc, char *argv[])
                }
                rv= Monitor(devlist, mailaddr, program,
                            delay?delay:60, daemonise, scan, oneshot,
-                           dosyslog, test, pidfile, increments);
+                           dosyslog, test, pidfile, increments, spare_sharing);
                break;
 
        case GROW:
diff --git a/mdadm.h b/mdadm.h
index 6b54249f4fbb79c3fa42da6aad74f7ee3bb1c283..daaf628d90e6989882303e33dd15a0843cf2c6b1 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -288,7 +288,8 @@ enum special_options {
        DetailPlatform,
        KillSubarray,
        UpdateSubarray, /* 16 */
-       IncrementalPath
+       IncrementalPath,
+       NoSharing
 };
 
 /* structures read from config file */
@@ -930,7 +931,8 @@ extern int Examine(struct mddev_dev *devlist, int brief, int export, int scan,
 extern 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);
+                  int dosyslog, int test, char *pidfile, int increments,
+                  int share);
 
 extern int Kill(char *dev, struct supertype *st, int force, int quiet, int noexcl);
 extern int Kill_subarray(char *dev, char *subarray, int quiet);