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 <neilb@suse.de>
This commit is contained in:
NeilBrown 2010-12-01 14:51:27 +11:00
parent c82afc17a8
commit acab7bb189
3 changed files with 15 additions and 16 deletions

View File

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

5
Grow.c
View File

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

14
mdadm.c
View File

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