]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Grow: add check that there are enough devices.
authorNeilBrown <neilb@suse.de>
Wed, 9 Mar 2011 07:37:00 +0000 (18:37 +1100)
committerNeilBrown <neilb@suse.de>
Wed, 9 Mar 2011 07:37:00 +0000 (18:37 +1100)
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 <neilb@suse.de>
Grow.c

diff --git a/Grow.c b/Grow.c
index 579498f54d4efc8a10c439a749bf18e368af0622..2c99924bf9a011c631ce714315ed6399f401cf48 100644 (file)
--- 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);