]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Assemble.c
Merge branch 'master' into devel-3.0
[thirdparty/mdadm.git] / Assemble.c
index 16f45cdf1ddc6bd21afa95ffec6e91e29633ed74..cb2725db5ebe6db9a48606a0b67bd852cc295690 100644 (file)
@@ -367,7 +367,8 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
                tmpdev->used = 1;
 
        loop:
-               tst->ss->free_super(tst);
+               if (tst)
+                       tst->ss->free_super(tst);
        }
 
        if (mdfd < 0) {
@@ -377,7 +378,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
                 */
                mdu_array_info_t inf;
                char *c;
-               if (!st->sb) {
+               if (!st || !st->sb) {
                        return 2;
                }
                st->ss->getinfo_super(st, &info);
@@ -568,17 +569,18 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
                devcnt++;
        }
 
-       if (update && strcmp(update, "byteorder")==0)
-               st->minor_version = 90;
-
        if (devcnt == 0) {
                fprintf(stderr, Name ": no devices found for %s\n",
                        mddev);
-               st->ss->free_super(st);
+               if (st)
+                       st->ss->free_super(st);
                if (must_close) close(mdfd);
                return 1;
        }
 
+       if (update && strcmp(update, "byteorder")==0)
+               st->minor_version = 90;
+
        st->ss->getinfo_super(st, &info);
        clean = info.array.state & 1;
 
@@ -654,7 +656,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
                        continue;
                }
                tst = dup_super(st);
-               if (tst->ss->load_super(st,fd, NULL)) {
+               if (tst->ss->load_super(tst,fd, NULL)) {
                        close(fd);
                        fprintf(stderr, Name ": RAID superblock disappeared from %s - not updating.\n",
                                devices[chosen_drive].devname);
@@ -1020,7 +1022,10 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
                                        "start the array while not clean "
                                        "- consider --force.\n");
 
-                       if (must_close) close(mdfd);
+                       if (must_close) {
+                               ioctl(mdfd, STOP_ARRAY, NULL);
+                               close(mdfd);
+                       }
                        return 1;
                }
                if (runstop == -1) {
@@ -1054,7 +1059,10 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
                                fprintf(stderr, " (use --run to insist).\n");
                        }
                }
-               if (must_close) close(mdfd);
+               if (must_close) {
+                       ioctl(mdfd, STOP_ARRAY, NULL);
+                       close(mdfd);
+               }
                return 1;
        } else {
                /* The "chosen_drive" is a good choice, and if necessary, the superblock has