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.
This commit is contained in:
Neil Brown 2008-05-20 16:28:48 +10:00
parent df5a0b9295
commit 1c203a4b5a
4 changed files with 38 additions and 5 deletions

View 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

View File

@ -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;

2
test
View File

@ -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

23
tests/07autoassemble Normal file
View File

@ -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