]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Fix autoassemble for stack arrays.
authorNeil Brown <neilb@suse.de>
Tue, 20 May 2008 06:28:48 +0000 (16:28 +1000)
committerNeil Brown <neilb@suse.de>
Tue, 20 May 2008 06:28:48 +0000 (16:28 +1000)
If you have stacked arrays, then
  mdadm -As --homehost=fred
should work but doesn't.  It gets into an infinite loop!

So write some tests, and fix the bugs.

Assemble.c
mdadm.c
test
tests/07autoassemble [new file with mode: 0644]

index 862120326d62a352fd75d7cc78be83872dfc775f..4cea76092f8f190f925be2ff13f867b9828b8686 100644 (file)
@@ -377,7 +377,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);
@@ -975,7 +975,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) {
@@ -1009,7 +1012,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
diff --git a/mdadm.c b/mdadm.c
index 67823d50059a9b273534b5d48a2fc605aed6b025..641d7170ed243e721a41f72b380e43ad52d68c1e 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -1100,11 +1100,12 @@ int main(int argc, char *argv[])
                                int acnt;
                                ident.autof = autof;
                                do {
+                                       mddev_dev_t devlist = conf_get_devs();
                                        acnt = 0;
                                        do {
                                                rv2 = Assemble(ss, NULL, -1,
                                                               &ident,
-                                                              NULL, NULL,
+                                                              devlist, NULL,
                                                               readonly, runstop, NULL, homehost, verbose-quiet, force);
                                                if (rv2==0) {
                                                        cnt++;
@@ -1138,7 +1139,8 @@ int main(int argc, char *argv[])
                                if (cnt == 0 && rv == 0) {
                                        fprintf(stderr, Name ": No arrays found in config file or automatically\n");
                                        rv = 1;
-                               }
+                               } else if (cnt)
+                                       rv = 0;
                        } else if (cnt == 0 && rv == 0) {
                                fprintf(stderr, Name ": No arrays found in config file\n");
                                rv = 1;
diff --git a/test b/test
index d2719854717a08ffbf2eaa5a292886f7b8dee9f6..a62d7e319f7343dc4c9d89006c738c893c49ce2c 100644 (file)
--- a/test
+++ b/test
@@ -30,6 +30,8 @@ targetdir=/var/tmp
 size=20000
 # super0, round down to multiple of 64 and substract 64
 mdsize0=19904
+# super00 is nested, subtract 128
+mdsize00=19840
 # super1.0 round down to multiple of 2, subtract 8
 mdsize1=19992
 # subtract another 4 for bitmaps
diff --git a/tests/07autoassemble b/tests/07autoassemble
new file mode 100644 (file)
index 0000000..4496476
--- /dev/null
@@ -0,0 +1,23 @@
+
+# create two raid1s, build a raid0 on top, then
+# tear it down and get auto-assemble to rebuild it.
+
+mdadm -CR $md1 -l1 -n2 $dev0 $dev1  --homehost=testing
+mdadm -CR $md2 -l1 -n2 $dev2 $dev3  --homehost=testing
+mdadm -CR $md0 -l0 -n2 $md1 $md2  --homehost=testing
+
+mdadm -Ss
+mdadm -As -c /dev/null --homehost=testing -vvv
+testdev $md1 1 $mdsize0 64
+testdev $md2 1 $mdsize0 64
+testdev $md0 2 $mdsize00 64
+mdadm -Ss
+
+mdadm --zero-superblock $dev0 $dev1 $dev2 $dev3
+## Now the raid0 uses one stacked and one not
+mdadm -CR $md1 -l1 -n2 $dev0 $dev1  --homehost=testing
+mdadm -CR $md0 -l0 -n2 $md1 $dev2  --homehost=testing
+mdadm -Ss
+mdadm -As -c /dev/null --homehost=testing -vvv
+testdev $md1 1 $mdsize0 64
+testdev $md0 1 $[mdsize0+mdsize00] 64