Factor common code into new "start_mdmon".
authorNeilBrown <neilb@suse.de>
Fri, 18 Jul 2008 06:37:11 +0000 (16:37 +1000)
committerNeilBrown <neilb@suse.de>
Fri, 18 Jul 2008 06:37:11 +0000 (16:37 +1000)
Signed-off-by: Neil Brown <neilb@suse.de>
Create.c
Incremental.c
mdadm.h
util.c

index b2edc7d..692a74c 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -769,28 +769,10 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                if (verbose >= 0)
                        fprintf(stderr, Name ": array %s started.\n", mddev);
                if (st->ss->external && st->subarray[0]) {
-                       if (need_mdmon && !env_no_mdmon()) {
-                               int dn = st->container_dev;
-                               int i;
-                               switch(fork()) {
-                               case 0:
-                                       /* FIXME yuk. CLOSE_EXEC?? */
-                                       for (i=3; i < 100; i++)
-                                               close(i);
-                                       execl("./mdmon", "mdmon",
-                                             map_dev(dev2major(dn),
-                                                     dev2minor(dn),
-                                                     1), NULL);
-                                       exit(1);
-                               case -1: fprintf(stderr, Name ": cannot fork. "
-                                                "Array remains readonly\n");
-                                       return 1;
-                               default: ; /* parent - good */
-                               }
-                       } else
-                               signal_mdmon(st->container_dev);
-                       /* FIXME wait for mdmon to set array to read-auto */
-                       sleep(1);
+                       if (need_mdmon)
+                               start_mdmon(st->container_dev);
+
+                       ping_monitor(devnum2devname(st->container_dev));
                        close(container_fd);
                }
        } else {
index e9a5457..9b22220 100644 (file)
@@ -836,28 +836,9 @@ int Incremental_container(struct supertype *st, char *devname, int verbose,
                                sysfs_set_str(sra, NULL, "array_state",
                                              "readonly");
                                /* start mdmon if needed. */
-                               if (mdmon_running(st->container_dev))
-                                       signal_mdmon(st->container_dev);
-                               else if (!env_no_mdmon()) {
-                                       int dn = st->container_dev;
-                                       int i;
-                                       switch(fork()) {
-                                       case 0:
-                                               /* FIXME yuk. CLOSE_EXEC?? */
-                                               for (i=3; i < 100; i++)
-                                                       close(i);
-                                               execl("./mdmon", "mdmon",
-                                                     map_dev(dev2major(dn),
-                                                             dev2minor(dn),
-                                                             1), NULL);
-                                               exit(1);
-                                       case -1: fprintf(stderr, Name
-                                                        ": cannot fork. "
-                                                 "Array remains readonly\n");
-                                               return 1;
-                                       default: ; /* parent - good */
-                                       }
-                               }
+                               if (!mdmon_running(st->container_dev))
+                                       start_mdmon(st->container_dev);
+                               ping_monitor(devnum2devname(st->container_dev));
                                break;
                        }
                        if (verbose >= 0)
diff --git a/mdadm.h b/mdadm.h
index 3672bc9..2c941cc 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -774,6 +774,7 @@ extern int open_container(int fd);
 extern int mdmon_running(int devnum);
 extern int signal_mdmon(int devnum);
 extern int env_no_mdmon(void);
+extern int start_mdmon(int devnum);
 
 extern char *devnum2devname(int num);
 extern int devname2devnum(char *name);
diff --git a/util.c b/util.c
index 283eeb6..da61a0b 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1074,6 +1074,31 @@ int signal_mdmon(int devnum)
        return 0;
 }
 
+int start_mdmon(int devnum)
+{
+       int i;
+
+       if (env_no_mdmon())
+               return 0;
+
+       switch(fork()) {
+       case 0:
+               /* FIXME yuk. CLOSE_EXEC?? */
+               for (i=3; i < 100; i++)
+                       close(i);
+               execl("./mdmon", "mdmon",
+                     map_dev(dev2major(devnum),
+                             dev2minor(devnum),
+                             1), NULL);
+               exit(1);
+       case -1: fprintf(stderr, Name ": cannot run mdmon. "
+                        "Array remains readonly\n");
+               return -1;
+       default: ; /* parent - good */
+       }
+       return 0;
+}
+
 int env_no_mdmon(void)
 {
        char *val = getenv("MDADM_NO_MDMON");