[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RFC tools 4/6] tools/libxc: Remove osdep indirection for xc_evtchn
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. Note that the intention is to move this into a separate library shortly. Nested virt probably suffices for this use case now. For now only evtchn is done as a PoC, other sub-APIs will follow. One incorrect instance of using xc_interface where xc_evtchn (in ocaml stubs) is removed, this used to work because they were typedefs to the same struct, but is no longer permitted. Build tested for Linux and stubdom, but not FreeBSd, NetBSD or Solaris. Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx> --- tools/libxc/include/xenctrl.h | 2 +- tools/libxc/include/xenctrlosdep.h | 16 ----- tools/libxc/xc_evtchn.c | 45 ------------- tools/libxc/xc_freebsd_osdep.c | 79 ++++++++-------------- tools/libxc/xc_linux_osdep.c | 76 ++++++++------------- tools/libxc/xc_minios.c | 63 +++++++----------- tools/libxc/xc_netbsd.c | 72 ++++++++------------ tools/libxc/xc_private.c | 37 +++++++++-- tools/libxc/xc_private.h | 17 +++++ tools/libxc/xc_solaris.c | 71 ++++++++------------ tools/libxc/xenctrl_osdep_ENOSYS.c | 87 ------------------------- tools/ocaml/libs/eventchn/xeneventchn_stubs.c | 4 +- 12 files changed, 180 insertions(+), 389 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 50fa9e7..f7b6533 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -118,7 +118,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 e97944b..a8b27ae 100644 --- a/tools/libxc/include/xenctrlosdep.h +++ b/tools/libxc/include/xenctrlosdep.h @@ -52,7 +52,6 @@ enum xc_osdep_type { XC_OSDEP_PRIVCMD, - XC_OSDEP_EVTCHN, XC_OSDEP_GNTTAB, XC_OSDEP_GNTSHR, }; @@ -91,21 +90,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 2e0679e..e6bd25c 100644 --- a/tools/libxc/xc_evtchn.c +++ b/tools/libxc/xc_evtchn.c @@ -78,51 +78,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 e6613ef..7274274 100644 --- a/tools/libxc/xc_freebsd_osdep.c +++ b/tools/libxc/xc_freebsd_osdep.c @@ -253,34 +253,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; @@ -288,10 +286,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; @@ -300,11 +297,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; @@ -314,10 +310,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; @@ -326,10 +321,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; @@ -337,10 +331,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) ) @@ -349,33 +342,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) @@ -384,8 +359,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 2687424..3c96c76 100644 --- a/tools/libxc/xc_linux_osdep.c +++ b/tools/libxc/xc_linux_osdep.c @@ -39,10 +39,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) { @@ -457,29 +456,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; @@ -487,10 +488,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; @@ -498,11 +498,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; @@ -511,10 +510,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; @@ -522,9 +520,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; @@ -532,9 +530,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) ) @@ -543,31 +541,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); @@ -871,8 +853,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 e703684..e9c4d8b 100644 --- a/tools/libxc/xc_minios.c +++ b/tools/libxc/xc_minios.c @@ -220,20 +220,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) @@ -245,12 +248,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; @@ -282,9 +285,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; @@ -309,10 +312,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; @@ -337,9 +340,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) { @@ -353,9 +356,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; @@ -378,9 +381,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; @@ -403,28 +406,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) { @@ -524,8 +511,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 8a90ef3..f9bc100 100644 --- a/tools/libxc/xc_netbsd.c +++ b/tools/libxc/xc_netbsd.c @@ -226,29 +226,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; @@ -256,10 +258,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; @@ -272,11 +273,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; @@ -290,9 +290,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; @@ -300,10 +300,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; @@ -316,10 +315,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 ) @@ -328,28 +326,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) { @@ -396,8 +378,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 2ffebd9..9f0ada7 100644 --- a/tools/libxc/xc_private.c +++ b/tools/libxc/xc_private.c @@ -120,7 +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_EVTCHN: return "evtchn"; case XC_OSDEP_GNTTAB: return "gnttab"; case XC_OSDEP_GNTSHR: return "gntshr"; } @@ -253,20 +252,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; + + if (!xce) return NULL; + + xce->fd = -1; + xce->logger = logger; + xce->logger_tofree = NULL; - xce = xc_interface_open_common(logger, NULL, open_flags, - XC_OSDEP_EVTCHN); + 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 247a408..4c66766 100644 --- a/tools/libxc/xc_private.h +++ b/tools/libxc/xc_private.h @@ -124,6 +124,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, @@ -447,3 +454,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 7257a54..8867d97 100644 --- a/tools/libxc/xc_solaris.c +++ b/tools/libxc/xc_solaris.c @@ -195,33 +195,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; @@ -229,10 +232,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; @@ -240,11 +242,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; @@ -253,10 +254,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; @@ -264,9 +264,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; @@ -274,10 +274,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 ) @@ -286,28 +285,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) { @@ -325,8 +308,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 dd59dcd..5182532 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 abefd6b..5939e7c 100644 --- a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c +++ b/tools/ocaml/libs/eventchn/xeneventchn_stubs.c @@ -34,14 +34,14 @@ #include <caml/callback.h> #include <caml/fail.h> -#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"); -- 1.7.10.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |