[LIBXC] Convert between byte-based and 64-bit bitmap arrays. Use this
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Fri, 19 Jan 2007 14:36:12 +0000 (14:36 +0000)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Fri, 19 Jan 2007 14:36:12 +0000 (14:36 +0000)
for conversion of the domctl_cpumap.
Original patch from Jimi Xenidis <jimix@watson.ibm.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
tools/libxc/xc_domain.c
tools/libxc/xc_private.c
tools/libxc/xc_private.h

index 3c42aba1293d651a665b2689c446eed5ac447715..9a156ebba40b3bcb2ddfc9bb1c0f07433a9dee79 100644 (file)
@@ -96,16 +96,19 @@ int xc_vcpu_setaffinity(int xc_handle,
 {
     DECLARE_DOMCTL;
     int ret = -1;
+    uint8_t local[sizeof (cpumap)];
 
     domctl.cmd = XEN_DOMCTL_setvcpuaffinity;
     domctl.domain = (domid_t)domid;
     domctl.u.vcpuaffinity.vcpu    = vcpu;
 
-    set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap,
-                         (uint8_t *)&cpumap);
+    bitmap_64_to_byte(local, &cpumap, sizeof (cpumap));
+
+    set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, local);
+
     domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap) * 8;
     
-    if ( lock_pages(&cpumap, sizeof(cpumap)) != 0 )
+    if ( lock_pages(local, sizeof(local)) != 0 )
     {
         PERROR("Could not lock memory for Xen hypercall");
         goto out;
@@ -113,7 +116,7 @@ int xc_vcpu_setaffinity(int xc_handle,
 
     ret = do_domctl(xc_handle, &domctl);
 
-    unlock_pages(&cpumap, sizeof(cpumap));
+    unlock_pages(local, sizeof(local));
 
  out:
     return ret;
@@ -127,16 +130,16 @@ int xc_vcpu_getaffinity(int xc_handle,
 {
     DECLARE_DOMCTL;
     int ret = -1;
+    uint8_t local[sizeof (cpumap)];
 
     domctl.cmd = XEN_DOMCTL_getvcpuaffinity;
     domctl.domain = (domid_t)domid;
     domctl.u.vcpuaffinity.vcpu = vcpu;
 
-    set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap,
-                         (uint8_t *)cpumap);
-    domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(*cpumap) * 8;
+    set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, local);
+    domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap) * 8;
     
-    if ( lock_pages(cpumap, sizeof(*cpumap)) != 0 )
+    if ( lock_pages(local, sizeof(local)) != 0 )
     {
         PERROR("Could not lock memory for Xen hypercall");
         goto out;
@@ -144,8 +147,8 @@ int xc_vcpu_getaffinity(int xc_handle,
 
     ret = do_domctl(xc_handle, &domctl);
 
-    unlock_pages(cpumap, sizeof(*cpumap));
-
+    unlock_pages(local, sizeof (local));
+    bitmap_byte_to_64(cpumap, local, sizeof (local));
  out:
     return ret;
 }
index 82e190989ce647f3927d7db1435ed8be6946b9c4..db3715989a14b042dc073215acc21ec615184e8f 100644 (file)
@@ -502,6 +502,37 @@ char *safe_strerror(int errcode)
     return errbuf;
 }
 
+void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits)
+{
+    uint64_t l;
+    int i, j, b;
+
+    for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) {
+        l = lp[i];
+        for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) {
+            bp[b+j] = l;
+            l >>= 8;
+            nbits -= 8;
+        }
+    }
+}
+
+void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits)
+{
+    uint64_t l;
+    int i, j, b;
+
+    for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) {
+        l = 0;
+        for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) {
+            l <<= 8;
+            l |= bp[b+j];
+            nbits -= 8;
+        }
+        lp[i] = l;
+    }
+}
+
 /*
  * Local variables:
  * mode: C
index 6dfbdead7af39ddae8d20c6ef145d43dd9f10a4f..7705063326badd3437fd9bf18184ac8f752e5eb1 100644 (file)
@@ -155,4 +155,7 @@ void *map_domain_va_core(unsigned long domfd, int cpu, void *guest_va,
 int xc_waitdomain_core(int xc_handle, int domain, int *status,
     int options, vcpu_guest_context_t *ctxt);
 
+void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits);
+void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits);
+
 #endif /* __XC_PRIVATE_H__ */