[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] [LIBXC] Convert between byte-based and 64-bit bitmap arrays. Use this



# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Date 1169217372 0
# Node ID cd532c9351fc746ac368bbd07180cfffc95ad9f0
# Parent  fa5bc90a3cb7ef206e29cb28c0c4d1d762eb9362
[LIBXC] Convert between byte-based and 64-bit bitmap arrays. Use this
for conversion of the domctl_cpumap.
Original patch from Jimi Xenidis <jimix@xxxxxxxxxxxxxx>
Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>
---
 tools/libxc/xc_domain.c  |   23 +++++++++++++----------
 tools/libxc/xc_private.c |   31 +++++++++++++++++++++++++++++++
 tools/libxc/xc_private.h |    3 +++
 3 files changed, 47 insertions(+), 10 deletions(-)

diff -r fa5bc90a3cb7 -r cd532c9351fc tools/libxc/xc_domain.c
--- a/tools/libxc/xc_domain.c   Fri Jan 19 14:24:28 2007 +0000
+++ b/tools/libxc/xc_domain.c   Fri Jan 19 14:36:12 2007 +0000
@@ -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;
 }
diff -r fa5bc90a3cb7 -r cd532c9351fc tools/libxc/xc_private.c
--- a/tools/libxc/xc_private.c  Fri Jan 19 14:24:28 2007 +0000
+++ b/tools/libxc/xc_private.c  Fri Jan 19 14:36:12 2007 +0000
@@ -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
diff -r fa5bc90a3cb7 -r cd532c9351fc tools/libxc/xc_private.h
--- a/tools/libxc/xc_private.h  Fri Jan 19 14:24:28 2007 +0000
+++ b/tools/libxc/xc_private.h  Fri Jan 19 14:36:12 2007 +0000
@@ -155,4 +155,7 @@ int xc_waitdomain_core(int xc_handle, in
 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__ */

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.