From: NeilBrown Date: Wed, 9 Mar 2011 07:37:00 +0000 (+1100) Subject: Grow: add check that there are enough devices. X-Git-Tag: mdadm-3.2.1~79 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e06c4e59b328ed881007962d22db17bfe9e07b6c;p=thirdparty%2Fmdadm.git Grow: add check that there are enough devices. The check for 'enough spares' doesn't apply to RAID0 as we don't mind it going degraded. But add a test that there are enough spares to actually produce a working array. Signed-off-by: NeilBrown --- diff --git a/Grow.c b/Grow.c index 579498f5..2c99924b 100644 --- a/Grow.c +++ b/Grow.c @@ -1675,6 +1675,7 @@ static int reshape_array(char *container, int fd, char *devname, * freeze_array and freeze_container. */ sysfs_freeze_array(info); + /* Check we have enough spares to not be degraded */ spares_needed = max(reshape.before.data_disks, reshape.after.data_disks) + reshape.parity - array.raid_disks; @@ -1691,6 +1692,20 @@ static int reshape_array(char *container, int fd, char *devname, info->array.spare_disks); goto release; } + /* Check we have enough spares to not fail */ + spares_needed = max(reshape.before.data_disks, + reshape.after.data_disks) + - array.raid_disks; + if ((info->new_level > 1 || info->new_level == 0) && + spares_needed > info->array.spare_disks) { + fprintf(stderr, + Name ": Need %d spare%s to create working array," + " and only have %d.\n", + spares_needed, + spares_needed == 1 ? "" : "s", + info->array.spare_disks); + goto release; + } if (reshape.level != info->array.level) { char *c = map_num(pers, reshape.level);