]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Create/grow: improve checks on number of devices.
authorNeilBrown <neilb@suse.de>
Wed, 1 Dec 2010 03:51:27 +0000 (14:51 +1100)
committerNeilBrown <neilb@suse.de>
Wed, 1 Dec 2010 03:51:27 +0000 (14:51 +1100)
Check on upper limit of number of devices was in the wrong place.
Result was could not create array with more than 27 devices without
explicitly setting metadata, even though default metadata allows more.

Fixed, and also perform check when growing an array.

Signed-off-by: NeilBrown <neilb@suse.de>
Create.c
Grow.c
mdadm.c

index c1364731f52f1f7c3761e9ce014116da91aae94f..7c6979ac2047ad68e55035585aef7c3e8f937143 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -66,11 +66,13 @@ static int default_layout(struct supertype *st, int level, int verbose)
 
 
 int Create(struct supertype *st, char *mddev,
-          int chunk, int level, int layout, unsigned long long size, int raiddisks, int sparedisks,
+          int chunk, int level, int layout, unsigned long long size,
+          int raiddisks, int sparedisks,
           char *name, char *homehost, int *uuid,
           int subdevs, struct mddev_dev *devlist,
           int runstop, int verbose, int force, int assume_clean,
-          char *bitmap_file, int bitmap_chunk, int write_behind, int delay, int autof)
+          char *bitmap_file, int bitmap_chunk, int write_behind,
+          int delay, int autof)
 {
        /*
         * Create a new raid array.
@@ -395,6 +397,12 @@ int Create(struct supertype *st, char *mddev,
                        close(fd);
                }
        }
+       if (raiddisks + sparedisks > st->max_devs) {
+               fprintf(stderr, Name ": Too many devices:"
+                       " %s metadata only supports %d\n",
+                       st->ss->name, st->max_devs);
+               return 1;
+       }
        if (have_container)
                info.array.working_disks = raiddisks;
        if (fail) {
diff --git a/Grow.c b/Grow.c
index e6055916cfc3e8db893cc38315f684d840efeffd..6e88d6d1914e975a4d42324e7ec42d7784033743 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -1017,6 +1017,11 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
                fprintf(stderr, Name ": Unable to determine metadata format for %s\n", devname);
                return 1;
        }
+       if (raid_disks > st->max_devs) {
+               fprintf(stderr, Name ": Cannot increase raid-disks on this array"
+                       " beyond %d\n", st->max_devs);
+               return 1;
+       }
 
        /* in the external case we need to check that the requested reshape is
         * supported, and perform an initial check that the container holds the
diff --git a/mdadm.c b/mdadm.c
index c5acd43e29043f29b84c0bd827789e8207fd41ae..187ad891031de6b80f3933c1528d312c1d0c7ecc 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -46,7 +46,6 @@ int main(int argc, char *argv[])
        int layout = UnSet;
        char *layout_str = NULL;
        int raiddisks = 0;
-       int max_disks = MD_SB_DISKS; /* just a default */
        int sparedisks = 0;
        struct mddev_ident ident;
        char *configfile = NULL;
@@ -384,7 +383,6 @@ int main(int argc, char *argv[])
                                fprintf(stderr, Name ": unrecognised metadata identifier: %s\n", optarg);
                                exit(2);
                        }
-                       max_disks = ss->max_devs;
                        continue;
 
                case O(MANAGE,'W'):
@@ -1122,11 +1120,6 @@ int main(int argc, char *argv[])
        }
 
        if (raiddisks) {
-               if (raiddisks > max_disks) {
-                       fprintf(stderr, Name ": invalid number of raid devices: %d\n",
-                               raiddisks);
-                       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"
@@ -1134,13 +1127,6 @@ int main(int argc, char *argv[])
                        exit(2);
                }
        }
-       if (sparedisks) {
-               if ( sparedisks > max_disks - raiddisks) {
-                       fprintf(stderr, Name ": invalid number of spare-devices: %d\n",
-                               sparedisks);
-                       exit(2);
-               }
-       }
 
        if (homehost == NULL)
                homehost = conf_get_homehost(&require_homehost);