]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
imsm: fix insufficient mpb buffer allocation
authorDan Williams <dan.j.williams@intel.com>
Sat, 21 Jun 2008 07:19:53 +0000 (00:19 -0700)
committerDan Williams <dan.j.williams@intel.com>
Mon, 14 Jul 2008 20:56:28 +0000 (13:56 -0700)
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
super-intel.c

index 39528c2fb75598e9b0c03408dc63b6dde9f25ab8..b977a41a95ce522641fd4aab3aabc18ca73ab724 100644 (file)
@@ -1039,6 +1039,7 @@ static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info,
        unsigned long long array_blocks;
        unsigned long long sz;
        __u32 offset = 0;
+       size_t size_old, size_new;
 
        if (mpb->num_raid_devs >= 2) {
                fprintf(stderr, Name": This imsm-container already has the "
@@ -1046,6 +1047,24 @@ static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info,
                return 0;
        }
 
+       /* ensure the mpb is large enough for the new data */
+       size_old = __le32_to_cpu(mpb->mpb_size);
+       size_new = disks_to_mpb_size(info->nr_disks);
+       if (size_new > size_old) {
+               void *mpb_new;
+               size_t size_round = ROUND_UP(size_new, 512);
+
+               if (posix_memalign(&mpb_new, 512, size_round) != 0) {
+                       fprintf(stderr, Name": could not allocate new mpb\n");
+                       return 0;
+               }
+               memcpy(mpb_new, mpb, size_old);
+               free(mpb);
+               mpb = mpb_new;
+               super->mpb = mpb_new;
+               mpb->mpb_size = __cpu_to_le32(size_new);
+               memset(mpb_new + size_old, 0, size_round - size_old);
+       }
        super->current_vol = idx;
        sprintf(st->subarray, "%d", idx);
        mpb->num_raid_devs++;