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

[Xen-changelog] [xen-unstable] libxc: osdep: convert xc_map_foreign_{batch, bulk}



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1291369007 0
# Node ID c64fd0d604b0134757116f841fe9c08a0a5dfd58
# Parent  fcca454f2e4394f2629879e6ff5fbe852a69587e
libxc: osdep: convert xc_map_foreign_{batch,bulk}

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Signed-off-by: Ian Jackson <ian.jackson.citrix.com>
---
 tools/libxc/Makefile            |    1 +
 tools/libxc/xc_foreign_memory.c |   35 +++++++++++++++++++++++++++++++++++
 tools/libxc/xc_linux.c          |   39 +++++++++++++++++++++++----------------
 tools/libxc/xc_minios.c         |   13 +++++++++----
 tools/libxc/xc_misc.c           |    9 +++------
 tools/libxc/xc_netbsd.c         |   13 +++++++++----
 tools/libxc/xc_solaris.c        |   15 ++++++++++-----
 tools/libxc/xenctrlosdep.h      |   10 ++++++++++
 8 files changed, 100 insertions(+), 35 deletions(-)

diff -r fcca454f2e43 -r c64fd0d604b0 tools/libxc/Makefile
--- a/tools/libxc/Makefile      Fri Dec 03 09:36:46 2010 +0000
+++ b/tools/libxc/Makefile      Fri Dec 03 09:36:47 2010 +0000
@@ -30,6 +30,7 @@ CTRL_SRCS-y       += xc_mem_paging.c
 CTRL_SRCS-y       += xc_mem_paging.c
 CTRL_SRCS-y       += xc_memshr.c
 CTRL_SRCS-y       += xc_hcall_buf.c
+CTRL_SRCS-y       += xc_foreign_memory.c
 CTRL_SRCS-y       += xtl_core.c
 CTRL_SRCS-y       += xtl_logger_stdio.c
 CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
diff -r fcca454f2e43 -r c64fd0d604b0 tools/libxc/xc_foreign_memory.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxc/xc_foreign_memory.c   Fri Dec 03 09:36:47 2010 +0000
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * xc_foreign_memory.c
+ *
+ * Functions for mapping foreign domain's memory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+ */
+
+#include "xc_private.h"
+
+void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
+                           xen_pfn_t *arr, int num )
+{
+    return xch->ops->u.privcmd.map_foreign_batch(xch, xch->ops_handle,
+                                                 dom, prot, arr, num);
+}
+
+void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
+                          const xen_pfn_t *arr, int *err, unsigned int num)
+{
+    return xch->ops->u.privcmd.map_foreign_bulk(xch, xch->ops_handle,
+                                                dom, prot, arr, err, num);
+}
diff -r fcca454f2e43 -r c64fd0d604b0 tools/libxc/xc_linux.c
--- a/tools/libxc/xc_linux.c    Fri Dec 03 09:36:46 2010 +0000
+++ b/tools/libxc/xc_linux.c    Fri Dec 03 09:36:47 2010 +0000
@@ -81,7 +81,7 @@ static int linux_privcmd_hypercall(xc_in
     return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
 }
 
