]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Assemble.c
imsm: do not publish OROM/EFI unsupported arrays
[thirdparty/mdadm.git] / Assemble.c
index a9c7875af3d61527933dda821273bf1d1cc31fd1..bfc879c7f4433550aa25e80dc1fd39156544582f 100644 (file)
@@ -330,11 +330,13 @@ int Assemble(struct supertype *st, char *mddev,
                                        fprintf(stderr, Name ": %s is a container, but we are looking for components\n",
                                                devname);
                                tmpdev->used = 2;
+#if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)
                        } if (!tst && (tst = super_by_fd(dfd, NULL)) == NULL) {
                                if (report_missmatch)
                                        fprintf(stderr, Name ": not a recognisable container: %s\n",
                                                devname);
                                tmpdev->used = 2;
+#endif
                        } else if (!tst->ss->load_container
                                   || tst->ss->load_container(tst, dfd, NULL)) {
                                if (report_missmatch)
@@ -595,10 +597,15 @@ int Assemble(struct supertype *st, char *mddev,
                                tmpdev->devname, strerror(errno));
                        tmpdev->used = 2;
                } else {
-                       struct dev_policy *pol = NULL;
-                       pol = devnum_policy(stb.st_rdev);
-                       if (domain_test(domains, pol, NULL))
-                               /* take this spare if domains match */
+                       struct dev_policy *pol = devnum_policy(stb.st_rdev);
+                       int dt = domain_test(domains, pol, NULL);
+                       if (inargv && dt != 0)
+                               /* take this spare as domains match
+                                * if there are any */
+                               tmpdev->used = 1;
+                       else if (!inargv && dt == 1)
+                               /* device wasn't explicitly listed, so need
+                                * explicit domain match - which we have */
                                tmpdev->used = 1;
                        else
                                /* if domains don't match mark as unused */
@@ -689,8 +696,12 @@ int Assemble(struct supertype *st, char *mddev,
 #ifndef MDASSEMBLE
        if (content != &info) {
                /* This is a member of a container.  Try starting the array. */
-               return assemble_container_content(st, mdfd, content, runstop,
-                                          chosen_name, verbose);
+               int err;
+               err = assemble_container_content(st, mdfd, content, runstop,
+                                                chosen_name, verbose,
+                                                backup_file);
+               close(mdfd);
+               return err;
        }
 #endif
        /* Ok, no bad inconsistancy, we can try updating etc */
@@ -1493,42 +1504,87 @@ int Assemble(struct supertype *st, char *mddev,
 #ifndef MDASSEMBLE
 int assemble_container_content(struct supertype *st, int mdfd,
                               struct mdinfo *content, int runstop,
-                              char *chosen_name, int verbose)
+                              char *chosen_name, int verbose,
+                              char *backup_file)
 {
        struct mdinfo *dev, *sra;
        int working = 0, preexist = 0;
+       int expansion = 0;
        struct map_ent *map = NULL;
 
        sysfs_init(content, mdfd, 0);
 
        sra = sysfs_read(mdfd, 0, GET_VERSION);
        if (sra == NULL || strcmp(sra->text_version, content->text_version) != 0)
-               if (sysfs_set_array(content, md_get_version(mdfd)) != 0) {
-                       close(mdfd);
+               if (sysfs_set_array(content, md_get_version(mdfd)) != 0)
                        return 1;
-               }
+
+       if (content->reshape_active)
+               block_subarray(content);
+
        if (sra)
                sysfs_free(sra);
 
        for (dev = content->devs; dev; dev = dev->next)
-               if (sysfs_add_disk(content, dev, 1) == 0)
-                       working++;
-               else if (errno == EEXIST)
+               if (sysfs_add_disk(content, dev, 1) == 0) {
+                       if (dev->disk.raid_disk >= content->array.raid_disks &&
+                           content->reshape_active)
+                               expansion++;
+                       else
+                               working++;
+               } else if (errno == EEXIST)
                        preexist++;
-       if (working == 0) {
-               close(mdfd);
+       if (working == 0)
                return 1;/* Nothing new, don't try to start */
-       }
-       
+
        map_update(&map, fd2devnum(mdfd),
                   content->text_version,
                   content->uuid, chosen_name);
 
        if (runstop > 0 ||
-                (working + preexist) >= content->array.working_disks) {
+                (working + preexist + expansion) >=
+                       content->array.working_disks) {
                int err;
 
-               switch(content->array.level) {
+               if (content->reshape_active) {
+                       int spare = content->array.raid_disks + expansion;
+                       int i;
+                       int *fdlist = malloc(sizeof(int) *
+                                            (working + expansion
+                                             + content->array.raid_disks));
+                       for (i=0; i<spare; i++)
+                               fdlist[i] = -1;
+                       for (dev = content->devs; dev; dev = dev->next) {
+                               char buf[20];
+                               int fd;
+                               sprintf(buf, "%d:%d",
+                                       dev->disk.major,
+                                       dev->disk.minor);
+                               fd = dev_open(buf, O_RDWR);
+
+                               if (dev->disk.raid_disk >= 0)
+                                       fdlist[dev->disk.raid_disk] = fd;
+                               else
+                                       fdlist[spare++] = fd;
+                       }
+                       err = Grow_restart(st, content, fdlist, spare,
+                                          backup_file, verbose > 0);
+                       while (spare > 0) {
+                               spare--;
+                               if (fdlist[spare] >= 0)
+                                       close(fdlist[spare]);
+                       }
+                       if (err) {
+                               fprintf(stderr, Name ": Failed to restore critical"
+                                       " section for reshape - sorry.\n");
+                               if (!backup_file)
+                                       fprintf(stderr, Name ":  Possibly you need"
+                                               " to specify a --backup-file\n");
+                               return 1;
+                       }
+
+                       err = Grow_continue(mdfd, st, content, backup_file);
+               } else switch(content->array.level) {
                case LEVEL_LINEAR:
                case LEVEL_MULTIPATH:
                case 0:
@@ -1559,12 +1615,14 @@ int assemble_container_content(struct supertype *st, int mdfd,
                                        chosen_name, working + preexist);
                        if (preexist)
                                fprintf(stderr, " (%d new)", working);
+                       if (expansion)
+                               fprintf(stderr, " ( + %d for expansion)",
+                                       expansion);
                        fprintf(stderr, "\n");
                }
                if (!err)
                        wait_for(chosen_name, mdfd);
-               close(mdfd);
-               return 0;
+               return err;
                /* FIXME should have an O_EXCL and wait for read-auto */
        } else {
                if (verbose >= 0)
@@ -1572,7 +1630,6 @@ int assemble_container_content(struct supertype *st, int mdfd,
                                ": %s assembled with %d devices but "
                                "not started\n",
                                chosen_name, working);
-               close(mdfd);
                return 1;
        }
 }