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

[Xen-devel] [PATCH XEN v2 07/15] tools/libxc: Remove osdep indirection for xc_gnt{shr, tab}



The alternative backend (a xen-api/xapi shim) is no longer around and
so this stuff is now just baggage which is getting in the way of
refactoring libxenctrl.

Nested virt probably suffices for this use case now.

It is now necessary to provide explicit versions of things for
platforms which do not implement this functionality, since the osdep
dispatcher cannot fulfil this need any more. These are provided by
appropriate xc_nognt???.c files which are compiled and linked on the
appropriate platforms. In them open and close return failure and
everything else aborts, since if open fails they should never be
called.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
 tools/libxc/Makefile               |  10 ++--
 tools/libxc/include/xenctrl.h      |   4 +-
 tools/libxc/include/xenctrlosdep.h |  23 -------
 tools/libxc/xc_gnttab.c            |  57 ++++--------------
 tools/libxc/xc_linux_osdep.c       | 119 +++++++++++++++----------------------
 tools/libxc/xc_minios.c            |  51 ++++++----------
 tools/libxc/xc_nogntshr.c          |  44 ++++++++++++++
 tools/libxc/xc_nognttab.c          |  48 +++++++++++++++
 tools/libxc/xc_private.c           |  83 +++++++++++++++++++++-----
 tools/libxc/xc_private.h           |  24 ++++++++
 10 files changed, 270 insertions(+), 193 deletions(-)
 create mode 100644 tools/libxc/xc_nogntshr.c
 create mode 100644 tools/libxc/xc_nognttab.c

diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index baf054f..19ad0df 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -42,11 +42,11 @@ CTRL_SRCS-y       += xc_resource.c
 CTRL_SRCS-$(CONFIG_X86) += xc_psr.c
 CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
 CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c xc_linux_osdep.c
-CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c
-CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
-CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c
-CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c
-CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c
+CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c xc_nognttab.c 
xc_nogntshr.c
+CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c xc_nognttab.c xc_nogntshr.c
+CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c xc_nognttab.c xc_nogntshr.c
+CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c xc_nognttab.c xc_nogntshr.c
+CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c xc_nogntshr.c
 CTRL_SRCS-y       += xc_evtchn_compat.c
 
 GUEST_SRCS-y :=
diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index d7ca161..e60aa34 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -118,8 +118,8 @@
  */
 
 typedef struct xc_interface_core xc_interface;
-typedef struct xc_interface_core xc_gnttab;
-typedef struct xc_interface_core xc_gntshr;
+typedef struct xengntdev_handle xc_gnttab;
+typedef struct xengntdev_handle xc_gntshr;
 
 enum xc_error_code {
   XC_ERROR_NONE = 0,
diff --git a/tools/libxc/include/xenctrlosdep.h 
b/tools/libxc/include/xenctrlosdep.h
index a8b27ae..bad10f6 100644
--- a/tools/libxc/include/xenctrlosdep.h
+++ b/tools/libxc/include/xenctrlosdep.h
@@ -52,8 +52,6 @@
 
 enum xc_osdep_type {
     XC_OSDEP_PRIVCMD,
-    XC_OSDEP_GNTTAB,
-    XC_OSDEP_GNTSHR,
 };
 
 /* Opaque handle internal to the backend */
@@ -89,27 +87,6 @@ struct xc_osdep_ops
                                         size_t chunksize, privcmd_mmap_entry_t 
entries[],
                                         int nentries);
         } privcmd;
-        struct {
-#define XC_GRANT_MAP_SINGLE_DOMAIN 0x1
-            void *(*grant_map)(xc_gnttab *xcg, xc_osdep_handle h,
-                               uint32_t count, int flags, int prot,
-                               uint32_t *domids, uint32_t *refs,
-                               uint32_t notify_offset,
-                               evtchn_port_t notify_port);
-            int (*munmap)(xc_gnttab *xcg, xc_osdep_handle h,
-                          void *start_address,
-                          uint32_t count);
-            int (*set_max_grants)(xc_gnttab *xcg, xc_osdep_handle h, uint32_t 
count);
-        } gnttab;
-        struct {
-            void *(*share_pages)(xc_gntshr *xcg, xc_osdep_handle h,
-                                 uint32_t domid, int count,
-                                 uint32_t *refs, int writable,
-                                 uint32_t notify_offset,
-                                 evtchn_port_t notify_port);
-            int (*munmap)(xc_gntshr *xcg, xc_osdep_handle h,
-                          void *start_address, uint32_t count);
-        } gntshr;
     } u;
 };
 typedef struct xc_osdep_ops xc_osdep_ops;
