]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
raid0->raid10 takeover- allocate memory for added disks
authorKrzysztof Wojcik <krzysztof.wojcik@intel.com>
Tue, 25 Jan 2011 06:44:10 +0000 (17:44 +1100)
committerNeilBrown <neilb@suse.de>
Wed, 26 Jan 2011 00:38:10 +0000 (10:38 +1000)
Allocate memory will be used in process_update.
For raid0->raid10 takeover operation number of disks doubles
so we should allocate memory for additional disks
and one imsm_dev structure with extended order table.

Signed-off-by: Krzysztof Wojcik <krzysztof.wojcik@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
super-intel.c

index dd3acebf6992565128d81ea42b643d3164088657..8a3fe7fc64be7af687bb6ea75941ef29ea4a1922 100644 (file)
@@ -6189,6 +6189,53 @@ static void imsm_prepare_update(struct supertype *st,
        size_t len = 0;
 
        switch (type) {
+       case update_takeover: {
+               struct imsm_update_takeover *u = (void *)update->buf;
+               if (u->direction == R0_TO_R10) {
+                       void **tail = (void **)&update->space_list;
+                       struct imsm_dev *dev = get_imsm_dev(super, u->subarray);
+                       struct imsm_map *map = get_imsm_map(dev, 0);
+                       int num_members = map->num_members;
+                       void *space;
+                       int size, i;
+                       int err = 0;
+                       /* allocate memory for added disks */
+                       for (i = 0; i < num_members; i++) {
+                               size = sizeof(struct dl);
+                               space = malloc(size);
+                               if (!space) {
+                                       err++;
+                                       break;
+                               }
+                               *tail = space;
+                               tail = space;
+                               *tail = NULL;
+                       }
+                       /* allocate memory for new device */
+                       size = sizeof_imsm_dev(super->devlist->dev, 0) +
+                               (num_members * sizeof(__u32));
+                       space = malloc(size);
+                       if (!space)
+                               err++;
+                       else {
+                               *tail = space;
+                               tail = space;
+                               *tail = NULL;
+                       }
+                       if (!err) {
+                               len = disks_to_mpb_size(num_members * 2);
+                       } else {
+                               /* if allocation didn't success, free buffer */
+                               while (update->space_list) {
+                                       void **sp = update->space_list;
+                                       update->space_list = *sp;
+                                       free(sp);
+                               }
+                       }
+               }
+
+               break;
+       }
        case update_reshape_container_disks: {
                /* Every raid device in the container is about to
                 * gain some more devices, and we will enter a