diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 079cad0f4e..1bf70f9656 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -117,7 +117,7 @@ */ typedef struct xc_interface_core xc_interface; -typedef struct xc_interface_core xc_evtchn; +typedef struct xenevtchn_handle xc_evtchn; typedef struct xc_interface_core xc_gnttab; typedef struct xc_interface_core xc_gntshr; diff --git a/tools/libxc/include/xenctrlosdep.h b/tools/libxc/include/xenctrlosdep.h index 5121d9bd19..89564e1ff3 100644 --- a/tools/libxc/include/xenctrlosdep.h +++ b/tools/libxc/include/xenctrlosdep.h @@ -51,7 +51,6 @@ enum xc_osdep_type { XC_OSDEP_PRIVCMD, - XC_OSDEP_EVTCHN, XC_OSDEP_GNTTAB, XC_OSDEP_GNTSHR, }; @@ -90,21 +89,6 @@ struct xc_osdep_ops int nentries); } privcmd; struct { - int (*fd)(xc_evtchn *xce, xc_osdep_handle h); - - int (*notify)(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port); - - evtchn_port_or_error_t (*bind_unbound_port)(xc_evtchn *xce, xc_osdep_handle h, int domid); - evtchn_port_or_error_t (*bind_interdomain)(xc_evtchn *xce, xc_osdep_handle h, int domid, - evtchn_port_t remote_port); - evtchn_port_or_error_t (*bind_virq)(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq); - - int (*unbind)(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port); - - evtchn_port_or_error_t (*pending)(xc_evtchn *xce, xc_osdep_handle h); - int (*unmask)(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port); - } evtchn; - 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, diff --git a/tools/libxc/xc_evtchn.c b/tools/libxc/xc_evtchn.c index 15f0580ef6..ae2fe1a21b 100644 --- a/tools/libxc/xc_evtchn.c +++ b/tools/libxc/xc_evtchn.c @@ -77,51 +77,6 @@ int xc_evtchn_status(xc_interface *xch, xc_evtchn_status_t *status) sizeof(*status), 1); } -int xc_evtchn_fd(xc_evtchn *xce) -{ - return xce->ops->u.evtchn.fd(xce, xce->ops_handle); -} - -int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) -{ - return xce->ops->u.evtchn.notify(xce, xce->ops_handle, port); -} - -evtchn_port_or_error_t -xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid) -{ - return xce->ops->u.evtchn.bind_unbound_port(xce, xce->ops_handle, domid); -} - -evtchn_port_or_error_t -xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, - evtchn_port_t remote_port) -{ - return xce->ops->u.evtchn.bind_interdomain(xce, xce->ops_handle, domid, remote_port); -} - -evtchn_port_or_error_t -xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) -{ - return xce->ops->u.evtchn.bind_virq(xce, xce->ops_handle, virq); -} - -int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port) -{ - return xce->ops->u.evtchn.unbind(xce, xce->ops_handle, port); -} - -evtchn_port_or_error_t -xc_evtchn_pending(xc_evtchn *xce) -{ - return xce->ops->u.evtchn.pending(xce, xce->ops_handle); -} - -int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port) -{ - return xce->ops->u.evtchn.unmask(xce, xce->ops_handle, port); -} - /* * Local variables: * mode: C diff --git a/tools/libxc/xc_freebsd_osdep.c b/tools/libxc/xc_freebsd_osdep.c index 4d31a1e454..4323e16fc3 100644 --- a/tools/libxc/xc_freebsd_osdep.c +++ b/tools/libxc/xc_freebsd_osdep.c @@ -252,34 +252,32 @@ static struct xc_osdep_ops freebsd_privcmd_ops = { }; /*-------------------------- Evtchn device interface -------------------------*/ -static xc_osdep_handle -freebsd_evtchn_open(xc_evtchn *xce) +int osdep_evtchn_open(xc_evtchn *xce) { int fd = open(EVTCHN_DEV, O_RDWR); if ( fd == -1 ) - return XC_OSDEP_OPEN_ERROR; - - return (xc_osdep_handle)fd; + return -1; + xce->fd = fd; + return 0; } -static int -freebsd_evtchn_close(xc_evtchn *xce, xc_osdep_handle h) +int osdep_evtchn_close(xc_evtchn *xce) { - int fd = (int)h; - return close(fd); + if ( xce->fd == -1 ) + return 0; + + return close(xce->fd); } -static int -freebsd_evtchn_fd(xc_evtchn *xce, xc_osdep_handle h) +int xc_evtchn_fd(xc_evtchn *xce) { - return (int)h; + return xce->fd; } /*------------------------------ Evtchn interface ----------------------------*/ -static int -freebsd_evtchn_notify(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) +int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) { - int fd = (int)h; + int fd = xce->fd; struct ioctl_evtchn_notify notify; notify.port = port; @@ -287,10 +285,9 @@ freebsd_evtchn_notify(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify); } -static evtchn_port_or_error_t -freebsd_evtchn_bind_unbound_port(xc_evtchn *xce, xc_osdep_handle h, int domid) +evtchn_port_or_error_t xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid) { - int ret, fd = (int)h; + int ret, fd = xce->fd; struct ioctl_evtchn_bind_unbound_port bind; bind.remote_domain = domid; @@ -299,11 +296,10 @@ freebsd_evtchn_bind_unbound_port(xc_evtchn *xce, xc_osdep_handle h, int domid) return ( ret == 0 ) ? bind.port : ret; } -static evtchn_port_or_error_t -freebsd_evtchn_bind_interdomain(xc_evtchn *xce, xc_osdep_handle h, int domid, - evtchn_port_t remote_port) +evtchn_port_or_error_t +xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, evtchn_port_t remote_port) { - int ret, fd = (int)h; + int ret, fd = xce->fd; struct ioctl_evtchn_bind_interdomain bind; bind.remote_domain = domid; @@ -313,10 +309,9 @@ freebsd_evtchn_bind_interdomain(xc_evtchn *xce, xc_osdep_handle h, int domid, return ( ret == 0 ) ? bind.port : ret; } -static evtchn_port_or_error_t -freebsd_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq) +evtchn_port_or_error_t xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) { - int ret, fd = (int)h; + int ret, fd = xce->fd; struct ioctl_evtchn_bind_virq bind; bind.virq = virq; @@ -325,10 +320,9 @@ freebsd_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq) return ( ret == 0 ) ? bind.port : ret; } -static int -freebsd_evtchn_unbind(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) +int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port) { - int fd = (int)h; + int fd = xce->fd; struct ioctl_evtchn_unbind unbind; unbind.port = port; @@ -336,10 +330,9 @@ freebsd_evtchn_unbind(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind); } -static evtchn_port_or_error_t -freebsd_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h) +evtchn_port_or_error_t xc_evtchn_pending(xc_evtchn *xce) { - int fd = (int)h; + int fd = xce->fd; evtchn_port_t port; if ( read(fd, &port, sizeof(port)) != sizeof(port) ) @@ -348,33 +341,15 @@ freebsd_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h) return port; } -static int -freebsd_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) +int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port) { - int fd = (int)h; + int fd = xce->fd; if ( write(fd, &port, sizeof(port)) != sizeof(port) ) return -1; return 0; } -/*----------------------------- Evtchn handlers ------------------------------*/ -static struct xc_osdep_ops freebsd_evtchn_ops = { - .open = &freebsd_evtchn_open, - .close = &freebsd_evtchn_close, - - .u.evtchn = { - .fd = &freebsd_evtchn_fd, - .notify = &freebsd_evtchn_notify, - .bind_unbound_port = &freebsd_evtchn_bind_unbound_port, - .bind_interdomain = &freebsd_evtchn_bind_interdomain, - .bind_virq = &freebsd_evtchn_bind_virq, - .unbind = &freebsd_evtchn_unbind, - .pending = &freebsd_evtchn_pending, - .unmask = &freebsd_evtchn_unmask, - }, -}; - /*---------------------------- FreeBSD interface -----------------------------*/ static struct xc_osdep_ops * freebsd_osdep_init(xc_interface *xch, enum xc_osdep_type type) @@ -383,8 +358,6 @@ freebsd_osdep_init(xc_interface *xch, enum xc_osdep_type type) { case XC_OSDEP_PRIVCMD: return &freebsd_privcmd_ops; - case XC_OSDEP_EVTCHN: - return &freebsd_evtchn_ops; default: return NULL; } diff --git a/tools/libxc/xc_linux_osdep.c b/tools/libxc/xc_linux_osdep.c index c3a3a140e2..90544fb3ab 100644 --- a/tools/libxc/xc_linux_osdep.c +++ b/tools/libxc/xc_linux_osdep.c @@ -38,10 +38,9 @@ #include "xenctrl.h" #include "xenctrlosdep.h" +#include "xc_private.h" + #define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1)) -#define ERROR(_m, _a...) xc_osdep_log(xch,XTL_ERROR,XC_INTERNAL_ERROR,_m , ## _a ) -#define PERROR(_m, _a...) xc_osdep_log(xch,XTL_ERROR,XC_INTERNAL_ERROR,_m \ - " (%d = %s)", ## _a , errno, xc_strerror(xch, errno)) static xc_osdep_handle linux_privcmd_open(xc_interface *xch) { @@ -462,29 +461,31 @@ static struct xc_osdep_ops linux_privcmd_ops = { #define DEVXEN "/dev/xen/" -static xc_osdep_handle linux_evtchn_open(xc_evtchn *xce) +int osdep_evtchn_open(xc_evtchn *xce) { int fd = open(DEVXEN "evtchn", O_RDWR); if ( fd == -1 ) - return XC_OSDEP_OPEN_ERROR; - - return (xc_osdep_handle)fd; + return -1; + xce->fd = fd; + return 0; } -static int linux_evtchn_close(xc_evtchn *xce, xc_osdep_handle h) +int osdep_evtchn_close(xc_evtchn *xce) { - int fd = (int)h; - return close(fd); + if ( xce->fd == -1 ) + return 0; + + return close(xce->fd); } -static int linux_evtchn_fd(xc_evtchn *xce, xc_osdep_handle h) +int xc_evtchn_fd(xc_evtchn *xce) { - return (int)h; + return xce->fd; } -static int linux_evtchn_notify(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) +int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) { - int fd = (int)h; + int fd = xce->fd; struct ioctl_evtchn_notify notify; notify.port = port; @@ -492,10 +493,9 @@ static int linux_evtchn_notify(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify); } -static evtchn_port_or_error_t -linux_evtchn_bind_unbound_port(xc_evtchn *xce, xc_osdep_handle h, int domid) +evtchn_port_or_error_t xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid) { - int fd = (int)h; + int fd = xce->fd; struct ioctl_evtchn_bind_unbound_port bind; bind.remote_domain = domid; @@ -503,11 +503,10 @@ linux_evtchn_bind_unbound_port(xc_evtchn *xce, xc_osdep_handle h, int domid) return ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); } -static evtchn_port_or_error_t -linux_evtchn_bind_interdomain(xc_evtchn *xce, xc_osdep_handle h, int domid, - evtchn_port_t remote_port) +evtchn_port_or_error_t xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, + evtchn_port_t remote_port) { - int fd = (int)h; + int fd = xce->fd; struct ioctl_evtchn_bind_interdomain bind; bind.remote_domain = domid; @@ -516,10 +515,9 @@ linux_evtchn_bind_interdomain(xc_evtchn *xce, xc_osdep_handle h, int domid, return ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); } -static evtchn_port_or_error_t -linux_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq) +evtchn_port_or_error_t xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) { - int fd = (int)h; + int fd = xce->fd; struct ioctl_evtchn_bind_virq bind; bind.virq = virq; @@ -527,9 +525,9 @@ linux_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq) return ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind); } -static int linux_evtchn_unbind(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) +int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port) { - int fd = (int)h; + int fd = xce->fd; struct ioctl_evtchn_unbind unbind; unbind.port = port; @@ -537,9 +535,9 @@ static int linux_evtchn_unbind(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind); } -static evtchn_port_or_error_t linux_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h) +evtchn_port_or_error_t xc_evtchn_pending(xc_evtchn *xce) { - int fd = (int)h; + int fd = xce->fd; evtchn_port_t port; if ( read(fd, &port, sizeof(port)) != sizeof(port) ) @@ -548,31 +546,15 @@ static evtchn_port_or_error_t linux_evtchn_pending(xc_evtchn *xce, xc_osdep_hand return port; } -static int linux_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) +int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port) { - int fd = (int)h; + int fd = xce->fd; if ( write(fd, &port, sizeof(port)) != sizeof(port) ) return -1; return 0; } -static struct xc_osdep_ops linux_evtchn_ops = { - .open = &linux_evtchn_open, - .close = &linux_evtchn_close, - - .u.evtchn = { - .fd = &linux_evtchn_fd, - .notify = &linux_evtchn_notify, - .bind_unbound_port = &linux_evtchn_bind_unbound_port, - .bind_interdomain = &linux_evtchn_bind_interdomain, - .bind_virq = &linux_evtchn_bind_virq, - .unbind = &linux_evtchn_unbind, - .pending = &linux_evtchn_pending, - .unmask = &linux_evtchn_unmask, - }, -}; - static xc_osdep_handle linux_gnttab_open(xc_gnttab *xcg) { int fd = open(DEVXEN "gntdev", O_RDWR); @@ -876,8 +858,6 @@ static struct xc_osdep_ops *linux_osdep_init(xc_interface *xch, enum xc_osdep_ty { case XC_OSDEP_PRIVCMD: return &linux_privcmd_ops; - case XC_OSDEP_EVTCHN: - return &linux_evtchn_ops; case XC_OSDEP_GNTTAB: return &linux_gnttab_ops; case XC_OSDEP_GNTSHR: diff --git a/tools/libxc/xc_minios.c b/tools/libxc/xc_minios.c index 4f6498f255..4ace1b594b 100644 --- a/tools/libxc/xc_minios.c +++ b/tools/libxc/xc_minios.c @@ -219,20 +219,23 @@ static void port_dealloc(struct evtchn_port_info *port_info) { free(port_info); } -static xc_osdep_handle minios_evtchn_open(xc_evtchn *xce) +int osdep_evtchn_open(xc_evtchn *xce) { int fd = alloc_fd(FTYPE_EVTCHN); if ( fd == -1 ) - return XC_OSDEP_OPEN_ERROR; + return -1; LIST_INIT(&files[fd].evtchn.ports); + xce->fd = fd; printf("evtchn_open() -> %d\n", fd); - return (xc_osdep_handle)fd; + return 0; } -static int minios_evtchn_close(xc_evtchn *xce, xc_osdep_handle h) +int osdep_evtchn_close(xc_evtchn *xce, xc_osdep_handle h) { - int fd = (int)h; - return close(fd); + if ( xce->fd == -1 ) + return 0; + + return close(xce->fd); } void minios_evtchn_close_fd(int fd) @@ -244,12 +247,12 @@ void minios_evtchn_close_fd(int fd) files[fd].type = FTYPE_NONE; } -static int minios_evtchn_fd(xc_evtchn *xce, xc_osdep_handle h) +int xc_evtchn_fd(xc_evtchn *xce) { - return (int)h; + return xce->fd; } -static int minios_evtchn_notify(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) +int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) { int ret; @@ -281,9 +284,9 @@ static void evtchn_handler(evtchn_port_t port, struct pt_regs *regs, void *data) wake_up(&event_queue); } -static evtchn_port_or_error_t minios_evtchn_bind_unbound_port(xc_evtchn *xce, xc_osdep_handle h, int domid) +evtchn_port_or_error_t xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid) { - int fd = (int)h; + int fd = xce->fd; struct evtchn_port_info *port_info; int ret; evtchn_port_t port; @@ -308,10 +311,10 @@ static evtchn_port_or_error_t minios_evtchn_bind_unbound_port(xc_evtchn *xce, xc return port; } -static evtchn_port_or_error_t minios_evtchn_bind_interdomain(xc_evtchn *xce, xc_osdep_handle h, int domid, - evtchn_port_t remote_port) +evtchn_port_or_error_t xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, + evtchn_port_t remote_port) { - int fd = (int)h; + int fd = xce->fd; struct evtchn_port_info *port_info; evtchn_port_t local_port; int ret; @@ -336,9 +339,9 @@ static evtchn_port_or_error_t minios_evtchn_bind_interdomain(xc_evtchn *xce, xc_ return local_port; } -static int minios_evtchn_unbind(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) +int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port) { - int fd = (int)h; + int fd = xce->fd; struct evtchn_port_info *port_info; LIST_FOREACH(port_info, &files[fd].evtchn.ports, list) { @@ -352,9 +355,9 @@ static int minios_evtchn_unbind(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t return -1; } -static evtchn_port_or_error_t minios_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq) +evtchn_port_or_error_t xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) { - int fd = (int)h; + int fd = xce->fd; struct evtchn_port_info *port_info; evtchn_port_t port; @@ -377,9 +380,9 @@ static evtchn_port_or_error_t minios_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_h return port; } -static evtchn_port_or_error_t minios_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h) +evtchn_port_or_error_t xc_evtchn_pending(xc_evtchn *xce) { - int fd = (int)h; + int fd = xce->fd; struct evtchn_port_info *port_info; unsigned long flags; evtchn_port_t ret = -1; @@ -402,28 +405,12 @@ static evtchn_port_or_error_t minios_evtchn_pending(xc_evtchn *xce, xc_osdep_han return ret; } -static int minios_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) +int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port) { unmask_evtchn(port); return 0; } -static struct xc_osdep_ops minios_evtchn_ops = { - .open = &minios_evtchn_open, - .close = &minios_evtchn_close, - - .u.evtchn = { - .fd = &minios_evtchn_fd, - .notify = &minios_evtchn_notify, - .bind_unbound_port = &minios_evtchn_bind_unbound_port, - .bind_interdomain = &minios_evtchn_bind_interdomain, - .bind_virq = &minios_evtchn_bind_virq, - .unbind = &minios_evtchn_unbind, - .pending = &minios_evtchn_pending, - .unmask = &minios_evtchn_unmask, - }, -}; - /* Optionally flush file to disk and discard page cache */ void discard_file_cache(xc_interface *xch, int fd, int flush) { @@ -523,8 +510,6 @@ static struct xc_osdep_ops *minios_osdep_init(xc_interface *xch, enum xc_osdep_t { case XC_OSDEP_PRIVCMD: return &minios_privcmd_ops; - case XC_OSDEP_EVTCHN: - return &minios_evtchn_ops; case XC_OSDEP_GNTTAB: return &minios_gnttab_ops; default: diff --git a/tools/libxc/xc_netbsd.c b/tools/libxc/xc_netbsd.c index 54f1d7ba2a..b1b828f78c 100644 --- a/tools/libxc/xc_netbsd.c +++ b/tools/libxc/xc_netbsd.c @@ -225,29 +225,31 @@ static struct xc_osdep_ops netbsd_privcmd_ops = { #define EVTCHN_DEV_NAME "/dev/xenevt" -static xc_osdep_handle netbsd_evtchn_open(xc_evtchn *xce) +int osdep_evtchn_open(xc_evtchn *xce) { int fd = open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR); if ( fd == -1 ) - return XC_OSDEP_OPEN_ERROR; - - return (xc_osdep_handle)fd; + return -1; + xce->fd = fd; + return 0; } -static int netbsd_evtchn_close(xc_evtchn *xce, xc_osdep_handle h) +int osdep_evtchn_close(xc_evtchn *xce, xc_osdep_handle h) { - int fd = (int)h; - return close(fd); + if ( xce->fd == -1 ) + return 0; + + return close(xce->fd); } -static int netbsd_evtchn_fd(xc_evtchn *xce, xc_osdep_handle h) +int xc_evtchn_fd(xc_evtchn *xce) { - return (int)h; + return xce->fd; } -static int netbsd_evtchn_notify(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) +int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) { - int fd = (int)h; + int fd = xce->fd; struct ioctl_evtchn_notify notify; notify.port = port; @@ -255,10 +257,9 @@ static int netbsd_evtchn_notify(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify); } -static evtchn_port_or_error_t -netbsd_evtchn_bind_unbound_port(xc_evtchn * xce, xc_osdep_handle h, int domid) +evtchn_port_or_error_t xc_evtchn_bind_unbound_port(xc_evtchn * xce, int domid) { - int fd = (int)h; + int fd = xce->fd; struct ioctl_evtchn_bind_unbound_port bind; int ret; @@ -271,11 +272,10 @@ netbsd_evtchn_bind_unbound_port(xc_evtchn * xce, xc_osdep_handle h, int domid) return -1; } -static evtchn_port_or_error_t -netbsd_evtchn_bind_interdomain(xc_evtchn *xce, xc_osdep_handle h, int domid, - evtchn_port_t remote_port) +evtchn_port_or_error_t xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, + evtchn_port_t remote_port) { - int fd = (int)h; + int fd = xce->fd; struct ioctl_evtchn_bind_interdomain bind; int ret; @@ -289,9 +289,9 @@ netbsd_evtchn_bind_interdomain(xc_evtchn *xce, xc_osdep_handle h, int domid, return -1; } -static int netbsd_evtchn_unbind(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) +int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port) { - int fd = (int)h; + int fd = xce->fd; struct ioctl_evtchn_unbind unbind; unbind.port = port; @@ -299,10 +299,9 @@ static int netbsd_evtchn_unbind(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind); } -static evtchn_port_or_error_t -netbsd_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq) +evtchn_port_or_error_t xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) { - int fd = (int)h; + int fd = xce->fd; struct ioctl_evtchn_bind_virq bind; int err; @@ -315,10 +314,9 @@ netbsd_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq) return bind.port; } -static evtchn_port_or_error_t -netbsd_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h) +evtchn_port_or_error_t xc_evtchn_pending(xc_evtchn *xce) { - int fd = (int)h; + int fd = xce->fd; evtchn_port_t port; if ( read_exact(fd, (char *)&port, sizeof(port)) == -1 ) @@ -327,28 +325,12 @@ netbsd_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h) return port; } -static int netbsd_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) +int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port) { - int fd = (int)h; + int fd = xce->fd; return write_exact(fd, (char *)&port, sizeof(port)); } -static struct xc_osdep_ops netbsd_evtchn_ops = { - .open = &netbsd_evtchn_open, - .close = &netbsd_evtchn_close, - - .u.evtchn = { - .fd = &netbsd_evtchn_fd, - .notify = &netbsd_evtchn_notify, - .bind_unbound_port = &netbsd_evtchn_bind_unbound_port, - .bind_interdomain = &netbsd_evtchn_bind_interdomain, - .bind_virq = &netbsd_evtchn_bind_virq, - .unbind = &netbsd_evtchn_unbind, - .pending = &netbsd_evtchn_pending, - .unmask = &netbsd_evtchn_unmask, - }, -}; - /* Optionally flush file to disk and discard page cache */ void discard_file_cache(xc_interface *xch, int fd, int flush) { @@ -395,8 +377,6 @@ static struct xc_osdep_ops *netbsd_osdep_init(xc_interface *xch, enum xc_osdep_t { case XC_OSDEP_PRIVCMD: return &netbsd_privcmd_ops; - case XC_OSDEP_EVTCHN: - return &netbsd_evtchn_ops; default: return NULL; } diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c index 6c0c0d62a0..cb79f227c9 100644 --- a/tools/libxc/xc_private.c +++ b/tools/libxc/xc_private.c @@ -119,7 +119,6 @@ static const char *xc_osdep_type_name(enum xc_osdep_type type) switch ( type ) { case XC_OSDEP_PRIVCMD: return "privcmd"; - case XC_OSDEP_EVTCHN: return "evtchn"; case XC_OSDEP_GNTTAB: return "gnttab"; case XC_OSDEP_GNTSHR: return "gntshr"; } @@ -252,20 +251,44 @@ int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall) return xch->ops->u.privcmd.hypercall(xch, xch->ops_handle, hypercall); } -xc_evtchn *xc_evtchn_open(xentoollog_logger *logger, - unsigned open_flags) +xc_evtchn *xc_evtchn_open(xentoollog_logger *logger, unsigned open_flags) { - xc_evtchn *xce; + xc_evtchn *xce = malloc(sizeof(*xce)); + int rc; - xce = xc_interface_open_common(logger, NULL, open_flags, - XC_OSDEP_EVTCHN); + if (!xce) return NULL; + + xce->fd = -1; + xce->logger = logger; + xce->logger_tofree = NULL; + + if (!xce->logger) { + xce->logger = xce->logger_tofree = + (xentoollog_logger*) + xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0); + if (!xce->logger) goto err; + } + + rc = osdep_evtchn_open(xce); + if ( rc < 0 ) goto err; return xce; + +err: + osdep_evtchn_close(xce); + xtl_logger_destroy(xce->logger_tofree); + free(xce); + return NULL; } int xc_evtchn_close(xc_evtchn *xce) { - return xc_interface_close_common(xce); + int rc; + + rc = osdep_evtchn_close(xce); + xtl_logger_destroy(xce->logger_tofree); + free(xce); + return rc; } xc_gnttab *xc_gnttab_open(xentoollog_logger *logger, diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h index f603c15d29..f4d155a275 100644 --- a/tools/libxc/xc_private.h +++ b/tools/libxc/xc_private.h @@ -123,6 +123,13 @@ struct xc_interface_core { xc_osdep_handle ops_handle; /* opaque data for xc_osdep_ops */ }; +struct xenevtchn_handle { + xentoollog_logger *logger, *logger_tofree; + int fd; +}; +int osdep_evtchn_open(xc_evtchn *xce); +int osdep_evtchn_close(xc_evtchn *xce); + 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, @@ -446,3 +453,13 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param, uint32_t *port); #endif /* __XC_PRIVATE_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/tools/libxc/xc_solaris.c b/tools/libxc/xc_solaris.c index 7e5d847634..088228a1cb 100644 --- a/tools/libxc/xc_solaris.c +++ b/tools/libxc/xc_solaris.c @@ -194,33 +194,36 @@ static struct xc_osdep_ops solaris_privcmd_ops = { }, }; -static xc_osdep_handle solaris_evtchn_open(xc_evtchn *xce) +int osdep_evtchn_open(xc_evtchn *xce) { int fd; if ( (fd = open("/dev/xen/evtchn", O_RDWR)) == -1 ) { PERROR("Could not open event channel interface"); - return XC_OSDEP_OPEN_ERROR; + return -1; } - return (xc_osdep_handle)fd; + xce->fd = fd; + return 0; } -static int solaris_evtchn_close(xc_evtchn *xce, xc_osdep_handle h) +int osdep_evtchn_close(xc_evtchn *xce) { - int fd = (int)h; - return close(fd); + if ( xce->fd == -1 ) + return 0; + + return close(xce->fd); } -static int solaris_evtchn_fd(xc_evtchn *xce, xc_osdep_handle h) +int xc_evtchn_fd(xc_evtchn *xce) { - return (int)h; + return xce->fd; } -static int solaris_evtchn_notify(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) +int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) { - int fd = (int)h; + int fd = xce->fd; struct ioctl_evtchn_notify notify; notify.port = port; @@ -228,10 +231,9 @@ static int solaris_evtchn_notify(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_ return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify); } -static evtchn_port_or_error_t -solaris_evtchn_bind_unbound_port(xc_evtchn *xce, xc_osdep_handle h, int domid) +evtchn_port_or_error_t xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid) { - int fd = (int)h; + int fd = xce->fd; struct ioctl_evtchn_bind_unbound_port bind; bind.remote_domain = domid; @@ -239,11 +241,10 @@ solaris_evtchn_bind_unbound_port(xc_evtchn *xce, xc_osdep_handle h, int domid) return ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); } -evtchn_port_or_error_t -solaris_evtchn_bind_interdomain(xc_evtchn *xce, xc_osdep_handle h, int domid, - evtchn_port_t remote_port) +evtchn_port_or_error_t xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, + evtchn_port_t remote_port) { - int fd = (int)h; + int fd = xce->fd; struct ioctl_evtchn_bind_interdomain bind; bind.remote_domain = domid; @@ -252,10 +253,9 @@ solaris_evtchn_bind_interdomain(xc_evtchn *xce, xc_osdep_handle h, int domid, return ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); } -static evtchn_port_or_error_t -solaris_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq) +evtchn_port_or_error_t xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) { - int fd = (int)h; + int fd = xce->fd; struct ioctl_evtchn_bind_virq bind; bind.virq = virq; @@ -263,9 +263,9 @@ solaris_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq) return ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind); } -static int solaris_evtchn_unbind(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) +int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port) { - int fd = (int)h; + int fd = xce->fd; struct ioctl_evtchn_unbind unbind; unbind.port = port; @@ -273,10 +273,9 @@ static int solaris_evtchn_unbind(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_ return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind); } -static evtchn_port_or_error_t -solaris_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h) +evtchn_port_or_error_t xc_evtchn_pending(xc_evtchn *xce) { - int fd = (int)h; + int fd = xce->fd; evtchn_port_t port; if ( read_exact(fd, (char *)&port, sizeof(port)) == -1 ) @@ -285,28 +284,12 @@ solaris_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h) return port; } -static int solaris_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h,evtchn_port_t port) +int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port) { - int fd = (int)h; + int fd = xce->fd; return write_exact(fd, (char *)&port, sizeof(port)); } -static struct xc_osdep_ops solaris_evtchn_ops = { - .open = &solaris_evtchn_open, - .close = &solaris_evtchn_close, - - .u.evtchn = { - .fd = &solaris_evtchn_fd, - .notify = &solaris_evtchn_notify, - .bind_unbound_port = &solaris_evtchn_bind_unbound_port, - .bind_interdomain = &solaris_evtchn_bind_interdomain, - .bind_virq = &solaris_evtchn_bind_virq, - .unbind = &solaris_evtchn_unbind, - .pending = &solaris_evtchn_pending, - .unmask = &solaris_evtchn_unmask, - }, -}; - /* Optionally flush file to disk and discard page cache */ void discard_file_cache(xc_interface *xch, int fd, int flush) { @@ -324,8 +307,6 @@ static struct xc_osdep_ops *solaris_osdep_init(xc_interface *xch, enum xc_osdep_ { case XC_OSDEP_PRIVCMD: return &solaris_privcmd_ops; - case XC_OSDEP_EVTCHN: - return &solaris_evtchn_ops; default: return NULL; } diff --git a/tools/libxc/xenctrl_osdep_ENOSYS.c b/tools/libxc/xenctrl_osdep_ENOSYS.c index dd59dcda21..5182532970 100644 --- a/tools/libxc/xenctrl_osdep_ENOSYS.c +++ b/tools/libxc/xenctrl_osdep_ENOSYS.c @@ -81,90 +81,6 @@ static struct xc_osdep_ops ENOSYS_privcmd_ops = } }; -static xc_osdep_handle ENOSYS_evtchn_open(xc_interface *xce) -{ - IPRINTF(xce, "ENOSYS_evtchn: opening handle %p\n", (void *)1); - return (xc_osdep_handle)2; /*dummy*/ -} - -static int ENOSYS_evtchn_close(xc_interface *xce, xc_osdep_handle h) -{ - IPRINTF(xce, "ENOSYS_evtchn: closing handle %lx\n", h); - return 0; -} - -static int ENOSYS_evtchn_fd(xc_interface *xce, xc_osdep_handle h) -{ - IPRINTF(xce, "ENOSYS_fd %lx fd\n", h); - return (int)h; -} - -static int ENOSYS_evtchn_notify(xc_interface *xce, xc_osdep_handle h, evtchn_port_t port) -{ - IPRINTF(xce, "ENOSYS_evtchn %lx notify: %d\n", h, port); - return -ENOSYS; -} - -static int ENOSYS_evtchn_bind_unbound_port(xc_interface *xce, xc_osdep_handle h, int domid) -{ - IPRINTF(xce, "ENOSYS_evtchn %lx bind_unbound_port: dom%d\n", h, domid); - return -ENOSYS; -} - - -static int ENOSYS_evtchn_bind_interdomain(xc_interface *xce, xc_osdep_handle h, int domid, evtchn_port_t remote_port) -{ - IPRINTF(xce, "ENOSYS_evtchn %lx bind_interdomain: dmo%d %d\n", h, domid, remote_port); - return -ENOSYS; -} - - -static int ENOSYS_evtchn_bind_virq(xc_interface *xce, xc_osdep_handle h, unsigned int virq) -{ - IPRINTF(xce, "ENOSYS_evtchn %lx bind_virq: %d\n", h, virq); - return -ENOSYS; -} - - -static int ENOSYS_evtchn_unbind(xc_interface *xce, xc_osdep_handle h, evtchn_port_t port) -{ - IPRINTF(xce, "ENOSYS_evtchn %lx unbind: %d\n", h, port); - return -ENOSYS; -} - - -static evtchn_port_or_error_t ENOSYS_evtchn_pending(xc_interface *xce, xc_osdep_handle h) -{ - IPRINTF(xce, "ENOSYS_evtchn %lx pending\n", h); - return -ENOSYS; -} - -static int ENOSYS_evtchn_unmask(xc_interface *xce, xc_osdep_handle h, evtchn_port_t port) -{ - IPRINTF(xce, "ENOSYS_evtchn %lx unmask: %d\n", h, port); - return -ENOSYS; -} - -static struct xc_osdep_ops ENOSYS_evtchn_ops = { - .open = &ENOSYS_evtchn_open, - .close = &ENOSYS_evtchn_close, - - .u.evtchn = { - .fd = &ENOSYS_evtchn_fd, - - .notify = &ENOSYS_evtchn_notify, - - .bind_unbound_port = &ENOSYS_evtchn_bind_unbound_port, - .bind_interdomain = &ENOSYS_evtchn_bind_interdomain, - .bind_virq = &ENOSYS_evtchn_bind_virq, - - .unbind = &ENOSYS_evtchn_unbind, - - .pending = &ENOSYS_evtchn_pending, - .unmask = &ENOSYS_evtchn_unmask, - }, -}; - static struct xc_osdep_ops * ENOSYS_osdep_init(xc_interface *xch, enum xc_osdep_type type) { struct xc_osdep_ops *ops; @@ -180,9 +96,6 @@ static struct xc_osdep_ops * ENOSYS_osdep_init(xc_interface *xch, enum xc_osdep_ case XC_OSDEP_PRIVCMD: ops = &ENOSYS_privcmd_ops; break; - case XC_OSDEP_EVTCHN: - ops = &ENOSYS_evtchn_ops; - break; default: ops = NULL; break; diff --git a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c b/tools/ocaml/libs/eventchn/xeneventchn_stubs.c index abefd6b73d..5939e7c52c 100644 --- a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c +++ b/tools/ocaml/libs/eventchn/xeneventchn_stubs.c @@ -34,14 +34,14 @@ #include #include -#define _H(__h) ((xc_interface *)(__h)) +#define _H(__h) ((xc_evtchn *)(__h)) CAMLprim value stub_eventchn_init(void) { CAMLparam0(); CAMLlocal1(result); - xc_interface *xce = xc_evtchn_open(NULL, XC_OPENFLAG_NON_REENTRANT); + xc_evtchn *xce = xc_evtchn_open(NULL, XC_OPENFLAG_NON_REENTRANT); if (xce == NULL) caml_failwith("open failed");