]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Move the test for validity of raid_disk later.
authorNeil Brown <neilb@suse.de>
Tue, 7 Jun 2005 23:03:45 +0000 (23:03 +0000)
committerNeil Brown <neilb@suse.de>
Tue, 7 Jun 2005 23:03:45 +0000 (23:03 +0000)
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>
mdadm.c

diff --git a/mdadm.c b/mdadm.c
index 6c7162a7a164b927a88262113740f5221869b9c8..44fd30c9cf3db74ae8f91460242c2622d8ca9335 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -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) {