]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Monitor.c
Monitor: Check destination array domain early.
[thirdparty/mdadm.git] / Monitor.c
index 61550ee00b83cd1dc77c5302321e2b3433d7f8ef..e79f658b6d0795c21c0cc058db5e02e1b49068c1 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
@@ -152,9 +152,11 @@ int Monitor(struct mddev_dev *devlist,
        info.mailfrom = mailfrom;
        info.dosyslog = dosyslog;
 
-       if (daemonise)
-               if (make_daemon(pidfile))
-                       return 1;
+       if (daemonise) {
+               int rv = make_daemon(pidfile);
+               if (rv >= 0)
+                       return rv;
+       }
 
        if (share) 
                if (check_one_sharer(scan))
@@ -247,6 +249,12 @@ int Monitor(struct mddev_dev *devlist,
 
 static int make_daemon(char *pidfile)
 {
+       /* Return:
+        * -1 in the forked daemon
+        *  0 in the parent
+        *  1 on error
+        * so a none-negative becomes the exit code.
+        */
        int pid = fork();
        if (pid > 0) {
                if (!pidfile)
@@ -272,7 +280,7 @@ static int make_daemon(char *pidfile)
        dup2(0,1);
        dup2(0,2);
        setsid();
-       return 0;
+       return -1;
 }
 
 static int check_one_sharer(int scan)
@@ -739,9 +747,9 @@ static int move_spare(struct state *from, struct state *to,
        sprintf(devname, "%d:%d", major(devid), minor(devid));
 
        devlist.disposition = 'r';
-       if (Manage_subdevs(from->devname, fd2, &devlist, -1, 0) == 0) {
+       if (Manage_subdevs(from->devname, fd2, &devlist, -1, 0, NULL) == 0) {
                devlist.disposition = 'a';
-               if (Manage_subdevs(to->devname, fd1, &devlist, -1, 0) == 0) {
+               if (Manage_subdevs(to->devname, fd1, &devlist, -1, 0, NULL) == 0) {
                        alert("MoveSpare", to->devname, from->devname, info);
                        /* make sure we will see newly added spare before next
                         * time through loop
@@ -752,15 +760,14 @@ static int move_spare(struct state *from, struct state *to,
                        close(fd2);
                        return 1;
                }
-               else Manage_subdevs(from->devname, fd2, &devlist, -1, 0);
+               else Manage_subdevs(from->devname, fd2, &devlist, -1, 0, NULL);
        }
        close(fd1);
        close(fd2);
        return 0;
 }
 
-static int check_donor(struct state *from, struct state *to,
-                      struct domainlist *domlist)
+static int check_donor(struct state *from, struct state *to)
 {
        struct state *sub;
 
@@ -782,8 +789,6 @@ static int check_donor(struct state *from, struct state *to,
                        return 0;
        if (from->spare <= 0)
                return 0;
-       if (domlist == NULL)
-               return 0;
        return 1;
 }
 
@@ -915,10 +920,15 @@ static void try_spare_migration(struct state *statelist, struct alert_info *info
                                                           to->metadata->ss->name);
                        if (to->spare_group)
                                domain_add(&domlist, to->spare_group);
-
+                       /*
+                        * No spare migration if the destination
+                        * has no domain. Skip this array.
+                        */
+                       if (!domlist)
+                               continue;
                        for (from=statelist ; from ; from=from->next) {
                                dev_t devid;
-                               if (!check_donor(from, to, domlist))
+                               if (!check_donor(from, to))
                                        continue;
                                if (from->metadata->ss->external)
                                        devid = container_choose_spare(