ia64/xen-unstable

changeset 13517:cd532c9351fc

[LIBXC] Convert between byte-based and 64-bit bitmap arrays. Use this
for conversion of the domctl_cpumap.
Original patch from Jimi Xenidis <jimix@watson.ibm.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Jan 19 14:36:12 2007 +0000 (2007-01-19)
parents fa5bc90a3cb7
children 1a45828882e9
files tools/libxc/xc_domain.c tools/libxc/xc_private.c tools/libxc/xc_private.h
line diff
     1.1 --- a/tools/libxc/xc_domain.c	Fri Jan 19 14:24:28 2007 +0000
     1.2 +++ b/tools/libxc/xc_domain.c	Fri Jan 19 14:36:12 2007 +0000
     1.3 @@ -96,16 +96,19 @@ int xc_vcpu_setaffinity(int xc_handle,
     1.4  {
     1.5      DECLARE_DOMCTL;
     1.6      int ret = -1;
     1.7 +    uint8_t local[sizeof (cpumap)];
     1.8  
     1.9      domctl.cmd = XEN_DOMCTL_setvcpuaffinity;
    1.10      domctl.domain = (domid_t)domid;
    1.11      domctl.u.vcpuaffinity.vcpu    = vcpu;
    1.12  
    1.13 -    set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap,
    1.14 -                         (uint8_t *)&cpumap);
    1.15 +    bitmap_64_to_byte(local, &cpumap, sizeof (cpumap));
    1.16 +
    1.17 +    set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, local);
    1.18 +
    1.19      domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap) * 8;
    1.20      
    1.21 -    if ( lock_pages(&cpumap, sizeof(cpumap)) != 0 )
    1.22 +    if ( lock_pages(local, sizeof(local)) != 0 )
    1.23      {
    1.24          PERROR("Could not lock memory for Xen hypercall");
    1.25          goto out;
    1.26 @@ -113,7 +116,7 @@ int xc_vcpu_setaffinity(int xc_handle,
    1.27  
    1.28      ret = do_domctl(xc_handle, &domctl);
    1.29  
    1.30 -    unlock_pages(&cpumap, sizeof(cpumap));
    1.31 +    unlock_pages(local, sizeof(local));
    1.32  
    1.33   out:
    1.34      return ret;
    1.35 @@ -127,16 +130,16 @@ int xc_vcpu_getaffinity(int xc_handle,
    1.36  {
    1.37      DECLARE_DOMCTL;
    1.38      int ret = -1;
    1.39 +    uint8_t local[sizeof (cpumap)];
    1.40  
    1.41      domctl.cmd = XEN_DOMCTL_getvcpuaffinity;
    1.42      domctl.domain = (domid_t)domid;
    1.43      domctl.u.vcpuaffinity.vcpu = vcpu;
    1.44  
    1.45 -    set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap,
    1.46 -                         (uint8_t *)cpumap);
    1.47 -    domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(*cpumap) * 8;
    1.48 +    set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, local);
    1.49 +    domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap) * 8;
    1.50      
    1.51 -    if ( lock_pages(cpumap, sizeof(*cpumap)) != 0 )
    1.52 +    if ( lock_pages(local, sizeof(local)) != 0 )
    1.53      {
    1.54          PERROR("Could not lock memory for Xen hypercall");
    1.55          goto out;
    1.56 @@ -144,8 +147,8 @@ int xc_vcpu_getaffinity(int xc_handle,
    1.57  
    1.58      ret = do_domctl(xc_handle, &domctl);
    1.59  
    1.60 -    unlock_pages(cpumap, sizeof(*cpumap));
    1.61 -
    1.62 +    unlock_pages(local, sizeof (local));
    1.63 +    bitmap_byte_to_64(cpumap, local, sizeof (local));
    1.64   out:
    1.65      return ret;
    1.66  }
     2.1 --- a/tools/libxc/xc_private.c	Fri Jan 19 14:24:28 2007 +0000
     2.2 +++ b/tools/libxc/xc_private.c	Fri Jan 19 14:36:12 2007 +0000
     2.3 @@ -502,6 +502,37 @@ char *safe_strerror(int errcode)
     2.4      return errbuf;
     2.5  }
     2.6  
     2.7 +void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits)
     2.8 +{
     2.9 +    uint64_t l;
    2.10 +    int i, j, b;
    2.11 +
    2.12 +    for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) {
    2.13 +        l = lp[i];
    2.14 +        for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) {
    2.15 +            bp[b+j] = l;
    2.16 +            l >>= 8;
    2.17 +            nbits -= 8;
    2.18 +        }
    2.19 +    }
    2.20 +}
    2.21 +
    2.22 +void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits)
    2.23 +{
    2.24 +    uint64_t l;
    2.25 +    int i, j, b;
    2.26 +
    2.27 +    for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) {
    2.28 +        l = 0;
    2.29 +        for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) {
    2.30 +            l <<= 8;
    2.31 +            l |= bp[b+j];
    2.32 +            nbits -= 8;
    2.33 +        }
    2.34 +        lp[i] = l;
    2.35 +    }
    2.36 +}
    2.37 +
    2.38  /*
    2.39   * Local variables:
    2.40   * mode: C
     3.1 --- a/tools/libxc/xc_private.h	Fri Jan 19 14:24:28 2007 +0000
     3.2 +++ b/tools/libxc/xc_private.h	Fri Jan 19 14:36:12 2007 +0000
     3.3 @@ -155,4 +155,7 @@ void *map_domain_va_core(unsigned long d
     3.4  int xc_waitdomain_core(int xc_handle, int domain, int *status,
     3.5      int options, vcpu_guest_context_t *ctxt);
     3.6  
     3.7 +void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits);
     3.8 +void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits);
     3.9 +
    3.10  #endif /* __XC_PRIVATE_H__ */