Neil Brown: Fix autoassemble for stack arrays.

Martin F. Krafft madduck at alioth.debian.org
Tue Jun 24 22:01:54 UTC 2008


Module: mdadm
Branch: upstream
Commit: 1c203a4b5a05789a0de2548294c049481bff2254
URL:    http://git.debian.org/?p=pkg-mdadm/mdadm.git;a=commit;h=1c203a4b5a05789a0de2548294c049481bff2254

Author: Neil Brown <neilb at suse.de>
Date:   Tue May 20 16:28:48 2008 +1000

Fix autoassemble for stack arrays.

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           |   12 +++++++++---
 mdadm.c              |    6 ++++--
 test                 |    2 ++
 tests/07autoassemble |   23 +++++++++++++++++++++++
 4 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/Assemble.c b/Assemble.c
index 8621203..4cea760 100644
--- a/Assemble.c
+++ b/Assemble.c
@@ -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 67823d5..641d717 100644
--- 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 d271985..a62d7e3 100644
--- 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
index 0000000..4496476
--- /dev/null
+++ b/tests/07autoassemble
@@ -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




More information about the pkg-mdadm-commits mailing list