-static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom,
+static int xc_map_foreign_batch_single(int fd, uint32_t dom,
                                        xen_pfn_t *mfn, unsigned long addr)
 {
     privcmd_mmapbatch_t ioctlx;
@@ -96,21 +96,23 @@ static int xc_map_foreign_batch_single(x
     {
         *mfn ^= XEN_DOMCTL_PFINFO_PAGEDTAB;
         usleep(100);
-        rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
+        rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
     }
     while ( (rc < 0) && (errno == ENOENT) );
 
     return rc;
 }
 
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
-                           xen_pfn_t *arr, int num)
-{
+static void *linux_privcmd_map_foreign_batch(xc_interface *xch, 
xc_osdep_handle h,
+                                             uint32_t dom, int prot,
+                                             xen_pfn_t *arr, int num)
+{
+    int fd = (int)h;
     privcmd_mmapbatch_t ioctlx;
     void *addr;
     int rc;
 
-    addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, xch->fd, 0);
+    addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, fd, 0);
     if ( addr == MAP_FAILED )
     {
         PERROR("xc_map_foreign_batch: mmap failed");
@@ -122,7 +124,7 @@ void *xc_map_foreign_batch(xc_interface 
     ioctlx.addr = (unsigned long)addr;
     ioctlx.arr = arr;
 
-    rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
+    rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
     if ( (rc < 0) && (errno == ENOENT) )
     {
         int i;
@@ -133,7 +135,7 @@ void *xc_map_foreign_batch(xc_interface 
                  XEN_DOMCTL_PFINFO_PAGEDTAB )
             {
                 unsigned long paged_addr = (unsigned long)addr + (i << 
PAGE_SHIFT);
-                rc = xc_map_foreign_batch_single(xch, dom, &arr[i],
+                rc = xc_map_foreign_batch_single(fd, dom, &arr[i],
                                                  paged_addr);
                 if ( rc < 0 )
                     goto out;
@@ -154,16 +156,18 @@ void *xc_map_foreign_batch(xc_interface 
     return addr;
 }
 
-void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
-                          const xen_pfn_t *arr, int *err, unsigned int num)
-{
+static void *linux_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle 
h,
+                                            uint32_t dom, int prot,
+                                            const xen_pfn_t *arr, int *err, 
unsigned int num)
+{
+    int fd = (int)h;
     privcmd_mmapbatch_v2_t ioctlx;
     void *addr;
     unsigned int i;
     int rc;
 
     addr = mmap(NULL, (unsigned long)num << PAGE_SHIFT, prot, MAP_SHARED,
-                xch->fd, 0);
+                fd, 0);
     if ( addr == MAP_FAILED )
     {
         PERROR("xc_map_foreign_batch: mmap failed");
@@ -176,7 +180,7 @@ void *xc_map_foreign_bulk(xc_interface *
     ioctlx.arr = arr;
     ioctlx.err = err;
 
-    rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
+    rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
 
     if ( rc < 0 && errno == ENOENT )
     {
@@ -192,7 +196,7 @@ void *xc_map_foreign_bulk(xc_interface *
             ioctlx.err = err + i;
             do {
                 usleep(100);
-                rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
+                rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
             } while ( rc < 0 && err[i] == -ENOENT );
         }
     }
@@ -216,7 +220,7 @@ void *xc_map_foreign_bulk(xc_interface *
             ioctlx.addr = (unsigned long)addr;
             ioctlx.arr = pfn;
 
-            rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
+            rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
 
             rc = rc < 0 ? -errno : 0;
 
@@ -236,7 +240,7 @@ void *xc_map_foreign_bulk(xc_interface *
                         err[i] = rc ?: -EINVAL;
                         continue;
                     }
-                    rc = xc_map_foreign_batch_single(xch, dom, pfn + i,
+                    rc = xc_map_foreign_batch_single(fd, dom, pfn + i,
                         (unsigned long)addr + ((unsigned long)i<<PAGE_SHIFT));
                     if ( rc < 0 )
                     {
@@ -328,6 +332,9 @@ static struct xc_osdep_ops linux_privcmd
 
     .u.privcmd = {
         .hypercall = &linux_privcmd_hypercall,
+
+        .map_foreign_batch = &linux_privcmd_map_foreign_batch,
+        .map_foreign_bulk = &linux_privcmd_map_foreign_bulk,
     },
 };
 
diff -r fcca454f2e43 -r c64fd0d604b0 tools/libxc/xc_minios.c
--- a/tools/libxc/xc_minios.c   Fri Dec 03 09:36:46 2010 +0000
+++ b/tools/libxc/xc_minios.c   Fri Dec 03 09:36:47 2010 +0000
@@ -93,8 +93,9 @@ static int minios_privcmd_hypercall(xc_i
     return call.result;
 }
 
-void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
-                          const xen_pfn_t *arr, int *err, unsigned int num)
+static void *minios_privcmd_map_foreign_bulk(xc_interface *xch, 
xc_osdep_handle h,
+                                             uint32_t dom, int prot,
+                                             const xen_pfn_t *arr, int *err, 
unsigned int num)
 {
     unsigned long pt_prot = 0;
 #ifdef __ia64__
@@ -108,8 +109,9 @@ void *xc_map_foreign_bulk(xc_interface *
     return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);    
 }
 
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
-                           xen_pfn_t *arr, int num)
+static void *minios_privcmd_map_foreign_batch(xc_interface *xch,  
xc_osdep_handle h,
+                                              uint32_t dom, int prot,
+                                              xen_pfn_t *arr, int num)
 {
     unsigned long pt_prot = 0;
     int err[num];
@@ -185,6 +187,9 @@ static struct xc_osdep_ops minios_privcm
 
     .u.privcmd = {
         .hypercall = &minios_privcmd_hypercall,
+
+        .map_foreign_batch = &minios_privcmd_map_foreign_batch,
+        .map_foreign_bulk = &minios_privcmd_map_foreign_bulk,
     },
 };
 
diff -r fcca454f2e43 -r c64fd0d604b0 tools/libxc/xc_misc.c
--- a/tools/libxc/xc_misc.c     Fri Dec 03 09:36:46 2010 +0000
+++ b/tools/libxc/xc_misc.c     Fri Dec 03 09:36:47 2010 +0000
@@ -513,12 +513,9 @@ int xc_hvm_set_mem_type(
 
 
 /* stub for all not yet converted OSes */
-void *
-#ifdef __GNUC__
-__attribute__((__weak__))
-#endif
-xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
-                    const xen_pfn_t *arr, int *err, unsigned int num)
+void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h,
+                                 uint32_t dom, int prot,
+                                 const xen_pfn_t *arr, int *err, unsigned int 
num)
 {
     xen_pfn_t *pfn;
     unsigned int i;
diff -r fcca454f2e43 -r c64fd0d604b0 tools/libxc/xc_netbsd.c
--- a/tools/libxc/xc_netbsd.c   Fri Dec 03 09:36:46 2010 +0000
+++ b/tools/libxc/xc_netbsd.c   Fri Dec 03 09:36:47 2010 +0000
@@ -79,9 +79,11 @@ static int netbsd_privcmd_hypercall(xc_i
         return hypercall->retval;
 }
 
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
-                           xen_pfn_t *arr, int num)
-{
+static void *netbsd_privcmd_map_foreign_batch(xc_interface *xch, 
xc_osdep_handle h,
+                                              uint32_t dom, int prot,
+                                              xen_pfn_t *arr, int num)
+{
+    int fd = (int)h;
     privcmd_mmapbatch_t ioctlx;
     void *addr;
     addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_ANON | MAP_SHARED, -1, 0);
@@ -94,7 +96,7 @@ void *xc_map_foreign_batch(xc_interface 
     ioctlx.dom=dom;
     ioctlx.addr=(unsigned long)addr;
     ioctlx.arr=arr;
-    if ( ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
+    if ( ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
     {
         int saved_errno = errno;
         PERROR("xc_map_foreign_batch: ioctl failed");
@@ -178,6 +180,9 @@ static struct xc_osdep_ops netbsd_privcm
 
     .u.privcmd = {
         .hypercall = &netbsd_privcmd_hypercall;
+
+        .map_foreign_batch = &netbsd_privcmd_map_foreign_batch,
+        .map_foreign_bulk = &xc_map_foreign_bulk_compat,
     },
 };
 
diff -r fcca454f2e43 -r c64fd0d604b0 tools/libxc/xc_solaris.c
--- a/tools/libxc/xc_solaris.c  Fri Dec 03 09:36:46 2010 +0000
+++ b/tools/libxc/xc_solaris.c  Fri Dec 03 09:36:47 2010 +0000
@@ -74,12 +74,14 @@ static int solaris_privcmd_hypercall(xc_
     return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
 }
 
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
-                           xen_pfn_t *arr, int num)
-{
+static void *solaris_privcmd_map_foreign_batch(xc_interface *xch, 
xc_osdep_handle h,
+                                               uint32_t dom, int prot,
+                                               xen_pfn_t *arr, int num)
+{
+    int fd = (int)h;
     privcmd_mmapbatch_t ioctlx;
     void *addr;
-    addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xch->fd, 0);
+    addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, fd, 0);
     if ( addr == MAP_FAILED )
         return NULL;
 
@@ -87,7 +89,7 @@ void *xc_map_foreign_batch(xc_interface 
     ioctlx.dom=dom;
     ioctlx.addr=(unsigned long)addr;
     ioctlx.arr=arr;
-    if ( ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
+    if ( ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
     {
         int saved_errno = errno;
         PERROR("XXXXXXXX");
@@ -168,6 +170,9 @@ static struct xc_osdep_ops solaris_privc
 
     .u.privcmd = {
         .hypercall = &solaris_privcmd_hypercall;
+
+        .map_foreign_batch = &solaris_privcmd_map_foreign_batch,
+        .map_foreign_bulk = &xc_map_foreign_bulk_compat,
     },
 };
 
diff -r fcca454f2e43 -r c64fd0d604b0 tools/libxc/xenctrlosdep.h
--- a/tools/libxc/xenctrlosdep.h        Fri Dec 03 09:36:46 2010 +0000
+++ b/tools/libxc/xenctrlosdep.h        Fri Dec 03 09:36:47 2010 +0000
@@ -63,6 +63,11 @@ struct xc_osdep_ops
     union {
         struct {
             int (*hypercall)(xc_interface *xch, xc_osdep_handle h, 
privcmd_hypercall_t *hypercall);
+
+            void *(*map_foreign_batch)(xc_interface *xch, xc_osdep_handle h, 
uint32_t dom, int prot,
+                                       xen_pfn_t *arr, int num);
+            void *(*map_foreign_bulk)(xc_interface *xch, xc_osdep_handle h, 
uint32_t dom, int prot,
+                                      const xen_pfn_t *arr, int *err, unsigned 
int num);
         } privcmd;
     } u;
 };
@@ -83,6 +88,11 @@ typedef struct xc_osdep_info xc_osdep_in
 /* All backends, including the builtin backend, must supply this structure. */
 extern xc_osdep_info_t xc_osdep_info;
 
+/* Stub for not yet converted OSes */
+void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h,
+                                 uint32_t dom, int prot,
+                                 const xen_pfn_t *arr, int *err, unsigned int 
num);
+
 #endif
 
 /*

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