]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Assemble.c
fix mdmon option parsing
[thirdparty/mdadm.git] / Assemble.c
index a52dc50dc4c4f6b32bef6bae944895265a9c3a08..1f73a5be05f5339ee6811860f269e0556bc684d5 100644 (file)
@@ -434,7 +434,7 @@ int Assemble(struct supertype *st, char *mddev,
                                }
                        }
                        st = tst; tst = NULL;
-                       if (!auto_assem && tmpdev->next != NULL) {
+                       if (!auto_assem && inargv && tmpdev->next != NULL) {
                                fprintf(stderr, Name ": %s is a container, but is not "
                                        "only device given: confused and aborting\n",
                                        devname);
@@ -619,7 +619,14 @@ int Assemble(struct supertype *st, char *mddev,
                        remove_partitions(dfd);
 
                        tst = dup_super(st);
-                       tst->ss->load_super(tst, dfd, NULL);
+                       if (dfd < 0 || tst->ss->load_super(tst, dfd, NULL) != 0) {
+                               fprintf(stderr, Name ": cannot re-read metadata from %s - aborting\n",
+                                       devname);
+                               if (dfd >= 0)
+                                       close(dfd);
+                               close(mdfd);
+                               return 1;
+                       }
                        tst->ss->getinfo_super(tst, content);
 
                        memcpy(content->uuid, ident->uuid, 16);
@@ -662,7 +669,14 @@ int Assemble(struct supertype *st, char *mddev,
 
                        remove_partitions(dfd);
 
-                       tst->ss->load_super(tst, dfd, NULL);
+                       if (dfd < 0 || tst->ss->load_super(tst, dfd, NULL) != 0) {
+                               fprintf(stderr, Name ": cannot re-read metadata from %s - aborting\n",
+                                       devname);
+                               if (dfd >= 0)
+                                       close(dfd);
+                               close(mdfd);
+                               return 1;
+                       }
                        tst->ss->getinfo_super(tst, content);
                        tst->ss->free_super(tst);
                        close(dfd);
@@ -683,7 +697,7 @@ int Assemble(struct supertype *st, char *mddev,
                            > devices[most_recent].i.events)
                                most_recent = devcnt;
                }
-               if (content->array.level == -4)
+               if (content->array.level == LEVEL_MULTIPATH)
                        /* with multipath, the raid_disk from the superblock is meaningless */
                        i = devcnt;
                else
@@ -776,8 +790,8 @@ int Assemble(struct supertype *st, char *mddev,
                /* note: we ignore error flags in multipath arrays
                 * as they don't make sense
                 */
-               if (content->array.level != -4)
-                       if (!(devices[j].i.disk.state & (1<<MD_DISK_SYNC))) {
+               if (content->array.level != LEVEL_MULTIPATH)
+                       if (!(devices[j].i.disk.state & (1<<MD_DISK_ACTIVE))) {
                                if (!(devices[j].i.disk.state
                                      & (1<<MD_DISK_FAULTY)))
                                        sparecnt++;
@@ -786,7 +800,8 @@ int Assemble(struct supertype *st, char *mddev,
                if (devices[j].i.events+event_margin >=
                    devices[most_recent].i.events) {
                        devices[j].uptodate = 1;
-                       if (i < content->array.raid_disks) {
+                       if (i < content->array.raid_disks &&
+                           devices[j].i.recovery_start == MaxSector) {
                                okcnt++;
                                avail[i]=1;
                        } else
@@ -808,6 +823,7 @@ int Assemble(struct supertype *st, char *mddev,
                        int j = best[i];
                        if (j>=0 &&
                            !devices[j].uptodate &&
+                           devices[j].i.recovery_start == MaxSector &&
                            (chosen_drive < 0 ||
                             devices[j].i.events
                             > devices[chosen_drive].i.events))
@@ -990,7 +1006,7 @@ int Assemble(struct supertype *st, char *mddev,
        if (content->reshape_active) {
                int err = 0;
                int *fdlist = malloc(sizeof(int)* bestcnt);
-               if (verbose)
+               if (verbose > 0)
                        fprintf(stderr, Name ":%s has an active reshape - checking "
                                "if critical section needs to be restored\n",
                                chosen_name);
@@ -1008,7 +1024,7 @@ int Assemble(struct supertype *st, char *mddev,
                                fdlist[i] = -1;
                }
                if (!err)
-                       err = Grow_restart(st, content, fdlist, bestcnt, backup_file, verbose);
+                       err = Grow_restart(st, content, fdlist, bestcnt, backup_file, verbose > 0);
                while (i>0) {
                        i--;
                        if (fdlist[i]>=0) close(fdlist[i]);
@@ -1041,12 +1057,14 @@ int Assemble(struct supertype *st, char *mddev,
                if (rv) {
                        fprintf(stderr, Name ": failed to set array info for %s: %s\n",
                                mddev, strerror(errno));
+                       ioctl(mdfd, STOP_ARRAY, NULL);
                        close(mdfd);
                        return 1;
                }
                if (ident->bitmap_fd >= 0) {
                        if (ioctl(mdfd, SET_BITMAP_FILE, ident->bitmap_fd) != 0) {
                                fprintf(stderr, Name ": SET_BITMAP_FILE failed.\n");
+                               ioctl(mdfd, STOP_ARRAY, NULL);
                                close(mdfd);
                                return 1;
                        }
@@ -1056,12 +1074,14 @@ int Assemble(struct supertype *st, char *mddev,
                        if (bmfd < 0) {
                                fprintf(stderr, Name ": Could not open bitmap file %s\n",
                                        ident->bitmap_file);
+                               ioctl(mdfd, STOP_ARRAY, NULL);
                                close(mdfd);
                                return 1;
                        }
                        if (ioctl(mdfd, SET_BITMAP_FILE, bmfd) != 0) {
                                fprintf(stderr, Name ": Failed to set bitmapfile for %s\n", mddev);
                                close(bmfd);
+                               ioctl(mdfd, STOP_ARRAY, NULL);
                                close(mdfd);
                                return 1;
                        }