Move the test for validity of raid_disk later.

This allows the check to be done after we know what
metadata format is being used, and so the max number of raiddisks
is known.

Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au>
This commit is contained in:
Neil Brown 2005-06-07 23:03:45 +00:00
parent 96395475fc
commit e4c4352e49
1 changed files with 22 additions and 8 deletions

30
mdadm.c
View File

@ -427,17 +427,11 @@ int main(int argc, char *argv[])
exit(2);
}
raiddisks = strtol(optarg, &c, 10);
if (!optarg[0] || *c || raiddisks<=0 || raiddisks > max_disks) {
if (!optarg[0] || *c || raiddisks<=0) {
fprintf(stderr, Name ": invalid number of raid devices: %s\n",
optarg);
exit(2);
}
if (raiddisks == 1 && !force && level != -5) {
fprintf(stderr, Name ": '1' is an unusual number of drives for an array, so it is probably\n"
" a mistake. If you really mean it you will need to specify --force before\n"
" setting the number of drives.\n");
exit(2);
}
ident.raid_disks = raiddisks;
continue;
@ -453,7 +447,7 @@ int main(int argc, char *argv[])
exit(2);
}
sparedisks = strtol(optarg, &c, 10);
if (!optarg[0] || *c || sparedisks < 0 || sparedisks > max_disks - raiddisks) {
if (!optarg[0] || *c || sparedisks < 0) {
fprintf(stderr, Name ": invalid number of spare-devices: %s\n",
optarg);
exit(2);
@ -782,6 +776,26 @@ int main(int argc, char *argv[])
}
}
if (raiddisks) {
if (raiddisks > max_disks) {
fprintf(stderr, Name ": invalid number of raid devices: %s\n",
optarg);
exit(2);
}
if (raiddisks == 1 && !force && level != -5) {
fprintf(stderr, Name ": '1' is an unusual number of drives for an array, so it is probably\n"
" a mistake. If you really mean it you will need to specify --force before\n"
" setting the number of drives.\n");
exit(2);
}
}
if (sparedisks) {
if ( sparedisks > max_disks - raiddisks) {
fprintf(stderr, Name ": invalid number of spare-devices: %s\n",
optarg);
exit(2);
}
}
rv = 0;
switch(mode) {