aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxc/xc_linux.c
diff options
context:
space:
mode:
authorIan Campbell <ian.campbell@citrix.com>2010-12-03 09:36:46 +0000
committerIan Campbell <ian.campbell@citrix.com>2010-12-03 09:36:46 +0000
commit02e4f47747e6198c834017e5038fa6bf98a0cfeb (patch)
treee186d387ef6632056c5e55a9750a6e9f3987c0c4 /tools/libxc/xc_linux.c
parent94705cc4bfe4d9d749d86f49045f62ed9e48a0bc (diff)
downloadxen-02e4f47747e6198c834017e5038fa6bf98a0cfeb.tar.gz
xen-02e4f47747e6198c834017e5038fa6bf98a0cfeb.tar.bz2
xen-02e4f47747e6198c834017e5038fa6bf98a0cfeb.zip
libxc: osdep: add framework for abstracting access to dom0 OS hypervisor interfaces.
This patch introduces the basic infrastructure and uses it for open and close operations on privcmd, evtchn and gnttab devices. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Signed-off-by: Ian Jackson <ian.jackson.citrix.com>
Diffstat (limited to 'tools/libxc/xc_linux.c')
-rw-r--r--tools/libxc/xc_linux.c80
1 files changed, 65 insertions, 15 deletions
diff --git a/tools/libxc/xc_linux.c b/tools/libxc/xc_linux.c
index 13cb802d5d..5c9e70c065 100644
--- a/tools/libxc/xc_linux.c
+++ b/tools/libxc/xc_linux.c
@@ -29,7 +29,7 @@
#include <unistd.h>
#include <fcntl.h>
-int xc_interface_open_core(xc_interface *xch)
+static xc_osdep_handle linux_privcmd_open(xc_interface *xch)
{
int flags, saved_errno;
int fd = open("/proc/xen/privcmd", O_RDWR);
@@ -37,7 +37,7 @@ int xc_interface_open_core(xc_interface *xch)
if ( fd == -1 )
{
PERROR("Could not obtain handle on privileged command interface");
- return -1;
+ return XC_OSDEP_OPEN_ERROR;
}
/* Although we return the file handle as the 'xc handle' the API
@@ -58,19 +58,21 @@ int xc_interface_open_core(xc_interface *xch)
goto error;
}
- return fd;
+ xch->fd = fd; /* Remove after transition to full xc_osdep_ops. */
+
+ return (xc_osdep_handle)fd;
error:
saved_errno = errno;
close(fd);
errno = saved_errno;
-
- return -1;
+ return XC_OSDEP_OPEN_ERROR;
}
-int xc_interface_close_core(xc_interface *xch)
+static int linux_privcmd_close(xc_interface *xch, xc_osdep_handle h)
{
- return close(xch->fd);
+ int fd = (int)h;
+ return close(fd);
}
static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom,
@@ -325,16 +327,27 @@ int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
(unsigned long)hypercall);
}
+static struct xc_osdep_ops linux_privcmd_ops = {
+ .open = &linux_privcmd_open,
+ .close = &linux_privcmd_close,
+};
+
#define DEVXEN "/dev/xen/"
-int xc_evtchn_open_core(xc_evtchn *xce)
+static xc_osdep_handle linux_evtchn_open(xc_evtchn *xce)
{
- return open(DEVXEN "evtchn", O_RDWR);
+ int fd = open(DEVXEN "evtchn", O_RDWR);
+ if ( fd == -1 )
+ return XC_OSDEP_OPEN_ERROR;
+
+ xce->fd = fd; /* Remove after transition to full xc_osdep_ops. */
+ return (xc_osdep_handle)fd;
}
-int xc_evtchn_close_core(xc_evtchn *xce)
+static int linux_evtchn_close(xc_evtchn *xce, xc_osdep_handle h)
{
- return close(xce->fd);
+ int fd = (int)h;
+ return close(fd);
}
int xc_evtchn_fd(xc_evtchn *xce)
@@ -408,6 +421,11 @@ int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
return write_exact(xce->fd, (char *)&port, sizeof(port));
}
+static struct xc_osdep_ops linux_evtchn_ops = {
+ .open = &linux_evtchn_open,
+ .close = &linux_evtchn_close,
+};
+
/* Optionally flush file to disk and discard page cache */
void discard_file_cache(xc_interface *xch, int fd, int flush)
{
@@ -443,14 +461,21 @@ void discard_file_cache(xc_interface *xch, int fd, int flush)
errno = saved_errno;
}
-int xc_gnttab_open_core(xc_gnttab *xcg)
+static xc_osdep_handle linux_gnttab_open(xc_gnttab *xcg)
{
- return open(DEVXEN "gntdev", O_RDWR);
+ int fd = open(DEVXEN "gntdev", O_RDWR);
+
+ if ( fd == -1 )
+ return XC_OSDEP_OPEN_ERROR;
+
+ xcg->fd = fd; /* Remove after transition to full xc_osdep_ops. */
+ return (xc_osdep_handle)fd;
}
-int xc_gnttab_close_core(xc_gnttab *xcg)
+static int linux_gnttab_close(xc_gnttab *xcg, xc_osdep_handle h)
{
- return close(xcg->fd);
+ int fd = (int)h;
+ return close(fd);
}
void *xc_gnttab_map_grant_ref(xc_gnttab *xch, uint32_t domid, uint32_t ref, int prot)
@@ -602,6 +627,31 @@ int xc_gnttab_set_max_grants(xc_gnttab *xcg, uint32_t count)
return 0;
}
+static struct xc_osdep_ops linux_gnttab_ops = {
+ .open = &linux_gnttab_open,
+ .close = &linux_gnttab_close,
+};
+
+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_EVTCHN:
+ return &linux_evtchn_ops;
+ case XC_OSDEP_GNTTAB:
+ return &linux_gnttab_ops;
+ default:
+ return NULL;
+ }
+}
+
+xc_osdep_info_t xc_osdep_info = {
+ .name = "Linux Native OS interface",
+ .init = &linux_osdep_init,
+};
+
/*
* Local variables:
* mode: C