]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Incremental.c
wait_for improvement.
[thirdparty/mdadm.git] / Incremental.c
index 43b1f77638a2977e73126355591eabe8c4c5d615..b1cee23fe0c94285047789ee3bb7c1bf3747d29e 100644 (file)
@@ -220,11 +220,8 @@ int Incremental(char *devname, int verbose, int runstop,
        else if (homehost == NULL ||
                 st->ss->match_home(st, homehost) != 1)
                trustworthy = FOREIGN;
-       name_to_use = strchr(info.name, ':');
-       if (name_to_use)
-               name_to_use++;
        else
-               name_to_use = info.name;
+               trustworthy = LOCAL;
 
        /* There are three possible sources for 'autof':  command line,
         * ARRAY line in mdadm.conf, or CREATE line in mdadm.conf.
@@ -243,6 +240,19 @@ int Incremental(char *devname, int verbose, int runstop,
                return Incremental_container(st, devname, verbose, runstop,
                                             autof, trustworthy);
        }
+       name_to_use = strchr(info.name, ':');
+       if (name_to_use)
+               name_to_use++;
+       else
+               name_to_use = info.name;
+
+       if ((!name_to_use || name_to_use[0] == 0) &&
+           info.array.level == LEVEL_CONTAINER &&
+           trustworthy == LOCAL) {
+               name_to_use = info.text_version;
+               trustworthy = METADATA;
+       }
+
        /* 4/ Check if array exists.
         */
        map_lock(&map);
@@ -265,8 +275,7 @@ int Incremental(char *devname, int verbose, int runstop,
 
                /* Couldn't find an existing array, maybe make a new one */
                mdfd = create_mddev(match ? match->devname : NULL,
-                                   info.name, autof, trustworthy, chosen_name);
-
+                                   name_to_use, autof, trustworthy, chosen_name);
 
                if (mdfd < 0)
                        return 1;
@@ -383,14 +392,16 @@ int Incremental(char *devname, int verbose, int runstop,
        /* 7a/ if not, finish with success. */
        if (info.array.level == LEVEL_CONTAINER) {
                /* Try to assemble within the container */
-               close(mdfd);
                map_unlock(&map);
                sysfs_uevent(&info, "change");
                if (verbose >= 0)
                        fprintf(stderr, Name
                                ": container %s now has %d devices\n",
                                chosen_name, info.array.working_disks);
-               wait_for(chosen_name);
+               wait_for(chosen_name, mdfd);
+               close(mdfd);
+               if (runstop < 0)
+                       return 0; /* don't try to assemble */
                return Incremental(chosen_name, verbose, runstop,
                                   NULL, homehost, autof);
        }
@@ -398,7 +409,8 @@ int Incremental(char *devname, int verbose, int runstop,
        active_disks = count_active(st, mdfd, &avail, &info);
        if (enough(info.array.level, info.array.raid_disks,
                   info.array.layout, info.array.state & 1,
-                  avail, active_disks) == 0) {
+                  avail, active_disks) == 0 ||
+           (runstop < 0 && active_disks < info.array.raid_disks)) {
                free(avail);
                if (verbose >= 0)
                        fprintf(stderr, Name
@@ -462,7 +474,7 @@ int Incremental(char *devname, int verbose, int runstop,
                           ": %s attached to %s, which has been started.\n",
                                        devname, chosen_name);
                        rv = 0;
-                       wait_for(chosen_name);
+                       wait_for(chosen_name, mdfd);
                } else {
                        fprintf(stderr, Name
                              ": %s attached to %s, but failed to start: %s.\n",
@@ -721,7 +733,10 @@ int Incremental_container(struct supertype *st, char *devname, int verbose,
 
                mp = map_by_uuid(&map, ra->uuid);
 
-               if (!mp) {
+               if (mp) {
+                       mdfd = open_dev(mp->devnum);
+                       strcpy(chosen_name, mp->path);
+               } else {
 
                        /* Check in mdadm.conf for devices == devname and
                         * member == ra->text_version after second slash.
@@ -760,13 +775,13 @@ int Incremental_container(struct supertype *st, char *devname, int verbose,
                                                array_list->member);
                                break;
                        }
-               }
 
-               mdfd = create_mddev(match ? match->devname : NULL,
-                                   ra->name,
-                                   autof,
-                                   trustworthy,
-                                   chosen_name);
+                       mdfd = create_mddev(match ? match->devname : NULL,
+                                           ra->name,
+                                           autof,
+                                           trustworthy,
+                                           chosen_name);
+               }
 
                if (mdfd < 0) {
                        fprintf(stderr, Name ": failed to open %s: %s.\n",