]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Create.c
Remove st->text_version in favour of info->text_version
[thirdparty/mdadm.git] / Create.c
index 0bc473809cbaed44539b68da41bb6663f971ccc1..b7f0914329b79940db80577b615e3a73e6ea4052 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -71,6 +71,8 @@ int Create(struct supertype *st, char *mddev, int mdfd,
        int rv;
        int bitmap_fd;
        int have_container = 0;
+       int container_fd;
+       int need_mdmon = 0;
        unsigned long long bitmapsize;
        struct mdinfo *sra;
        struct mdinfo info;
@@ -94,10 +96,10 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                }
        }
        if (level == UnSet) {
-               /* "ddf" metadata only supports one level - should possibly
+               /* "ddf" and "imsm" metadata only supports one level - should possibly
                 * push this into metadata handler??
                 */
-               if (st && st->ss == &super_ddf)
+               if (st && (st->ss == &super_ddf || st->ss == &super_imsm))
                        level = LEVEL_CONTAINER;
        }
 
@@ -510,6 +512,8 @@ int Create(struct supertype *st, char *mddev, int mdfd,
        if (!st->ss->init_super(st, &info.array, size, name, homehost, uuid))
                return 1;
 
+       st->ss->getinfo_super(st, &info);
+
        if (bitmap_file && vers < 9003) {
                major_num = BITMAP_MAJOR_HOSTENDIAN;
 #ifdef __BIG_ENDIAN
@@ -537,7 +541,41 @@ int Create(struct supertype *st, char *mddev, int mdfd,
 
        if (st->ss->external) {
                char ver[100];
-               strcat(strcpy(ver, "external:"), st->ss->text_version);
+               if (st->ss->external == 1)
+                       /* container */
+                       strcat(strcpy(ver, "external:"),
+                              info.text_version);
+               else {
+                       /* member */
+                       sprintf(ver, "external:/%s/%d",
+                               devnum2devname(st->container_dev),
+                               st->container_member);
+                       /* When creating a member, we need to be careful
+                        * to negotiate with mdmon properly.
+                        * If it is already running, we cannot write to
+                        * the devices and must ask it to do that part.
+                        * If it isn't running, we write to the devices,
+                        * and then start it.
+                        * We hold an exclusive open on the container
+                        * device to make sure mdmon doesn't exit after
+                        * we checked that it is running.
+                        *
+                        * For now, fail if it is already running.
+                        */
+                       container_fd = open_dev_excl(st->container_dev);
+                       if (container_fd < 0) {
+                               fprintf(stderr, Name ": Cannot get exclusive "
+                                       "open on container - weird.\n");
+                               return 1;
+                       }
+                       if (mdmon_running(st->container_dev)) {
+                               fprintf(stderr, Name ": mdmon already running "
+                                       "for %s - sorry\n",
+                                       devnum2devname(st->container_dev));
+                               return 1;
+                       }
+                       need_mdmon = 1;
+               }
                if ((vers % 100) < 2 ||
                    sra == NULL ||
                    sysfs_set_str(sra, NULL, "metadata_version",
@@ -632,16 +670,15 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                                                     fd, dv->devname);
                                break;
                        case 2:
+                               close(fd);
                                info.component_size = info.array.size * 2;
                                info.errors = 0;
                                rv = 0;
 
                                if (st->ss->external) {
                                        st->ss->getinfo_super_n(st, &info);
-                                       rv = sysfs_add_disk(sra, fd, &info);
-                                       close(fd);
+                                       rv = sysfs_add_disk(sra, &info);
                                } else {
-                                       close(fd);
                                        rv = ioctl(mdfd, ADD_NEW_DISK,
                                                 &info.disk);
                                }
@@ -674,6 +711,7 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                        case 0:
                                sysfs_set_str(sra, NULL, "array_state",
                                              "active");
+                               need_mdmon = 0;
                                break;
                        default:
                                sysfs_set_str(sra, NULL, "array_state",
@@ -691,6 +729,31 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                }
                if (verbose >= 0)
                        fprintf(stderr, Name ": array %s started.\n", mddev);
+               if (st->ss->external == 2) {
+                       if (need_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);
+                       close(container_fd);
+               }
        } else {
                fprintf(stderr, Name ": not starting array - not enough devices.\n");
        }