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@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>
This commit is contained in:
Shriram Rajagopalan committed 2011-12-01 15:35:02 +00:00
1 parent 3a313ac80e
commit de869779a0
6 files changed
+35 -6

No files matched your search

+12
View 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
+2 -3
View 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 )
+6 -1
View 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);
+7 -1
View 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 )
+6 -1
View 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 )
+2
View 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
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.