From acab7bb189f7f1e2ce1b8bbbc00e20358ce3149c Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Wed, 1 Dec 2010 14:51:27 +1100 Subject: [PATCH] Create/grow: improve checks on number of devices. 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 --- Create.c | 12 ++++++++++-- Grow.c | 5 +++++ mdadm.c | 14 -------------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Create.c b/Create.c index c136473..7c6979a 100644 --- 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 e605591..6e88d6d 100644 --- 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 c5acd43..187ad89 100644 --- 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);