]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Incremental.c
mdopen: be more careful when adding digit to names.
[thirdparty/mdadm.git] / Incremental.c
index ff8aa9a91d3fe949111732312e95fad402bf54c2..f8a5d326d8be27148d4e8aa698fb490fdef24f7b 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;
@@ -391,6 +400,8 @@ int Incremental(char *devname, int verbose, int runstop,
                                ": container %s now has %d devices\n",
                                chosen_name, info.array.working_disks);
                wait_for(chosen_name);
+               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
@@ -596,59 +608,6 @@ static int count_active(struct supertype *st, int mdfd, char **availp,
        return cnt + cnt1;
 }
 
-void RebuildMap(void)
-{
-       struct mdstat_ent *mdstat = mdstat_read(0, 0);
-       struct mdstat_ent *md;
-       struct map_ent *map = NULL;
-       int mdp = get_mdp_major();
-
-       for (md = mdstat ; md ; md = md->next) {
-               struct mdinfo *sra = sysfs_read(-1, md->devnum, GET_DEVS);
-               struct mdinfo *sd;
-
-               for (sd = sra->devs ; sd ; sd = sd->next) {
-                       char dn[30];
-                       int dfd;
-                       int ok;
-                       struct supertype *st;
-                       char *path;
-                       struct mdinfo info;
-
-                       sprintf(dn, "%d:%d", sd->disk.major, sd->disk.minor);
-                       dfd = dev_open(dn, O_RDONLY);
-                       if (dfd < 0)
-                               continue;
-                       st = guess_super(dfd);
-                       if ( st == NULL)
-                               ok = -1;
-                       else
-                               ok = st->ss->load_super(st, dfd, NULL);
-                       close(dfd);
-                       if (ok != 0)
-                               continue;
-                       st->ss->getinfo_super(st, &info);
-                       if (md->devnum > 0)
-                               path = map_dev(MD_MAJOR, md->devnum, 0);
-                       else
-                               path = map_dev(mdp, (-1-md->devnum)<< 6, 0);
-                       map_add(&map, md->devnum,
-                               info.text_version,
-                               info.uuid, path ? : "/unknown");
-                       st->ss->free_super(st);
-                       break;
-               }
-               sysfs_free(sra);
-       }
-       map_write(map);
-       map_free(map);
-       for (md = mdstat ; md ; md = md->next) {
-               struct mdinfo *sra = sysfs_read(-1, md->devnum, GET_VERSION);
-               sysfs_uevent(sra, "change");
-               sysfs_free(sra);
-       }
-}
-
 int IncrementalScan(int verbose)
 {
        /* look at every device listed in the 'map' file.
@@ -829,7 +788,6 @@ int Incremental_container(struct supertype *st, char *devname, int verbose,
 
                err = assemble_container_content(st, mdfd, ra, runstop,
                                                 chosen_name, verbose);
-               close(mdfd);
                if (err)
                        return err;
        }