tools/libxc: introduce xc_memalign in xc_{minios,linux,solaris,netbsd}.c
authorShriram Rajagopalan <rshriram@cs.ubc.ca>
Thu, 1 Dec 2011 15:35:02 +0000 (15:35 +0000)
committerShriram Rajagopalan <rshriram@cs.ubc.ca>
Thu, 1 Dec 2011 15:35:02 +0000 (15:35 +0000)
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@cs.ubc.ca>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Brendan Cully <brendan@cs.ubc.ca>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxc/xc_linux.c
tools/libxc/xc_linux_osdep.c
tools/libxc/xc_minios.c
tools/libxc/xc_netbsd.c
tools/libxc/xc_solaris.c
tools/libxc/xenctrl.h

index 9acf27573e0cfe0f486ada6f84fe761a69173a89..5504df6cba7cf23f6597dfa286cb7cc69db3051f 100644 (file)
@@ -55,6 +55,18 @@ void discard_file_cache(xc_interface *xch, int fd, int flush)
     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
index 04059b8126a4d487de8ea64aae452403f681b97d..0da20091db525cfa4b9a4e3ac3afd85f80038374 100644 (file)
@@ -91,10 +91,9 @@ static void *linux_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_ha
 {
     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 )
index ff9c0d8d192b5204579bd293f4bb3f54482e7a59..8bbfd186d5ce1c88d02b59a065f59a1ae6adc9aa 100644 (file)
@@ -73,7 +73,7 @@ void minios_interface_close_fd(int fd)
 
 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 @@ void discard_file_cache(xc_interface *xch, int fd, int flush)
         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);
index 0f49e30ad1177378f7ba14e9ce9e5d2108ad7af2..9782a3423aea7abd80ed3ae8dde767dbce7752ad 100644 (file)
@@ -71,8 +71,9 @@ static int netbsd_privcmd_close(xc_interface *xch, xc_osdep_handle h)
 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 @@ void discard_file_cache(xc_interface *xch, int fd, int flush)
     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 )
index eba4358c9dba45a3a43bc472dc83e3e08b764a4f..497c923eade0068bf6f9966627434a9c65bef536 100644 (file)
@@ -70,7 +70,7 @@ static int solaris_privcmd_close(xc_interface *xch, xc_osdep_handle h)
 
 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 @@ void discard_file_cache(xc_interface *xch, int fd, int flush)
     // 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 )
index 9e2a4373f4e429718ec15da092753aff372684c6..ee482f28ab677d514d331898d5a4364b8401aeb8 100644 (file)
@@ -1156,6 +1156,8 @@ int xc_lockprof_query(xc_interface *xch,
                       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