diff --git a/tools/libxc/xc_gnttab.c b/tools/libxc/xc_gnttab.c
index 4076e47..53cd670 100644
--- a/tools/libxc/xc_gnttab.c
+++ b/tools/libxc/xc_gnttab.c
@@ -144,68 +144,48 @@ grant_entry_v2_t *xc_gnttab_map_table_v2(xc_interface 
*xch, int domid,
     return _gnttab_map_table(xch, domid, gnt_num);
 }
 
-void *xc_gnttab_map_grant_ref(xc_gnttab *xcg,
+void *xc_gnttab_map_grant_ref(xc_gnttab *xgt,
                               uint32_t domid,
                               uint32_t ref,
                               int prot)
 {
-       return xcg->ops->u.gnttab.grant_map(xcg, xcg->ops_handle, 1, 0, prot,
-                                           &domid, &ref, -1, -1);
+    return osdep_gnttab_grant_map(xgt, 1, 0, prot, &domid, &ref, -1, -1);
 }
 
-void *xc_gnttab_map_grant_refs(xc_gnttab *xcg,
+void *xc_gnttab_map_grant_refs(xc_gnttab *xgt,
                                uint32_t count,
                                uint32_t *domids,
                                uint32_t *refs,
                                int prot)
 {
-       return xcg->ops->u.gnttab.grant_map(xcg, xcg->ops_handle, count, 0,
-                                           prot, domids, refs, -1, -1);
+    return osdep_gnttab_grant_map(xgt, count, 0, prot, domids, refs, -1, -1);
 }
 
-void *xc_gnttab_map_domain_grant_refs(xc_gnttab *xcg,
+void *xc_gnttab_map_domain_grant_refs(xc_gnttab *xgt,
                                       uint32_t count,
                                       uint32_t domid,
                                       uint32_t *refs,
                                       int prot)
 {
-       return xcg->ops->u.gnttab.grant_map(xcg, xcg->ops_handle, count,
-                                           XC_GRANT_MAP_SINGLE_DOMAIN,
-                                           prot, &domid, refs, -1, -1);
+    return osdep_gnttab_grant_map(xgt, count, XC_GRANT_MAP_SINGLE_DOMAIN,
+                                  prot, &domid, refs, -1, -1);
 }
 
-void *xc_gnttab_map_grant_ref_notify(xc_gnttab *xcg,
+void *xc_gnttab_map_grant_ref_notify(xc_gnttab *xgt,
                                      uint32_t domid,
                                      uint32_t ref,
                                      int prot,
                                      uint32_t notify_offset,
                                      evtchn_port_t notify_port)
 {
-       return xcg->ops->u.gnttab.grant_map(xcg, xcg->ops_handle, 1, 0, prot,
-                                     &domid, &ref, notify_offset, notify_port);
-}
-
-
-int xc_gnttab_munmap(xc_gnttab *xcg,
-                     void *start_address,
-                     uint32_t count)
-{
-       return xcg->ops->u.gnttab.munmap(xcg, xcg->ops_handle,
-                                        start_address, count);
-}
-
-int xc_gnttab_set_max_grants(xc_gnttab *xcg, uint32_t count)
-{
-       if (!xcg->ops->u.gnttab.set_max_grants)
-               return 0;
-       return xcg->ops->u.gnttab.set_max_grants(xcg, xcg->ops_handle, count);
+    return osdep_gnttab_grant_map(xgt, 1, 0, prot,  &domid, &ref,
+                                  notify_offset, notify_port);
 }
 
 void *xc_gntshr_share_pages(xc_gntshr *xcg, uint32_t domid,
                             int count, uint32_t *refs, int writable)
 {
-       return xcg->ops->u.gntshr.share_pages(xcg, xcg->ops_handle, domid,
-                                             count, refs, writable, -1, -1);
+    return osdep_gntshr_share_pages(xcg, domid, count, refs, writable, -1, -1);
 }
 
 void *xc_gntshr_share_page_notify(xc_gntshr *xcg, uint32_t domid,
@@ -213,22 +193,11 @@ void *xc_gntshr_share_page_notify(xc_gntshr *xcg, 
uint32_t domid,
                                   uint32_t notify_offset,
                                   evtchn_port_t notify_port)
 {
-       return xcg->ops->u.gntshr.share_pages(xcg, xcg->ops_handle,
-                       domid, 1, ref, writable, notify_offset, notify_port);
+    return osdep_gntshr_share_pages(xcg, domid, 1, ref, writable,
+                                    notify_offset, notify_port);
 }
 
 /*
- * Unmaps the @count pages starting at @start_address, which were mapped by a
- * call to xc_gntshr_share_*. Never logs.
- */
-int xc_gntshr_munmap(xc_gntshr *xcg, void *start_address, uint32_t count)
-{
-       return xcg->ops->u.gntshr.munmap(xcg, xcg->ops_handle,
-                                        start_address, count);
-}
-
-
-/*
  * Local variables:
  * mode: C
  * c-file-style: "BSD"
diff --git a/tools/libxc/xc_linux_osdep.c b/tools/libxc/xc_linux_osdep.c
index 2230e44..f2c7f10 100644
--- a/tools/libxc/xc_linux_osdep.c
+++ b/tools/libxc/xc_linux_osdep.c
@@ -42,6 +42,9 @@
 
 #define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
 
+#define GTERROR(_l, _f...) xtl_log(_l, XTL_ERROR, errno, "gnttab", _f)
+#define GSERROR(_l, _f...) xtl_log(_l, XTL_ERROR, errno, "gntshr", _f)
+
 static xc_osdep_handle linux_privcmd_open(xc_interface *xch)
 {
     int flags, saved_errno;
@@ -455,26 +458,26 @@ static struct xc_osdep_ops linux_privcmd_ops = {
 
 #define DEVXEN "/dev/xen/"
 
-static xc_osdep_handle linux_gnttab_open(xc_gnttab *xcg)
+int osdep_gnttab_open(xc_gnttab *xgt)
 {
     int fd = open(DEVXEN "gntdev", O_RDWR);
-
     if ( fd == -1 )
-        return XC_OSDEP_OPEN_ERROR;
-
-    return (xc_osdep_handle)fd;
+        return -1;
+    xgt->fd = fd;
+    return 0;
 }
 
-static int linux_gnttab_close(xc_gnttab *xcg, xc_osdep_handle h)
+int osdep_gnttab_close(xc_gnttab *xgt)
 {
-    int fd = (int)h;
-    return close(fd);
+    if ( xgt->fd == -1 )
+        return 0;
+
+    return close(xgt->fd);
 }
 
-static int linux_gnttab_set_max_grants(xc_gnttab *xch, xc_osdep_handle h,
-                                       uint32_t count)
+int xc_gnttab_set_max_grants(xc_gnttab *xgt, uint32_t count)
 {
-    int fd = (int)h, rc;
+    int fd = xgt->fd, rc;
     struct ioctl_gntdev_set_max_grants max_grants = { .count = count };
 
     rc = ioctl(fd, IOCTL_GNTDEV_SET_MAX_GRANTS, &max_grants);
@@ -486,19 +489,19 @@ static int linux_gnttab_set_max_grants(xc_gnttab *xch, 
xc_osdep_handle h,
         if (errno == ENOTTY)
             rc = 0;
         else
-            PERROR("linux_gnttab_set_max_grants: ioctl SET_MAX_GRANTS failed");
+            GTERROR(xgt->logger, "ioctl SET_MAX_GRANTS failed");
     }
 
     return rc;
 }
 
-static void *linux_gnttab_grant_map(xc_gnttab *xch, xc_osdep_handle h,
-                                    uint32_t count, int flags, int prot,
-                                    uint32_t *domids, uint32_t *refs,
-                                    uint32_t notify_offset,
-                                    evtchn_port_t notify_port)
+void *osdep_gnttab_grant_map(xc_gnttab *xgt,
+                             uint32_t count, int flags, int prot,
+                             uint32_t *domids, uint32_t *refs,
+                             uint32_t notify_offset,
+                             evtchn_port_t notify_port)
 {
-    int fd = (int)h;
+    int fd = xgt->fd;
     struct ioctl_gntdev_map_grant_ref *map;
     unsigned int map_size = ROUNDUP((sizeof(*map) + (count - 1) *
                                     sizeof(struct ioctl_gntdev_map_grant_ref)),
@@ -519,7 +522,7 @@ static void *linux_gnttab_grant_map(xc_gnttab *xch, 
xc_osdep_handle h,
                    MAP_PRIVATE | MAP_ANON | MAP_POPULATE, -1, 0);
         if ( map == MAP_FAILED )
         {
-            PERROR("linux_gnttab_grant_map: mmap of map failed");
+            GTERROR(xgt->logger, "mmap of map failed");
             return NULL;
         }
     }
@@ -533,7 +536,7 @@ static void *linux_gnttab_grant_map(xc_gnttab *xch, 
xc_osdep_handle h,
     map->count = count;
 
     if ( ioctl(fd, IOCTL_GNTDEV_MAP_GRANT_REF, map) ) {
-        PERROR("linux_gnttab_grant_map: ioctl MAP_GRANT_REF failed");
+        GTERROR(xgt->logger, "ioctl MAP_GRANT_REF failed");
         goto out;
     }
 
@@ -572,7 +575,7 @@ static void *linux_gnttab_grant_map(xc_gnttab *xch, 
xc_osdep_handle h,
         if (notify.action)
             rv = ioctl(fd, IOCTL_GNTDEV_SET_UNMAP_NOTIFY, &notify);
         if (rv) {
-            PERROR("linux_gnttab_grant_map: ioctl SET_UNMAP_NOTIFY failed");
+            GTERROR(xgt->logger, "ioctl SET_UNMAP_NOTIFY failed");
             munmap(addr, count * XC_PAGE_SIZE);
             addr = MAP_FAILED;
         }
@@ -584,7 +587,7 @@ static void *linux_gnttab_grant_map(xc_gnttab *xch, 
xc_osdep_handle h,
         struct ioctl_gntdev_unmap_grant_ref unmap_grant;
 
         /* Unmap the driver slots used to store the grant information. */
-        PERROR("xc_gnttab_map_grant_refs: mmap failed");
+        GTERROR(xgt->logger, "mmap failed");
         unmap_grant.index = map->index;
         unmap_grant.count = count;
         ioctl(fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant);
@@ -599,12 +602,9 @@ static void *linux_gnttab_grant_map(xc_gnttab *xch, 
xc_osdep_handle h,
     return addr;
 }
 
-
-
-static int linux_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h,
-                               void *start_address, uint32_t count)
+int xc_gnttab_munmap(xc_gnttab *xgt, void *start_address, uint32_t count)
 {
-    int fd = (int)h;
+    int fd = xgt->fd;
     struct ioctl_gntdev_get_offset_for_vaddr get_offset;
     struct ioctl_gntdev_unmap_grant_ref unmap_grant;
     int rc;
@@ -642,43 +642,33 @@ static int linux_gnttab_munmap(xc_gnttab *xcg, 
xc_osdep_handle h,
     return 0;
 }
 
-static struct xc_osdep_ops linux_gnttab_ops = {
-    .open = &linux_gnttab_open,
-    .close = &linux_gnttab_close,
-
-    .u.gnttab = {
-        .set_max_grants = linux_gnttab_set_max_grants,
-        .grant_map = &linux_gnttab_grant_map,
-        .munmap = &linux_gnttab_munmap,
-    },
-};
-
-static xc_osdep_handle linux_gntshr_open(xc_gntshr *xcg)
+int osdep_gntshr_open(xc_gntshr *xgs)
 {
     int fd = open(DEVXEN "gntalloc", O_RDWR);
-
     if ( fd == -1 )
-        return XC_OSDEP_OPEN_ERROR;
-
-    return (xc_osdep_handle)fd;
+        return -1;
+    xgs->fd = fd;
+    return 0;
 }
 
-static int linux_gntshr_close(xc_gntshr *xcg, xc_osdep_handle h)
+int osdep_gntshr_close(xc_gntshr *xgs)
 {
-    int fd = (int)h;
-    return close(fd);
+    if ( xgs->fd == -1 )
+        return 0;
+
+    return close(xgs->fd);
 }
 
-static void *linux_gntshr_share_pages(xc_gntshr *xch, xc_osdep_handle h,
-                                      uint32_t domid, int count,
-                                      uint32_t *refs, int writable,
-                                      uint32_t notify_offset,
-                                      evtchn_port_t notify_port)
+void *osdep_gntshr_share_pages(xc_gntshr *xgs,
+                               uint32_t domid, int count,
+                               uint32_t *refs, int writable,
+                               uint32_t notify_offset,
+                               evtchn_port_t notify_port)
 {
     struct ioctl_gntalloc_alloc_gref *gref_info = NULL;
     struct ioctl_gntalloc_unmap_notify notify;
     struct ioctl_gntalloc_dealloc_gref gref_drop;
-    int fd = (int)h;
+    int fd = xgs->fd;
     int err;
     void *area = NULL;
     gref_info = malloc(sizeof(*gref_info) + count * sizeof(uint32_t));
@@ -690,7 +680,7 @@ static void *linux_gntshr_share_pages(xc_gntshr *xch, 
xc_osdep_handle h,
 
     err = ioctl(fd, IOCTL_GNTALLOC_ALLOC_GREF, gref_info);
     if (err) {
-        PERROR("linux_gntshr_share_pages: ioctl failed");
+        GSERROR(xgs->logger, "ioctl failed");
         goto out;
     }
 
@@ -699,7 +689,7 @@ static void *linux_gntshr_share_pages(xc_gntshr *xch, 
xc_osdep_handle h,
 
     if (area == MAP_FAILED) {
         area = NULL;
-        PERROR("linux_gntshr_share_pages: mmap failed");
+        GSERROR(xgs->logger, "mmap failed");
         goto out_remove_fdmap;
     }
 
@@ -716,7 +706,7 @@ static void *linux_gntshr_share_pages(xc_gntshr *xch, 
xc_osdep_handle h,
     if (notify.action)
         err = ioctl(fd, IOCTL_GNTALLOC_SET_UNMAP_NOTIFY, &notify);
     if (err) {
-        PERROR("linux_gntshr_share_page_notify: ioctl SET_UNMAP_NOTIFY 
failed");
+        GSERROR(xgs->logger, "ioctl SET_UNMAP_NOTIFY failed");
                munmap(area, count * XC_PAGE_SIZE);
                area = NULL;
        }
@@ -735,33 +725,18 @@ static void *linux_gntshr_share_pages(xc_gntshr *xch, 
xc_osdep_handle h,
     return area;
 }
 
-static int linux_gntshr_munmap(xc_gntshr *xcg, xc_osdep_handle h,
-                               void *start_address, uint32_t count)
+int xc_gntshr_munmap(xc_gntshr *xgs,
+                     void *start_address, uint32_t count)
 {
     return munmap(start_address, count * XC_PAGE_SIZE);
 }
 
-static struct xc_osdep_ops linux_gntshr_ops = {
-    .open = &linux_gntshr_open,
-    .close = &linux_gntshr_close,
-
-    .u.gntshr = {
-        .share_pages = &linux_gntshr_share_pages,
-        .munmap = &linux_gntshr_munmap,
-    },
-};
-
-
 static struct xc_osdep_ops *linux_osdep_init(xc_interface *xch, enum 
xc_osdep_type type)
 {
     switch ( type )
     {
     case XC_OSDEP_PRIVCMD:
         return &linux_privcmd_ops;
-    case XC_OSDEP_GNTTAB:
-        return &linux_gnttab_ops;
-    case XC_OSDEP_GNTSHR:
-        return &linux_gntshr_ops;
     default:
         return NULL;
     }
diff --git a/tools/libxc/xc_minios.c b/tools/libxc/xc_minios.c
index 7878cfa..2cc9ea9 100644
--- a/tools/libxc/xc_minios.c
+++ b/tools/libxc/xc_minios.c
@@ -203,19 +203,22 @@ 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 osdep_gnttab_open(xc_gnttab *xgt)
 {
     int fd = alloc_fd(FTYPE_GNTMAP);
     if ( fd == -1 )
-        return XC_OSDEP_OPEN_ERROR;
+        return -1;
     gntmap_init(&files[fd].gntmap);
-    return (xc_osdep_handle)fd;
+    xgt->fd = fd;
+    return 0;
 }
 
-static int minios_gnttab_close(xc_gnttab *xcg, xc_osdep_handle h)
+int osdep_gnttab_close(xc_gnttab *xgt)
 {
-    int fd = (int)h;
-    return close(fd);
+    if ( xgt->fd == -1 )
+        return 0;
+
+    return close(xgt->fd);
 }
 
 void minios_gnttab_close_fd(int fd)
@@ -224,13 +227,13 @@ void minios_gnttab_close_fd(int fd)
     files[fd].type = FTYPE_NONE;
 }
 
-static void *minios_gnttab_grant_map(xc_gnttab *xcg, xc_osdep_handle h,
-                                     uint32_t count, int flags, int prot,
-                                     uint32_t *domids, uint32_t *refs,
-                                     uint32_t notify_offset,
-                                     evtchn_port_t notify_port)
+void *osdep_gnttab_grant_map(xc_gnttab *xgt,
+                             uint32_t count, int flags, int prot,
+                             uint32_t *domids, uint32_t *refs,
+                             uint32_t notify_offset,
+                             evtchn_port_t notify_port)
 {
-    int fd = (int)h;
+    int fd = xgt->fd;
     int stride = 1;
     if (flags & XC_GRANT_MAP_SINGLE_DOMAIN)
         stride = 0;
@@ -243,11 +246,9 @@ static void *minios_gnttab_grant_map(xc_gnttab *xcg, 
xc_osdep_handle h,
                                  refs, prot & PROT_WRITE);
 }
 
-static int minios_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h,
-                                void *start_address,
-                                uint32_t count)
+int xc_gnttab_munmap(xc_gnttab *xgt, void *start_address, uint32_t count)
 {
-    int fd = (int)h;
+    int fd = xgt->fd;
     int ret;
     ret = gntmap_munmap(&files[fd].gntmap,
                         (unsigned long) start_address,
@@ -259,10 +260,9 @@ static int minios_gnttab_munmap(xc_gnttab *xcg, 
xc_osdep_handle h,
     return ret;
 }
 
-static int minios_gnttab_set_max_grants(xc_gnttab *xcg, xc_osdep_handle h,
-                             uint32_t count)
+int xc_gnttab_set_max_grants(xc_gnttab *xgt, uint32_t count)
 {
-    int fd = (int)h;
+    int fd = xgt->fd;
     int ret;
     ret = gntmap_set_max_grants(&files[fd].gntmap,
                                 count);
@@ -273,25 +273,12 @@ static int minios_gnttab_set_max_grants(xc_gnttab *xcg, 
xc_osdep_handle h,
     return ret;
 }
 
-static struct xc_osdep_ops minios_gnttab_ops = {
-    .open = &minios_gnttab_open,
-    .close = &minios_gnttab_close,
-
-    .u.gnttab = {
-        .grant_map = &minios_gnttab_grant_map,
-        .munmap = &minios_gnttab_munmap,
-        .set_max_grants = &minios_gnttab_set_max_grants,
-    },
-};
-
 static struct xc_osdep_ops *minios_osdep_init(xc_interface *xch, enum 
xc_osdep_type type)
 {
     switch ( type )
     {
     case XC_OSDEP_PRIVCMD:
         return &minios_privcmd_ops;
-    case XC_OSDEP_GNTTAB:
-        return &minios_gnttab_ops;
     default:
         return NULL;
     }
diff --git a/tools/libxc/xc_nogntshr.c b/tools/libxc/xc_nogntshr.c
new file mode 100644
index 0000000..6681018
--- /dev/null
+++ b/tools/libxc/xc_nogntshr.c
@@ -0,0 +1,44 @@
+/******************************************************************************
+ *
+ * Copyright (c) 2007-2008, D G Murray <Derek.Murray@xxxxxxxxxxxx>
+ *
+ * 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.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "xc_private.h"
+
+int osdep_gntshr_open(xc_gnttab *xgt)
+{
+    return -1;
+}
+
+int osdep_gntshr_close(xc_gnttab *xgt)
+{
+    return 0;
+}
+
+void *osdep_gntshr_share_pages(xc_gntshr *xgs,
+                               uint32_t domid, int count,
+                               uint32_t *refs, int writable,
+                               uint32_t notify_offset,
+                               evtchn_port_t notify_port)
+{
+    abort()
+}
+
+int xc_gntshr_munmap(xc_gntshr *xgs,
+                     void *start_address, uint32_t count)
+{
+    abort();
+}
diff --git a/tools/libxc/xc_nognttab.c b/tools/libxc/xc_nognttab.c
new file mode 100644
index 0000000..4b4a2ca
--- /dev/null
+++ b/tools/libxc/xc_nognttab.c
@@ -0,0 +1,48 @@
+/******************************************************************************
+ *
+ * Copyright (c) 2007-2008, D G Murray <Derek.Murray@xxxxxxxxxxxx>
+ *
+ * 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.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "xc_private.h"
+
+int osdep_gnttab_open(xc_gnttab *xgt)
+{
+    return -1;
+}
+
+int osdep_gnttab_close(xc_gnttab *xgt)
+{
+    return 0;
+}
+
+int xc_gnttab_set_max_grants(xc_gnttab *xgt, uint32_t count)
+{
+    abort();
+}
+
+void *osdep_gnttab_grant_map(xc_gnttab *xgt,
+                             uint32_t count, int flags, int prot,
+                             uint32_t *domids, uint32_t *refs,
+                             uint32_t notify_offset,
+                             evtchn_port_t notify_port)
+{
+    abort();
+}
+
+int xc_gnttab_munmap(xc_gnttab *xgt, void *start_address, uint32_t count)
+{
+    abort();
+}
diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c
index 375430c..b2c3c06 100644
--- a/tools/libxc/xc_private.c
+++ b/tools/libxc/xc_private.c
@@ -120,8 +120,6 @@ static const char *xc_osdep_type_name(enum xc_osdep_type 
type)
     switch ( type )
     {
     case XC_OSDEP_PRIVCMD: return "privcmd";
-    case XC_OSDEP_GNTTAB:  return "gnttab";
-    case XC_OSDEP_GNTSHR:  return "gntshr";
     }
     return "unknown";
 }
@@ -252,30 +250,85 @@ int do_xen_hypercall(xc_interface *xch, 
privcmd_hypercall_t *hypercall)
     return xch->ops->u.privcmd.hypercall(xch, xch->ops_handle, hypercall);
 }
 
-xc_gnttab *xc_gnttab_open(xentoollog_logger *logger,
-                             unsigned open_flags)
+xc_gnttab *xc_gnttab_open(xentoollog_logger *logger, unsigned open_flags)
 {
-    return xc_interface_open_common(logger, NULL, open_flags,
-                                    XC_OSDEP_GNTTAB);
+    xc_gnttab *xgt = malloc(sizeof(*xgt));
+    int rc;
+
+    if (!xgt) return NULL;
+
+    xgt->fd = -1;
+    xgt->logger = logger;
+    xgt->logger_tofree  = NULL;
+
+    if (!xgt->logger) {
+        xgt->logger = xgt->logger_tofree =
+            (xentoollog_logger*)
+            xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);
+        if (!xgt->logger) goto err;
+    }
+
+    rc = osdep_gnttab_open(xgt);
+    if ( rc  < 0 ) goto err;
+
+    return xgt;
+
+err:
+    osdep_gnttab_close(xgt);
+    xtl_logger_destroy(xgt->logger_tofree);
+    free(xgt);
+    return NULL;
 }
 
-int xc_gnttab_close(xc_gnttab *xcg)
+int xc_gnttab_close(xc_gnttab *xgt)
 {
-    return xc_interface_close_common(xcg);
+    int rc;
+
+    rc = osdep_gnttab_close(xgt);
+    xtl_logger_destroy(xgt->logger_tofree);
+    free(xgt);
+    return rc;
 }
 
-xc_gntshr *xc_gntshr_open(xentoollog_logger *logger,
-                             unsigned open_flags)
+xc_gntshr *xc_gntshr_open(xentoollog_logger *logger, unsigned open_flags)
 {
-    return xc_interface_open_common(logger, NULL, open_flags,
-                                    XC_OSDEP_GNTSHR);
+    xc_gntshr *xgs = malloc(sizeof(*xgs));
+    int rc;
+
+    if (!xgs) return NULL;
+
+    xgs->fd = -1;
+    xgs->logger = logger;
+    xgs->logger_tofree  = NULL;
+
+    if (!xgs->logger) {
+        xgs->logger = xgs->logger_tofree =
+            (xentoollog_logger*)
+            xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);
+        if (!xgs->logger) goto err;
+    }
+
+    rc = osdep_gntshr_open(xgs);
+    if ( rc  < 0 ) goto err;
+
+    return xgs;
+
+err:
+    osdep_gntshr_close(xgs);
+    xtl_logger_destroy(xgs->logger_tofree);
+    free(xgs);
+    return NULL;
 }
 
-int xc_gntshr_close(xc_gntshr *xcg)
+int xc_gntshr_close(xc_gntshr *xgs)
 {
-    return xc_interface_close_common(xcg);
-}
+    int rc;
 
+    rc = osdep_gntshr_close(xgs);
+    xtl_logger_destroy(xgs->logger_tofree);
+    free(xgs);
+    return rc;
+}
 
 static pthread_key_t errbuf_pkey;
 static pthread_once_t errbuf_pkey_once = PTHREAD_ONCE_INIT;
diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h
index 61f2f45..81af034 100644
--- a/tools/libxc/xc_private.h
+++ b/tools/libxc/xc_private.h
@@ -124,6 +124,30 @@ struct xc_interface_core {
     xc_osdep_handle  ops_handle; /* opaque data for xc_osdep_ops */
 };
 
+struct xengntdev_handle {
+    xentoollog_logger *logger, *logger_tofree;
+    int fd;
+};
+
+int osdep_gnttab_open(xc_gnttab *xgt);
+int osdep_gnttab_close(xc_gnttab *xgt);
+
+#define XC_GRANT_MAP_SINGLE_DOMAIN 0x1
+void *osdep_gnttab_grant_map(xc_gnttab *xgt,
+                             uint32_t count, int flags, int prot,
+                             uint32_t *domids, uint32_t *refs,
+                             uint32_t notify_offset,
+                             evtchn_port_t notify_port);
+
+int osdep_gntshr_open(xc_gntshr *xgs);
+int osdep_gntshr_close(xc_gntshr *xgs);
+
+void *osdep_gntshr_share_pages(xc_gntshr *xgs,
+                               uint32_t domid, int count,
+                               uint32_t *refs, int writable,
+                               uint32_t notify_offset,
+                               evtchn_port_t notify_port);
+
 void xc_report_error(xc_interface *xch, int code, const char *fmt, ...)
     __attribute__((format(printf,3,4)));
 void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.