debuggers.hg

changeset 20888:9c6ba538ce75

libxc: mmapbatch-v2 adjustments

Just like the kernel, the fallback implementation of
xc_map_foreign_bulk() should clear the error indication array upon
success.

Also, a few allocations were needlessly using calloc() instead of
malloc().

Finally, in xc_domain_save() allocate the error indicator array once
(along with the other arrays) instead of using realloc() (without
error checking) in the loop body.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jan 22 10:59:51 2010 +0000 (2010-01-22)
parents fbe8f32fa257
children e1d61c5a008d
files tools/libxc/xc_domain_save.c tools/libxc/xc_linux.c tools/libxc/xc_misc.c
line diff
     1.1 --- a/tools/libxc/xc_domain_save.c	Fri Jan 22 10:59:03 2010 +0000
     1.2 +++ b/tools/libxc/xc_domain_save.c	Fri Jan 22 10:59:51 2010 +0000
     1.3 @@ -1059,7 +1059,8 @@ int xc_domain_save(int xc_handle, int io
     1.4      pfn_type   = xc_memalign(PAGE_SIZE, ROUNDUP(
     1.5                                MAX_BATCH_SIZE * sizeof(*pfn_type), PAGE_SHIFT));
     1.6      pfn_batch  = calloc(MAX_BATCH_SIZE, sizeof(*pfn_batch));
     1.7 -    if ( (pfn_type == NULL) || (pfn_batch == NULL) )
     1.8 +    pfn_err    = malloc(MAX_BATCH_SIZE * sizeof(*pfn_err));
     1.9 +    if ( (pfn_type == NULL) || (pfn_batch == NULL) || (pfn_err == NULL) )
    1.10      {
    1.11          ERROR("failed to alloc memory for pfn_type and/or pfn_batch arrays");
    1.12          errno = ENOMEM;
    1.13 @@ -1273,7 +1274,6 @@ int xc_domain_save(int xc_handle, int io
    1.14              if ( batch == 0 )
    1.15                  goto skip; /* vanishingly unlikely... */
    1.16  
    1.17 -            pfn_err = realloc(pfn_err, sizeof(int) * batch);
    1.18              region_base = xc_map_foreign_bulk(
    1.19                  xc_handle, dom, PROT_READ, pfn_type, pfn_err, batch);
    1.20              if ( region_base == NULL )
     2.1 --- a/tools/libxc/xc_linux.c	Fri Jan 22 10:59:03 2010 +0000
     2.2 +++ b/tools/libxc/xc_linux.c	Fri Jan 22 10:59:51 2010 +0000
     2.3 @@ -186,7 +186,7 @@ void *xc_map_foreign_bulk(int xc_handle,
     2.4           * IOCTL_PRIVCMD_MMAPBATCH_V2 is not supported - fall back to
     2.5           * IOCTL_PRIVCMD_MMAPBATCH.
     2.6           */
     2.7 -        xen_pfn_t *pfn = calloc(num, sizeof(*pfn));
     2.8 +        xen_pfn_t *pfn = malloc(num * sizeof(*pfn));
     2.9  
    2.10          if ( pfn )
    2.11          {
     3.1 --- a/tools/libxc/xc_misc.c	Fri Jan 22 10:59:03 2010 +0000
     3.2 +++ b/tools/libxc/xc_misc.c	Fri Jan 22 10:59:51 2010 +0000
     3.3 @@ -360,7 +360,7 @@ void *xc_map_foreign_pages(int xc_handle
     3.4          return NULL;
     3.5      }
     3.6  
     3.7 -    err = calloc(num, sizeof(*err));
     3.8 +    err = malloc(num * sizeof(*err));
     3.9      if (!err)
    3.10          return NULL;
    3.11  
    3.12 @@ -397,7 +397,7 @@ xc_map_foreign_bulk(int xc_handle, uint3
    3.13          return NULL;
    3.14      }
    3.15  
    3.16 -    pfn = calloc(num, sizeof(*pfn));
    3.17 +    pfn = malloc(num * sizeof(*pfn));
    3.18      if (!pfn) {
    3.19          errno = ENOMEM;
    3.20          return NULL;
    3.21 @@ -416,7 +416,8 @@ xc_map_foreign_bulk(int xc_handle, uint3
    3.22                  err[i] = -EINVAL;
    3.23                  break;
    3.24              }
    3.25 -    }
    3.26 +    } else
    3.27 +        memset(err, 0, num * sizeof(*err));
    3.28  
    3.29      free(pfn);
    3.30