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

[Xen-changelog] [xen-unstable] tools/libxc: introduce xc_memalign in xc_{minios, linux, solaris, netbsd}.c



# HG changeset patch
# User Shriram Rajagopalan <rshriram@xxxxxxxxx>
# Date 1322753702 0
# Node ID 8cc7470020f72de82968eb9b4326fcf062895c1a
# Parent  03279085a0f66856a4a495cdb525254dbc18ad54
tools/libxc: introduce xc_memalign in xc_{minios,linux,solaris,netbsd}.c

Move (page aligned) buffer allocations in {os}_privcmd_alloc_hypercall_buffer
into a global function xc_memalign. This API is also used by Remus
compression code to allocate compression caches that need to be page aligned.

Signed-off-by: Shriram Rajagopalan <rshriram@xxxxxxxxx>
Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Acked-by: Brendan Cully <brendan@xxxxxxxxx>
Committed-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---


diff -r 03279085a0f6 -r 8cc7470020f7 tools/libxc/xc_linux.c
--- a/tools/libxc/xc_linux.c    Thu Dec 01 15:24:19 2011 +0000
+++ b/tools/libxc/xc_linux.c    Thu Dec 01 15:35:02 2011 +0000
@@ -55,6 +55,18 @@
     errno = saved_errno;
 }
 
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
+{
+    int ret;
+    void *ptr;
+
+    ret = posix_memalign(&ptr, alignment, size);
+    if (ret != 0 || !ptr)
+        return NULL;
+
+    return ptr;
+}
+
 /*
  * Local variables:
  * mode: C
diff -r 03279085a0f6 -r 8cc7470020f7 tools/libxc/xc_linux_osdep.c
--- a/tools/libxc/xc_linux_osdep.c      Thu Dec 01 15:24:19 2011 +0000
+++ b/tools/libxc/xc_linux_osdep.c      Thu Dec 01 15:35:02 2011 +0000
@@ -91,10 +91,9 @@
 {
     size_t size = npages * XC_PAGE_SIZE;
     void *p;
-    int ret;
 
-    ret = posix_memalign(&p, XC_PAGE_SIZE, size);
-    if (ret != 0 || !p)
+    p = xc_memalign(xch, XC_PAGE_SIZE, size);
+    if (!p)
         return NULL;
 
     if ( mlock(p, size) < 0 )
diff -r 03279085a0f6 -r 8cc7470020f7 tools/libxc/xc_minios.c
--- a/tools/libxc/xc_minios.c   Thu Dec 01 15:24:19 2011 +0000
+++ b/tools/libxc/xc_minios.c   Thu Dec 01 15:35:02 2011 +0000
@@ -73,7 +73,7 @@
 
 static void *minios_privcmd_alloc_hypercall_buffer(xc_interface *xch, 
xc_osdep_handle h, int npages)
 {
-    return memalign(PAGE_SIZE, npages * PAGE_SIZE);
+    return xc_memalign(xch, PAGE_SIZE, npages * PAGE_SIZE);
 }
 
 static void minios_privcmd_free_hypercall_buffer(xc_interface *xch, 
xc_osdep_handle h, void *ptr, int npages)
@@ -437,6 +437,11 @@
         fsync(fd);
 }
 
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
+{
+    return memalign(alignment, size);
+}
+
 static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg)
 {
     int fd = alloc_fd(FTYPE_GNTMAP);
diff -r 03279085a0f6 -r 8cc7470020f7 tools/libxc/xc_netbsd.c
--- a/tools/libxc/xc_netbsd.c   Thu Dec 01 15:24:19 2011 +0000
+++ b/tools/libxc/xc_netbsd.c   Thu Dec 01 15:35:02 2011 +0000
@@ -71,8 +71,9 @@
 static void *netbsd_privcmd_alloc_hypercall_buffer(xc_interface *xch, 
xc_osdep_handle h, int npages)
 {
     size_t size = npages * XC_PAGE_SIZE;
-    void *p = valloc(size);
+    void *p;
 
+    p = xc_memalign(xch, XC_PAGE_SIZE, size);
     if (!p)
         return NULL;
 
@@ -378,6 +379,11 @@
     errno = saved_errno;
 }
 
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
+{
+    return valloc(size);
+}
+
 static struct xc_osdep_ops *netbsd_osdep_init(xc_interface *xch, enum 
xc_osdep_type type)
 {
     switch ( type )
diff -r 03279085a0f6 -r 8cc7470020f7 tools/libxc/xc_solaris.c
--- a/tools/libxc/xc_solaris.c  Thu Dec 01 15:24:19 2011 +0000
+++ b/tools/libxc/xc_solaris.c  Thu Dec 01 15:35:02 2011 +0000
@@ -70,7 +70,7 @@
 
 static void *solaris_privcmd_alloc_hypercall_buffer(xc_interface *xch, 
xc_osdep_handle h, int npages)
 {
-    return memalign(XC_PAGE_SIZE, npages * XC_PAGE_SIZE);
+    return xc_memalign(xch, XC_PAGE_SIZE, npages * XC_PAGE_SIZE);
 }
 
 static void solaris_privcmd_free_hypercall_buffer(xc_interface *xch, 
xc_osdep_handle h, void *ptr, int npages)
@@ -314,6 +314,11 @@
     // TODO: Implement for Solaris!
 }
 
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
+{
+    return memalign(alignment, size);
+}
+
 static struct xc_osdep_ops *solaris_osdep_init(xc_interface *xch, enum 
xc_osdep_type type)
 {
     switch ( type )
diff -r 03279085a0f6 -r 8cc7470020f7 tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h     Thu Dec 01 15:24:19 2011 +0000
+++ b/tools/libxc/xenctrl.h     Thu Dec 01 15:35:02 2011 +0000
@@ -1156,6 +1156,8 @@
                       uint64_t *time,
                       xc_hypercall_buffer_t *data);
 
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size);
+
 /**
  * Memory maps a range within one domain to a local address range.  Mappings
  * should be unmapped with munmap and should follow the same rules as mmap

_______________________________________________
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®.