]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Create.c
Create: print message when preparing a container.
[thirdparty/mdadm.git] / Create.c
index 87cfebf9d56818b32ce33cc34e24e47944272e58..f69cfd9a3e57bce429b041df4f8c0a6b752f3ef2 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -79,6 +79,8 @@ int Create(struct supertype *st, char *mddev,
        struct mdinfo info, *infos;
        int did_default = 0;
        unsigned long safe_mode_delay = 0;
+       char chosen_name[1024];
+       struct map_ent *map = NULL;
 
        int major_num = BITMAP_MAJOR_HI;
 
@@ -311,7 +313,7 @@ int Create(struct supertype *st, char *mddev,
                }
 
                if (size && freesize < size) {
-                       fprintf(stderr, Name ": %s is smaller that given size."
+                       fprintf(stderr, Name ": %s is smaller than given size."
                                " %lluK < %lluK + metadata\n",
                                dname, freesize, size);
                        fail = 1;
@@ -387,7 +389,8 @@ int Create(struct supertype *st, char *mddev,
         * as missing, so that a reconstruct happens (faster than re-parity)
         * FIX: Can we do this for raid6 as well?
         */
-       if (assume_clean==0 && force == 0 && first_missing >= raiddisks) {
+       if (st->ss->external == 0 &&
+           assume_clean==0 && force == 0 && first_missing >= raiddisks) {
                switch ( level ) {
                case 4:
                case 5:
@@ -421,9 +424,11 @@ int Create(struct supertype *st, char *mddev,
        }
 
        /* We need to create the device */
-       mdfd = create_mddev(mddev, autof);
+       map_lock(&map);
+       mdfd = create_mddev(mddev, name, autof, LOCAL, chosen_name);
        if (mdfd < 0)
                return 1;
+       mddev = chosen_name;
 
        vers = md_get_version(mdfd);
        if (vers < 9000) {
@@ -439,6 +444,7 @@ int Create(struct supertype *st, char *mddev,
                        goto abort;
                }
        }
+
        /* Ok, lets try some ioctls */
 
        info.array.level = level;
@@ -514,6 +520,7 @@ int Create(struct supertype *st, char *mddev,
                 *  /dev/md/home -> home
                 *  /dev/mdhome -> home
                 */
+               /* FIXME compare this with rules in create_mddev */
                name = strrchr(mddev, '/');
                if (name) {
                        name++;
@@ -558,6 +565,10 @@ int Create(struct supertype *st, char *mddev,
                                " %s metadata\n", info.text_version);
        }
 
+       map_update(&map, fd2devnum(mdfd), info.text_version,
+                  info.uuid, chosen_name);
+       map_unlock(&map);
+
        if (bitmap_file && vers < 9003) {
                major_num = BITMAP_MAJOR_HOSTENDIAN;
 #ifdef __BIG_ENDIAN
@@ -694,8 +705,9 @@ int Create(struct supertype *st, char *mddev,
                                inf->disk.minor = minor(stb.st_rdev);
 
                                remove_partitions(fd);
-                               st->ss->add_to_super(st, &inf->disk,
-                                                    fd, dv->devname);
+                               if (st->ss->add_to_super(st, &inf->disk,
+                                                        fd, dv->devname))
+                                       goto abort;
                                st->ss->getinfo_super(st, inf);
                                safe_mode_delay = inf->safe_mode_delay;
 
@@ -729,11 +741,13 @@ int Create(struct supertype *st, char *mddev,
        free(infos);
        st->ss->free_super(st);
 
-       /* param is not actually used */
-       if (level == LEVEL_CONTAINER)
-               /* No need to start */
-               ;
-       else if (runstop == 1 || subdevs >= raiddisks) {
+       if (level == LEVEL_CONTAINER) {
+               /* No need to start.  But we should signal udev to
+                * create links */
+               sysfs_uevent(&info, "change");
+               if (verbose >= 0)
+                       fprintf(stderr, Name ": container %s prepared.\n", mddev);
+       } else if (runstop == 1 || subdevs >= raiddisks) {
                if (st->ss->external) {
                        switch(level) {
                        case LEVEL_LINEAR:
@@ -750,6 +764,7 @@ int Create(struct supertype *st, char *mddev,
                        }
                        sysfs_set_safemode(&info, safe_mode_delay);
                } else {
+                       /* param is not actually used */
                        mdu_param_t param;
                        if (ioctl(mdfd, RUN_ARRAY, &param)) {
                                fprintf(stderr, Name ": RUN_ARRAY failed: %s\n",
@@ -767,6 +782,7 @@ int Create(struct supertype *st, char *mddev,
                        ping_monitor(devnum2devname(st->container_dev));
                        close(container_fd);
                }
+               wait_for(chosen_name);
        } else {
                fprintf(stderr, Name ": not starting array - not enough devices.\n");
        }