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

[Xen-changelog] [xen-unstable] libxc: Use a single mmap interface to Linux



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1248083886 -3600
# Node ID 6d41644623de6d8f1bab853031a72e23f53d94b2
# Parent  e34975d7d8f1ed63213486614c13c6b668989894
libxc: Use a single mmap interface to Linux

Modify xc_map_foreign_range and xc_map_foreign_ranges to call
mmap_map_foreign_batch. This eliminates the need for multiple privcmd
mmap ioctls. Now only IOCTL_PRIVCMD_MMAPBATCH is required.

Signed-off-by: Patrick Colp <Patrick.Colp@xxxxxxxxxx>
---
 tools/libxc/xc_linux.c |   77 +++++++++++++++----------------------------------
 1 files changed, 24 insertions(+), 53 deletions(-)

diff -r e34975d7d8f1 -r 6d41644623de tools/libxc/xc_linux.c
--- a/tools/libxc/xc_linux.c    Mon Jul 20 10:12:38 2009 +0100
+++ b/tools/libxc/xc_linux.c    Mon Jul 20 10:58:06 2009 +0100
@@ -92,67 +92,38 @@ void *xc_map_foreign_range(int xc_handle
                            int size, int prot,
                            unsigned long mfn)
 {
-    privcmd_mmap_t ioctlx;
-    privcmd_mmap_entry_t entry;
-    void *addr;
-    addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
-    if ( addr == MAP_FAILED ) {
-        perror("xc_map_foreign_range: mmap failed");
-        return NULL;
-    }
-
-    ioctlx.num=1;
-    ioctlx.dom=dom;
-    ioctlx.entry=&entry;
-    entry.va=(unsigned long) addr;
-    entry.mfn=mfn;
-    entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT;
-    if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 )
-    {
-        int saved_errno = errno;
-        perror("xc_map_foreign_range: ioctl failed");
-        (void)munmap(addr, size);
-        errno = saved_errno;
-        return NULL;
-    }
-    return addr;
+    xen_pfn_t *arr;
+    int num;
+    int i;
+
+    num = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
+    arr = calloc(num, sizeof(xen_pfn_t));
+
+    for ( i = 0; i < num; i++ )
+        arr[i] = mfn + i;
+
+    return xc_map_foreign_batch(xc_handle, dom, prot, arr, num);
 }
 
 void *xc_map_foreign_ranges(int xc_handle, uint32_t dom,
                             size_t size, int prot, size_t chunksize,
                             privcmd_mmap_entry_t entries[], int nentries)
 {
-    privcmd_mmap_t ioctlx;
-    int i, rc;
-    void *addr;
-
-    addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
-    if ( addr == MAP_FAILED )
-        goto mmap_failed;
+    xen_pfn_t *arr;
+    int num_per_entry;
+    int num;
+    int i;
+    int j;
+
+    num_per_entry = chunksize >> PAGE_SHIFT;
+    num = num_per_entry * nentries;
+    arr = calloc(num, sizeof(xen_pfn_t));
 
     for ( i = 0; i < nentries; i++ )
-    {
-        entries[i].va = (unsigned long)addr + (i * chunksize);
-        entries[i].npages = chunksize >> PAGE_SHIFT;
-    }
-
-    ioctlx.num   = nentries;
-    ioctlx.dom   = dom;
-    ioctlx.entry = entries;
-
-    rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx);
-    if ( rc )
-        goto ioctl_failed;
-
-    return addr;
-
-ioctl_failed:
-    rc = munmap(addr, size);
-    if ( rc == -1 )
-        ERROR("%s: error in error path\n", __FUNCTION__);
-
-mmap_failed:
-    return NULL;
+        for ( j = 0; j < num_per_entry; j++ )
+            arr[i * num_per_entry + j] = entries[i].mfn + j;
+
+    return xc_map_foreign_batch(xc_handle, dom, prot, arr, num);
 }
 
 static int do_privcmd(int xc_handle, unsigned int cmd, unsigned long data)

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