aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorIan Campbell <ian.campbell@citrix.com>2010-12-23 15:25:57 +0000
committerIan Campbell <ian.campbell@citrix.com>2010-12-23 15:25:57 +0000
commit3e446a35ee82c738367e8f90e3bc9166687043a8 (patch)
treed2ed5fd210a798cb5c54007a08e8bd2b9e9a221f /tools
parent252cb308e37470915d0f64c730e4e2e829ec2512 (diff)
downloadxen-3e446a35ee82c738367e8f90e3bc9166687043a8.tar.gz
xen-3e446a35ee82c738367e8f90e3bc9166687043a8.tar.bz2
xen-3e446a35ee82c738367e8f90e3bc9166687043a8.zip
libxc: convert evtchn interfaces to use an opaque handle type
This makes the interface consistent with the changes made to the main interface in 21483:779c0ef9682c. Also fix some references to "struct xc_interface" which should have been simply "xc_interface" in tools/xenpaging, and update QEMU_TAG to pull in the corresponding qemu change. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/console/daemon/io.c32
-rw-r--r--tools/fs-back/fs-backend.c12
-rw-r--r--tools/fs-back/fs-backend.h2
-rw-r--r--tools/libxc/xc_dom_elfloader.c4
-rw-r--r--tools/libxc/xc_domain_restore.c2
-rw-r--r--tools/libxc/xc_linux.c42
-rw-r--r--tools/libxc/xc_minios.c91
-rw-r--r--tools/libxc/xc_netbsd.c42
-rw-r--r--tools/libxc/xc_private.c43
-rw-r--r--tools/libxc/xc_private.h15
-rw-r--r--tools/libxc/xc_solaris.c38
-rw-r--r--tools/libxc/xc_suspend.c6
-rw-r--r--tools/libxc/xenctrl.h29
-rw-r--r--tools/libxc/xenguest.h6
-rw-r--r--tools/libxl/libxl_dom.c12
-rw-r--r--tools/misc/xen-hptool.c9
-rw-r--r--tools/python/xen/lowlevel/checkpoint/checkpoint.h2
-rw-r--r--tools/python/xen/lowlevel/checkpoint/libcheckpoint.c12
-rw-r--r--tools/xcutils/xc_save.c11
-rw-r--r--tools/xenmon/xenbaked.c10
-rw-r--r--tools/xenpaging/mem_event.h2
-rw-r--r--tools/xenpaging/policy_default.c2
-rw-r--r--tools/xenpaging/xc.c12
-rw-r--r--tools/xenpaging/xc.h4
-rw-r--r--tools/xenpaging/xenpaging.c14
-rw-r--r--tools/xenstore/xenstored_core.c6
-rw-r--r--tools/xenstore/xenstored_domain.c11
-rw-r--r--tools/xenstore/xenstored_domain.h3
-rw-r--r--tools/xentrace/xentrace.c15
29 files changed, 263 insertions, 226 deletions
diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 4b7f58f4a0..b6d41de99c 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -68,7 +68,7 @@ static int log_time_guest_needts = 1;
static int log_hv_fd = -1;
static evtchn_port_or_error_t log_hv_evtchn = -1;
static xc_interface *xch; /* why does xenconsoled have two xc handles ? */
-static int xce_handle = -1;
+static xc_evtchn *xce_handle = NULL;
struct buffer {
char *data;
@@ -90,7 +90,7 @@ struct domain {
int ring_ref;
evtchn_port_or_error_t local_port;
evtchn_port_or_error_t remote_port;
- int xce_handle;
+ xc_evtchn *xce_handle;
struct xencons_interface *interface;
int event_count;
long long next_period;
@@ -547,13 +547,13 @@ static int domain_create_ring(struct domain *dom)
dom->local_port = -1;
dom->remote_port = -1;
- if (dom->xce_handle != -1)
+ if (dom->xce_handle != NULL)
xc_evtchn_close(dom->xce_handle);
/* Opening evtchn independently for each console is a bit
* wasteful, but that's how the code is structured... */
- dom->xce_handle = xc_evtchn_open();
- if (dom->xce_handle == -1) {
+ dom->xce_handle = xc_evtchn_open(NULL, 0);
+ if (dom->xce_handle == NULL) {
err = errno;
goto out;
}
@@ -564,7 +564,7 @@ static int domain_create_ring(struct domain *dom)
if (rc == -1) {
err = errno;
xc_evtchn_close(dom->xce_handle);
- dom->xce_handle = -1;
+ dom->xce_handle = NULL;
goto out;
}
dom->local_port = rc;
@@ -574,7 +574,7 @@ static int domain_create_ring(struct domain *dom)
if (!domain_create_tty(dom)) {
err = errno;
xc_evtchn_close(dom->xce_handle);
- dom->xce_handle = -1;
+ dom->xce_handle = NULL;
dom->local_port = -1;
dom->remote_port = -1;
goto out;
@@ -655,7 +655,7 @@ static struct domain *create_domain(int domid)
dom->local_port = -1;
dom->remote_port = -1;
dom->interface = NULL;
- dom->xce_handle = -1;
+ dom->xce_handle = NULL;
if (!watch_domain(dom, true))
goto out;
@@ -722,9 +722,9 @@ static void shutdown_domain(struct domain *d)
if (d->interface != NULL)
munmap(d->interface, getpagesize());
d->interface = NULL;
- if (d->xce_handle != -1)
+ if (d->xce_handle != NULL)
xc_evtchn_close(d->xce_handle);
- d->xce_handle = -1;
+ d->xce_handle = NULL;
}
void enum_domains(void)
@@ -933,8 +933,8 @@ void handle_io(void)
errno, strerror(errno));
goto out;
}
- xce_handle = xc_evtchn_open();
- if (xce_handle == -1) {
+ xce_handle = xc_evtchn_open(NULL, 0);
+ if (xce_handle == NULL) {
dolog(LOG_ERR, "Failed to open xce handle: %d (%s)",
errno, strerror(errno));
goto out;
@@ -994,7 +994,7 @@ void handle_io(void)
if (!next_timeout ||
d->next_period < next_timeout)
next_timeout = d->next_period;
- } else if (d->xce_handle != -1) {
+ } else if (d->xce_handle != NULL) {
if (discard_overflowed_data ||
!d->buffer.max_capacity ||
d->buffer.size < d->buffer.max_capacity) {
@@ -1055,7 +1055,7 @@ void handle_io(void)
for (d = dom_head; d; d = n) {
n = d->next;
if (d->event_count < RATE_LIMIT_ALLOWANCE) {
- if (d->xce_handle != -1 &&
+ if (d->xce_handle != NULL &&
FD_ISSET(xc_evtchn_fd(d->xce_handle),
&readfds))
handle_ring_read(d);
@@ -1083,9 +1083,9 @@ void handle_io(void)
xc_interface_close(xch);
xch = 0;
}
- if (xce_handle != -1) {
+ if (xce_handle != NULL) {
xc_evtchn_close(xce_handle);
- xce_handle = -1;
+ xce_handle = NULL;
}
log_hv_evtchn = -1;
}
diff --git a/tools/fs-back/fs-backend.c b/tools/fs-back/fs-backend.c
index 1737baf9a2..e09a4f70af 100644
--- a/tools/fs-back/fs-backend.c
+++ b/tools/fs-back/fs-backend.c
@@ -228,9 +228,9 @@ static void handle_connection(int frontend_dom_id, int export_id, char *frontend
FS_DEBUG("ERROR: failed to write backend node on xenbus\n");
goto error;
}
- mount->evth = -1;
- mount->evth = xc_evtchn_open();
- if (mount->evth < 0) {
+ mount->evth = NULL;
+ mount->evth = xc_evtchn_open(NULL, 0);
+ if (mount->evth == NULL) {
FS_DEBUG("ERROR: Couldn't open evtchn!\n");
goto error;
}
@@ -289,7 +289,7 @@ error:
xc_gnttab_close(mount->xch, mount->gnth);
if (mount->local_evtchn > 0)
xc_evtchn_unbind(mount->evth, mount->local_evtchn);
- if (mount->evth > 0)
+ if (mount->evth != NULL)
xc_evtchn_close(mount->evth);
if (mount->xch)
xc_interface_close(mount->xch);
@@ -343,8 +343,8 @@ static void await_connections(void)
FD_SET(tfd, &fds);
ret = select(tfd + 1, &fds, NULL, NULL, &timeout);
if (ret < 0) {
- FS_DEBUG("fd %d is bogus, closing the related connection\n", tfd);
- pointer->evth = fd;
+ FS_DEBUG("fd %d is bogus, closing the related connection %p\n", tfd, pointer->evth);
+ /*pointer->evth = fd;*/
terminate_mount_request(pointer);
continue;
}
diff --git a/tools/fs-back/fs-backend.h b/tools/fs-back/fs-backend.h
index 9ffc9c2854..37f851cc63 100644
--- a/tools/fs-back/fs-backend.h
+++ b/tools/fs-back/fs-backend.h
@@ -45,7 +45,7 @@ struct fs_mount
grant_ref_t grefs[MAX_RING_SIZE];
evtchn_port_t remote_evtchn;
xc_interface *xch; /* just for error logging, so a dummy */
- int evth; /* Handle to the event channel */
+ xc_evtchn *evth; /* Handle to the event channel */
evtchn_port_t local_evtchn;
int gnth;
int shared_ring_size; /* in pages */
diff --git a/tools/libxc/xc_dom_elfloader.c b/tools/libxc/xc_dom_elfloader.c
index 9b6a22703c..9114bfb333 100644
--- a/tools/libxc/xc_dom_elfloader.c
+++ b/tools/libxc/xc_dom_elfloader.c
@@ -35,7 +35,7 @@
static void log_callback(struct elf_binary *elf, void *caller_data,
int iserr, const char *fmt, va_list al) {
- struct xc_interface *xch = caller_data;
+ xc_interface *xch = caller_data;
xc_reportv(xch,
xch->dombuild_logger ? xch->dombuild_logger : xch->error_handler,
@@ -44,7 +44,7 @@ static void log_callback(struct elf_binary *elf, void *caller_data,
fmt, al);
}
-void xc_elf_set_logfile(struct xc_interface *xch, struct elf_binary *elf,
+void xc_elf_set_logfile(xc_interface *xch, struct elf_binary *elf,
int verbose) {
elf_set_log(elf, log_callback, xch, verbose);
}
diff --git a/tools/libxc/xc_domain_restore.c b/tools/libxc/xc_domain_restore.c
index f868283059..d895710a7b 100644
--- a/tools/libxc/xc_domain_restore.c
+++ b/tools/libxc/xc_domain_restore.c
@@ -49,7 +49,7 @@ struct restore_ctx {
#define HEARTBEAT_MS 1000
#ifndef __MINIOS__
-static ssize_t rdexact(struct xc_interface *xch, struct restore_ctx *ctx,
+static ssize_t rdexact(xc_interface *xch, struct restore_ctx *ctx,
int fd, void* buf, size_t size)
{
size_t offset = 0;
diff --git a/tools/libxc/xc_linux.c b/tools/libxc/xc_linux.c
index 63b89b4786..f2a24c3ab5 100644
--- a/tools/libxc/xc_linux.c
+++ b/tools/libxc/xc_linux.c
@@ -68,9 +68,9 @@ int xc_interface_open_core(xc_interface *xch)
return -1;
}
-int xc_interface_close_core(xc_interface *xch, int fd)
+int xc_interface_close_core(xc_interface *xch)
{
- return close(fd);
+ return close(xch->fd);
}
static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom,
@@ -327,42 +327,42 @@ int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
#define DEVXEN "/dev/xen/"
-int xc_evtchn_open(void)
+int xc_evtchn_open_core(xc_evtchn *xce)
{
return open(DEVXEN "evtchn", O_RDWR);
}
-int xc_evtchn_close(int xce_handle)
+int xc_evtchn_close_core(xc_evtchn *xce)
{
- return close(xce_handle);
+ return close(xce->fd);
}
-int xc_evtchn_fd(int xce_handle)
+int xc_evtchn_fd(xc_evtchn *xce)
{
- return xce_handle;
+ return xce->fd;
}
-int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
+int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port)
{
struct ioctl_evtchn_notify notify;
notify.port = port;
- return ioctl(xce_handle, IOCTL_EVTCHN_NOTIFY, &notify);
+ return ioctl(xce->fd, IOCTL_EVTCHN_NOTIFY, &notify);
}
evtchn_port_or_error_t
-xc_evtchn_bind_unbound_port(int xce_handle, int domid)
+xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid)
{
struct ioctl_evtchn_bind_unbound_port bind;
bind.remote_domain = domid;
- return ioctl(xce_handle, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
+ return ioctl(xce->fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
}
evtchn_port_or_error_t
-xc_evtchn_bind_interdomain(int xce_handle, int domid,
+xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid,
evtchn_port_t remote_port)
{
struct ioctl_evtchn_bind_interdomain bind;
@@ -370,42 +370,42 @@ xc_evtchn_bind_interdomain(int xce_handle, int domid,
bind.remote_domain = domid;
bind.remote_port = remote_port;
- return ioctl(xce_handle, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
+ return ioctl(xce->fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
}
evtchn_port_or_error_t
-xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
+xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq)
{
struct ioctl_evtchn_bind_virq bind;
bind.virq = virq;
- return ioctl(xce_handle, IOCTL_EVTCHN_BIND_VIRQ, &bind);
+ return ioctl(xce->fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
}
-int xc_evtchn_unbind(int xce_handle, evtchn_port_t port)
+int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port)
{
struct ioctl_evtchn_unbind unbind;
unbind.port = port;
- return ioctl(xce_handle, IOCTL_EVTCHN_UNBIND, &unbind);
+ return ioctl(xce->fd, IOCTL_EVTCHN_UNBIND, &unbind);
}
evtchn_port_or_error_t
-xc_evtchn_pending(int xce_handle)
+xc_evtchn_pending(xc_evtchn *xce)
{
evtchn_port_t port;
- if ( read_exact(xce_handle, (char *)&port, sizeof(port)) == -1 )
+ if ( read_exact(xce->fd, (char *)&port, sizeof(port)) == -1 )
return -1;
return port;
}
-int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
+int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
{
- return write_exact(xce_handle, (char *)&port, sizeof(port));
+ return write_exact(xce->fd, (char *)&port, sizeof(port));
}
/* Optionally flush file to disk and discard page cache */
diff --git a/tools/libxc/xc_minios.c b/tools/libxc/xc_minios.c
index 146816b1d3..c8b0007ce6 100644
--- a/tools/libxc/xc_minios.c
+++ b/tools/libxc/xc_minios.c
@@ -44,6 +44,9 @@ void minios_interface_close_fd(int fd);
void minios_evtchn_close_fd(int fd);
void minios_gnttab_close_fd(int fd);
+extern void minios_interface_close_fd(int fd);
+extern void minios_evtchn_close_fd(int fd);
+
extern struct wait_queue_head event_queue;
int xc_interface_open_core(xc_interface *xch)
@@ -51,9 +54,9 @@ int xc_interface_open_core(xc_interface *xch)
return alloc_fd(FTYPE_XC);
}
-int xc_interface_close_core(xc_interface *xch, int fd)
+int xc_interface_close_core(xc_interface *xch)
{
- return close(fd);
+ return close(xch->fd);
}
void minios_interface_close_fd(int fd)
@@ -169,7 +172,7 @@ int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
return call.result;
}
-int xc_evtchn_open(void)
+int xc_evtchn_open_core(xc_evtchn *xce)
{
int fd = alloc_fd(FTYPE_EVTCHN), i;
for (i = 0; i < MAX_EVTCHN_PORTS; i++) {
@@ -180,9 +183,9 @@ int xc_evtchn_open(void)
return fd;
}
-int xc_evtchn_close(int xce_handle)
+int xc_evtchn_close_core(xc_evtchn *xce)
{
- return close(xce_handle);
+ return close(xce->fd);
}
void minios_evtchn_close_fd(int fd)
@@ -194,12 +197,12 @@ void minios_evtchn_close_fd(int fd)
files[fd].type = FTYPE_NONE;
}
-int xc_evtchn_fd(int xce_handle)
+int xc_evtchn_fd(xc_evtchn *xce)
{
- return xce_handle;
+ return xce->fd;
}
-int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
+int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port)
{
int ret;
@@ -213,144 +216,144 @@ int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
}
/* XXX Note: This is not threadsafe */
-static int port_alloc(int xce_handle) {
+static int port_alloc(int fd) {
int i;
for (i= 0; i < MAX_EVTCHN_PORTS; i++)
- if (files[xce_handle].evtchn.ports[i].port == -1)
+ if (files[fd].evtchn.ports[i].port == -1)
break;
if (i == MAX_EVTCHN_PORTS) {
printf("Too many ports in xc handle\n");
errno = EMFILE;
return -1;
}
- files[xce_handle].evtchn.ports[i].pending = 0;
+ files[fd].evtchn.ports[i].pending = 0;
return i;
}
static void evtchn_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
{
- int xce_handle = (intptr_t) data;
+ int fd = (int)(intptr_t)data;
int i;
- assert(files[xce_handle].type == FTYPE_EVTCHN);
+ assert(files[fd].type == FTYPE_EVTCHN);
mask_evtchn(port);
for (i= 0; i < MAX_EVTCHN_PORTS; i++)
- if (files[xce_handle].evtchn.ports[i].port == port)
+ if (files[fd].evtchn.ports[i].port == port)
break;
if (i == MAX_EVTCHN_PORTS) {
- printk("Unknown port for handle %d\n", xce_handle);
+ printk("Unknown port for handle %d\n", fd);
return;
}
- files[xce_handle].evtchn.ports[i].pending = 1;
- files[xce_handle].read = 1;
+ files[fd].evtchn.ports[i].pending = 1;
+ files[fd].read = 1;
wake_up(&event_queue);
}
-evtchn_port_or_error_t xc_evtchn_bind_unbound_port(int xce_handle, int domid)
+evtchn_port_or_error_t xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid)
{
int ret, i;
evtchn_port_t port;
assert(get_current() == main_thread);
- i = port_alloc(xce_handle);
+ i = port_alloc(xce->fd);
if (i == -1)
return -1;
printf("xc_evtchn_bind_unbound_port(%d)", domid);
- ret = evtchn_alloc_unbound(domid, evtchn_handler, (void*)(intptr_t)xce_handle, &port);
+ ret = evtchn_alloc_unbound(domid, evtchn_handler, (void*)(intptr_t)xce->fd, &port);
printf(" = %d\n", ret);
if (ret < 0) {
errno = -ret;
return -1;
}
- files[xce_handle].evtchn.ports[i].bound = 1;
- files[xce_handle].evtchn.ports[i].port = port;
+ files[xce->fd].evtchn.ports[i].bound = 1;
+ files[xce->fd].evtchn.ports[i].port = port;
unmask_evtchn(port);
return port;
}
-evtchn_port_or_error_t xc_evtchn_bind_interdomain(int xce_handle, int domid,
+evtchn_port_or_error_t xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid,
evtchn_port_t remote_port)
{
evtchn_port_t local_port;
int ret, i;
assert(get_current() == main_thread);
- i = port_alloc(xce_handle);
+ i = port_alloc(xce->fd);
if (i == -1)
return -1;
printf("xc_evtchn_bind_interdomain(%d, %"PRId32")", domid, remote_port);
- ret = evtchn_bind_interdomain(domid, remote_port, evtchn_handler, (void*)(intptr_t)xce_handle, &local_port);
+ ret = evtchn_bind_interdomain(domid, remote_port, evtchn_handler, (void*)(intptr_t)xce->fd, &local_port);
printf(" = %d\n", ret);
if (ret < 0) {
errno = -ret;
return -1;
}
- files[xce_handle].evtchn.ports[i].bound = 1;
- files[xce_handle].evtchn.ports[i].port = local_port;
+ files[xce->fd].evtchn.ports[i].bound = 1;
+ files[xce->fd].evtchn.ports[i].port = local_port;
unmask_evtchn(local_port);
return local_port;
}
-int xc_evtchn_unbind(int xce_handle, evtchn_port_t port)
+int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port)
{
int i;
for (i = 0; i < MAX_EVTCHN_PORTS; i++)
- if (files[xce_handle].evtchn.ports[i].port == port) {
- files[xce_handle].evtchn.ports[i].port = -1;
+ if (files[xce->fd].evtchn.ports[i].port == port) {
+ files[xce->fd].evtchn.ports[i].port = -1;
break;
}
if (i == MAX_EVTCHN_PORTS) {
- printf("Warning: couldn't find port %"PRId32" for xc handle %x\n", port, xce_handle);
+ printf("Warning: couldn't find port %"PRId32" for xc handle %x\n", port, xce->fd);
errno = -EINVAL;
return -1;
}
- files[xce_handle].evtchn.ports[i].bound = 0;
+ files[xce->fd].evtchn.ports[i].bound = 0;
unbind_evtchn(port);
return 0;
}
-evtchn_port_or_error_t xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
+evtchn_port_or_error_t xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq)
{
evtchn_port_t port;
int i;
assert(get_current() == main_thread);
- i = port_alloc(xce_handle);
+ i = port_alloc(xce->fd);
if (i == -1)
return -1;
printf("xc_evtchn_bind_virq(%d)", virq);
- port = bind_virq(virq, evtchn_handler, (void*)(intptr_t)xce_handle);
+ port = bind_virq(virq, evtchn_handler, (void*)(intptr_t)xce->fd);
if (port < 0) {
errno = -port;
return -1;
}
- files[xce_handle].evtchn.ports[i].bound = 1;
- files[xce_handle].evtchn.ports[i].port = port;
+ files[xce->fd].evtchn.ports[i].bound = 1;
+ files[xce->fd].evtchn.ports[i].port = port;
unmask_evtchn(port);
return port;
}
-evtchn_port_or_error_t xc_evtchn_pending(int xce_handle)
+evtchn_port_or_error_t xc_evtchn_pending(xc_evtchn *xce)
{
int i;
unsigned long flags;
evtchn_port_t ret = -1;
local_irq_save(flags);
- files[xce_handle].read = 0;
+ files[xce->fd].read = 0;
for (i = 0; i < MAX_EVTCHN_PORTS; i++) {
- evtchn_port_t port = files[xce_handle].evtchn.ports[i].port;
- if (port != -1 && files[xce_handle].evtchn.ports[i].pending) {
+ evtchn_port_t port = files[xce->fd].evtchn.ports[i].port;
+ if (port != -1 && files[xce->fd].evtchn.ports[i].pending) {
if (ret == -1) {
ret = port;
- files[xce_handle].evtchn.ports[i].pending = 0;
+ files[xce->fd].evtchn.ports[i].pending = 0;
} else {
- files[xce_handle].read = 1;
+ files[xce->fd].read = 1;
break;
}
}
@@ -359,7 +362,7 @@ evtchn_port_or_error_t xc_evtchn_pending(int xce_handle)
return ret;
}
-int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
+int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
{
unmask_evtchn(port);
return 0;
diff --git a/tools/libxc/xc_netbsd.c b/tools/libxc/xc_netbsd.c
index c6bf227684..f60d0d4154 100644
--- a/tools/libxc/xc_netbsd.c
+++ b/tools/libxc/xc_netbsd.c
@@ -60,9 +60,9 @@ int xc_interface_open_core(xc_interface *xch)
return -1;
}
-int xc_interface_close_core(xc_interface *xch, int fd)
+int xc_interface_close_core(xc_interface *xch)
{
- return close(fd);
+ return close(xch->fd);
}
void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
@@ -181,39 +181,39 @@ int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
#define EVTCHN_DEV_NAME "/dev/xenevt"
-int xc_evtchn_open(void)
+int xc_evtchn_open_core(xc_evtchn *xce)
{
return open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR);
}
-int xc_evtchn_close(int xce_handle)
+int xc_evtchn_close_core(xc_evtchn *xce)
{
- return close(xce_handle);
+ return close(xce->fd);
}
-int xc_evtchn_fd(int xce_handle)
+int xc_evtchn_fd(xc_evtchn *xce)
{
- return xce_handle;
+ return xce->fd;
}
-int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
+int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port)
{
struct ioctl_evtchn_notify notify;
notify.port = port;
- return ioctl(xce_handle, IOCTL_EVTCHN_NOTIFY, &notify);
+ return ioctl(xce->fd, IOCTL_EVTCHN_NOTIFY, &notify);
}
evtchn_port_or_error_t
-xc_evtchn_bind_unbound_port(int xce_handle, int domid)
+xc_evtchn_bind_unbound_port(xc_evtchn * xce, int domid)
{
struct ioctl_evtchn_bind_unbound_port bind;
int ret;
bind.remote_domain = domid;
- ret = ioctl(xce_handle, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
+ ret = ioctl(xce->fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
if (ret == 0)
return bind.port;
else
@@ -221,7 +221,7 @@ xc_evtchn_bind_unbound_port(int xce_handle, int domid)
}
evtchn_port_or_error_t
-xc_evtchn_bind_interdomain(int xce_handle, int domid,
+xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid,
evtchn_port_t remote_port)
{
struct ioctl_evtchn_bind_interdomain bind;
@@ -230,31 +230,31 @@ xc_evtchn_bind_interdomain(int xce_handle, int domid,
bind.remote_domain = domid;
bind.remote_port = remote_port;
- ret = ioctl(xce_handle, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
+ ret = ioctl(xce->fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
if (ret == 0)
return bind.port;
else
return -1;
}
-int xc_evtchn_unbind(int xce_handle, evtchn_port_t port)
+int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port)
{
struct ioctl_evtchn_unbind unbind;
unbind.port = port;
- return ioctl(xce_handle, IOCTL_EVTCHN_UNBIND, &unbind);
+ return ioctl(xce->fd, IOCTL_EVTCHN_UNBIND, &unbind);
}
evtchn_port_or_error_t
-xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
+xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq)
{
struct ioctl_evtchn_bind_virq bind;
int err;
bind.virq = virq;
- err = ioctl(xce_handle, IOCTL_EVTCHN_BIND_VIRQ, &bind);
+ err = ioctl(xce->fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
if (err)
return -1;
else
@@ -262,19 +262,19 @@ xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
}
evtchn_port_or_error_t
-xc_evtchn_pending(int xce_handle)
+xc_evtchn_pending(xc_evtchn *xce)
{
evtchn_port_t port;
- if ( read_exact(xce_handle, (char *)&port, sizeof(port)) == -1 )
+ if ( read_exact(xce->fd, (char *)&port, sizeof(port)) == -1 )
return -1;
return port;
}
-int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
+int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
{
- return write_exact(xce_handle, (char *)&port, sizeof(port));
+ return write_exact(xce->fd, (char *)&port, sizeof(port));
}
/* Optionally flush file to disk and discard page cache */
diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c
index 3b83a8aa5f..4cd89209fa 100644
--- a/tools/libxc/xc_private.c
+++ b/tools/libxc/xc_private.c
@@ -27,11 +27,15 @@
#include <pthread.h>
#include <assert.h>
-xc_interface *xc_interface_open(xentoollog_logger *logger,
- xentoollog_logger *dombuild_logger,
- unsigned open_flags) {
- xc_interface xch_buf, *xch = &xch_buf;
+static struct xc_interface_core *xc_interface_open_common(xentoollog_logger *logger,
+ xentoollog_logger *dombuild_logger,
+ unsigned open_flags,
+ enum xc_interface_type type,
+ int (*open_core)(struct xc_interface_core *xch))
+{
+ struct xc_interface_core xch_buf, *xch = &xch_buf;
+ xch->type = type;
xch->flags = open_flags;
xch->fd = -1;
xch->dombuild_logger_file = 0;
@@ -57,7 +61,7 @@ xc_interface *xc_interface_open(xentoollog_logger *logger,
*xch = xch_buf;
if (!(open_flags & XC_OPENFLAG_DUMMY)) {
- xch->fd = xc_interface_open_core(xch);
+ xch->fd = open_core(xch);
if (xch->fd < 0)
goto err;
}
@@ -70,7 +74,7 @@ xc_interface *xc_interface_open(xentoollog_logger *logger,
return 0;
}
-int xc_interface_close(xc_interface *xch)
+static int xc_interface_close_common(xc_interface *xch, int (*close_core)(struct xc_interface_core *xch))
{
int rc = 0;
@@ -78,7 +82,7 @@ int xc_interface_close(xc_interface *xch)
xtl_logger_destroy(xch->error_handler_tofree);
if (xch->fd >= 0) {
- rc = xc_interface_close_core(xch, xch->fd);
+ rc = close_core(xch);
if (rc) PERROR("Could not close hypervisor interface");
}
@@ -86,6 +90,31 @@ int xc_interface_close(xc_interface *xch)
return rc;
}
+xc_interface *xc_interface_open(xentoollog_logger *logger,
+ xentoollog_logger *dombuild_logger,
+ unsigned open_flags)
+{
+ return xc_interface_open_common(logger, dombuild_logger, open_flags,
+ XC_INTERFACE_PRIVCMD, &xc_interface_open_core);
+}
+
+int xc_interface_close(xc_interface *xch)
+{
+ return xc_interface_close_common(xch, &xc_interface_close_core);
+}
+
+xc_evtchn *xc_evtchn_open(xentoollog_logger *logger,
+ unsigned open_flags)
+{
+ return xc_interface_open_common(logger, NULL, open_flags,
+ XC_INTERFACE_EVTCHN, &xc_evtchn_open_core);
+}
+
+int xc_evtchn_close(xc_evtchn *xce)
+{
+ return xc_interface_close_common(xce, &xc_evtchn_close_core);
+}
+
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 153458b0fb..5cd936cb72 100644
--- a/tools/libxc/xc_private.h
+++ b/tools/libxc/xc_private.h
@@ -65,7 +65,13 @@
*/
#define MAX_PAGECACHE_USAGE (4*1024)
-struct xc_interface {
+enum xc_interface_type {
+ XC_INTERFACE_PRIVCMD,
+ XC_INTERFACE_EVTCHN,
+};
+
+struct xc_interface_core {
+ enum xc_interface_type type;
int fd;
int flags;
xentoollog_logger *error_handler, *error_handler_tofree;
@@ -257,8 +263,11 @@ static inline int do_sysctl(xc_interface *xch, struct xen_sysctl *sysctl)
int do_memory_op(xc_interface *xch, int cmd, void *arg, size_t len);
-int xc_interface_open_core(xc_interface *xch); /* returns fd, logs errors */
-int xc_interface_close_core(xc_interface *xch, int fd); /* no logging */
+int xc_interface_open_core(struct xc_interface_core *xch); /* returns fd, logs errors */
+int xc_interface_close_core(struct xc_interface_core *xch); /* no logging */
+
+int xc_evtchn_open_core(struct xc_interface_core *xce); /* returns fd, logs errors */
+int xc_evtchn_close_core(struct xc_interface_core *xce); /* no logging */
void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom,
size_t size, int prot, size_t chunksize,
diff --git a/tools/libxc/xc_solaris.c b/tools/libxc/xc_solaris.c
index b0155e1de4..40ee6f03ca 100644
--- a/tools/libxc/xc_solaris.c
+++ b/tools/libxc/xc_solaris.c
@@ -167,7 +167,7 @@ int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
(unsigned long)hypercall);
}
-int xc_evtchn_open(void)
+int xc_evtchn_open_core(xc_evtchn *xce)
{
int fd;
@@ -180,37 +180,37 @@ int xc_evtchn_open(void)
return fd;
}
-int xc_evtchn_close(int xce_handle)
+int xc_evtchn_close_core(xc_evtchn *xce)
{
- return close(xce_handle);
+ return close(xce->fd);
}
-int xc_evtchn_fd(int xce_handle)
+int xc_evtchn_fd(xc_evtchn *xce)
{
- return xce_handle;
+ return xce->fd;
}
-int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
+int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port)
{
struct ioctl_evtchn_notify notify;
notify.port = port;
- return ioctl(xce_handle, IOCTL_EVTCHN_NOTIFY, &notify);
+ return ioctl(xce->fd, IOCTL_EVTCHN_NOTIFY, &notify);
}
evtchn_port_or_error_t
-xc_evtchn_bind_unbound_port(int xce_handle, int domid)
+xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid)
{
struct ioctl_evtchn_bind_unbound_port bind;
bind.remote_domain = domid;
- return ioctl(xce_handle, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
+ return ioctl(xce->fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
}
evtchn_port_or_error_t
-xc_evtchn_bind_interdomain(int xce_handle, int domid,
+xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid,
evtchn_port_t remote_port)
{
struct ioctl_evtchn_bind_interdomain bind;
@@ -218,42 +218,42 @@ xc_evtchn_bind_interdomain(int xce_handle, int domid,
bind.remote_domain = domid;
bind.remote_port = remote_port;
- return ioctl(xce_handle, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
+ return ioctl(xce->fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
}
evtchn_port_or_error_t
-xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
+xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq)
{
struct ioctl_evtchn_bind_virq bind;
bind.virq = virq;
- return ioctl(xce_handle, IOCTL_EVTCHN_BIND_VIRQ, &bind);
+ return ioctl(xce->fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
}
-int xc_evtchn_unbind(int xce_handle, evtchn_port_t port)
+int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port)
{
struct ioctl_evtchn_unbind unbind;
unbind.port = port;
- return ioctl(xce_handle, IOCTL_EVTCHN_UNBIND, &unbind);
+ return ioctl(xce->fd, IOCTL_EVTCHN_UNBIND, &unbind);
}
evtchn_port_or_error_t
-xc_evtchn_pending(int xce_handle)
+xc_evtchn_pending(xc_evtchn *xce)
{
evtchn_port_t port;
- if ( read_exact(xce_handle, (char *)&port, sizeof(port)) == -1 )
+ if ( read_exact(xce->fd, (char *)&port, sizeof(port)) == -1 )
return -1;
return port;
}
-int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
+int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
{
- return write_exact(xce_handle, (char *)&port, sizeof(port));
+ return write_exact(xce->fd, (char *)&port, sizeof(port));
}
/* Optionally flush file to disk and discard page cache */
diff --git a/tools/libxc/xc_suspend.c b/tools/libxc/xc_suspend.c
index 52e8a33707..1ace411860 100644
--- a/tools/libxc/xc_suspend.c
+++ b/tools/libxc/xc_suspend.c
@@ -75,7 +75,7 @@ static int unlock_suspend_event(xc_interface *xch, int domid)
return -EPERM;
}
-int xc_await_suspend(xc_interface *xch, int xce, int suspend_evtchn)
+int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn)
{
int rc;
@@ -94,7 +94,7 @@ int xc_await_suspend(xc_interface *xch, int xce, int suspend_evtchn)
return 0;
}
-int xc_suspend_evtchn_release(xc_interface *xch, int xce, int domid, int suspend_evtchn)
+int xc_suspend_evtchn_release(xc_interface *xch, xc_evtchn *xce, int domid, int suspend_evtchn)
{
if (suspend_evtchn >= 0)
xc_evtchn_unbind(xce, suspend_evtchn);
@@ -102,7 +102,7 @@ int xc_suspend_evtchn_release(xc_interface *xch, int xce, int domid, int suspend
return unlock_suspend_event(xch, domid);
}
-int xc_suspend_evtchn_init(xc_interface *xch, int xce, int domid, int port)
+int xc_suspend_evtchn_init(xc_interface *xch, xc_evtchn *xce, int domid, int port)
{
int rc, suspend_evtchn = -1;
diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h
index 48e7215310..abfeedb582 100644
--- a/tools/libxc/xenctrl.h
+++ b/tools/libxc/xenctrl.h
@@ -104,7 +104,8 @@
* the callback.
*/
-typedef struct xc_interface xc_interface;
+typedef struct xc_interface_core xc_interface;
+typedef struct xc_interface_core xc_evtchn;
typedef enum xc_error_code xc_error_code;
@@ -826,38 +827,38 @@ int xc_evtchn_status(xc_interface *xch, xc_evtchn_status_t *status);
*
* Before Xen pre-4.1 this function would sometimes report errors with perror.
*/
-int xc_evtchn_open(void);
+xc_evtchn *xc_evtchn_open(xentoollog_logger *logger,
+ unsigned open_flags);
/*
* Close a handle previously allocated with xc_evtchn_open().
*/
-int xc_evtchn_close(int xce_handle);
+int xc_evtchn_close(xc_evtchn *xce);
/*
- * Return an fd that can be select()ed on for further calls to
- * xc_evtchn_pending().
+ * Return an fd that can be select()ed on.
*/
-int xc_evtchn_fd(int xce_handle);
+int xc_evtchn_fd(xc_evtchn *xce);
/*
* Notify the given event channel. Returns -1 on failure, in which case
* errno will be set appropriately.
*/
-int xc_evtchn_notify(int xce_handle, evtchn_port_t port);
+int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port);
/*
* Returns a new event port awaiting interdomain connection from the given
* domain ID, or -1 on failure, in which case errno will be set appropriately.
*/
evtchn_port_or_error_t
-xc_evtchn_bind_unbound_port(int xce_handle, int domid);
+xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid);
/*
* Returns a new event port bound to the remote port for the given domain ID,
* or -1 on failure, in which case errno will be set appropriately.
*/
evtchn_port_or_error_t
-xc_evtchn_bind_interdomain(int xce_handle, int domid,
+xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid,
evtchn_port_t remote_port);
/*
@@ -865,26 +866,26 @@ xc_evtchn_bind_interdomain(int xce_handle, int domid,
* the VIRQ, or -1 on failure, in which case errno will be set appropriately.
*/
evtchn_port_or_error_t
-xc_evtchn_bind_virq(int xce_handle, unsigned int virq);
+xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq);
/*
* Unbind the given event channel. Returns -1 on failure, in which case errno
* will be set appropriately.
*/
-int xc_evtchn_unbind(int xce_handle, evtchn_port_t port);
+int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port);
/*
* Return the next event channel to become pending, or -1 on failure, in which
* case errno will be set appropriately.
*/
evtchn_port_or_error_t
-xc_evtchn_pending(int xce_handle);
+xc_evtchn_pending(xc_evtchn *xce);
/*
* Unmask the given event channel. Returns -1 on failure, in which case errno
* will be set appropriately.
*/
-int xc_evtchn_unmask(int xce_handle, evtchn_port_t port);
+int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port);
int xc_physdev_pci_access_modify(xc_interface *xch,
uint32_t domid,
@@ -1754,7 +1755,7 @@ int xc_flask_getavc_threshold(xc_interface *xc_handle);
int xc_flask_setavc_threshold(xc_interface *xc_handle, int threshold);
struct elf_binary;
-void xc_elf_set_logfile(struct xc_interface *xch, struct elf_binary *elf,
+void xc_elf_set_logfile(xc_interface *xch, struct elf_binary *elf,
int verbose);
/* Useful for callers who also use libelf. */
diff --git a/tools/libxc/xenguest.h b/tools/libxc/xenguest.h
index b9d986e20e..dd0c4cf6e8 100644
--- a/tools/libxc/xenguest.h
+++ b/tools/libxc/xenguest.h
@@ -173,11 +173,11 @@ int xc_hvm_build_mem(xc_interface *xch,
const char *image_buffer,
unsigned long image_size);
-int xc_suspend_evtchn_release(xc_interface *xch, int xce, int domid, int suspend_evtchn);
+int xc_suspend_evtchn_release(xc_interface *xch, xc_evtchn *xce, int domid, int suspend_evtchn);
-int xc_suspend_evtchn_init(xc_interface *xch, int xce, int domid, int port);
+int xc_suspend_evtchn_init(xc_interface *xch, xc_evtchn *xce, int domid, int port);
-int xc_await_suspend(xc_interface *xch, int xce, int suspend_evtchn);
+int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn);
int xc_get_bit_size(xc_interface *xch,
const char *image_name, const char *cmdline,
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index 31b057d680..7e49c5afaf 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -315,7 +315,7 @@ int libxl__domain_restore_common(libxl_ctx *ctx, uint32_t domid,
struct suspendinfo {
libxl__gc *gc;
- int xce; /* event channel handle */
+ xc_evtchn *xce; /* event channel handle */
int suspend_eventchn;
int domid;
int hvm;
@@ -419,11 +419,11 @@ int libxl__domain_suspend_common(libxl_ctx *ctx, uint32_t domid, int fd,
si.gc = &gc;
si.suspend_eventchn = -1;
- si.xce = xc_evtchn_open();
- if (si.xce < 0)
+ si.xce = xc_evtchn_open(NULL, 0);
+ if (si.xce == NULL)
goto out;
-
- if (si.xce > 0) {
+ else
+ {
port = xs_suspend_evtchn_port(si.domid);
if (port >= 0) {
@@ -447,7 +447,7 @@ int libxl__domain_suspend_common(libxl_ctx *ctx, uint32_t domid, int fd,
if (si.suspend_eventchn > 0)
xc_suspend_evtchn_release(ctx->xch, si.xce, domid, si.suspend_eventchn);
- if (si.xce > 0)
+ if (si.xce != NULL)
xc_evtchn_close(si.xce);
out:
diff --git a/tools/misc/xen-hptool.c b/tools/misc/xen-hptool.c
index cc4d6739f6..374d88315d 100644
--- a/tools/misc/xen-hptool.c
+++ b/tools/misc/xen-hptool.c
@@ -98,7 +98,7 @@ static int hp_mem_query_func(int argc, char *argv[])
extern int xs_suspend_evtchn_port(int domid);
-static int suspend_guest(xc_interface *xch, int xce, int domid, int *evtchn)
+static int suspend_guest(xc_interface *xch, xc_evtchn *xce, int domid, int *evtchn)
{
int port, rc, suspend_evtchn = -1;
@@ -192,10 +192,11 @@ static int hp_mem_offline_func(int argc, char *argv[])
}
else if (status & PG_OFFLINE_OWNED)
{
- int result, xce, suspend_evtchn = -1;
- xce = xc_evtchn_open();
+ int result, suspend_evtchn = -1;
+ xc_evtchn *xce;
+ xce = xc_evtchn_open(NULL, 0);
- if (xce < 0)
+ if (xce == NULL)
{
fprintf(stderr, "When exchange page, fail"
" to open evtchn\n");
diff --git a/tools/python/xen/lowlevel/checkpoint/checkpoint.h b/tools/python/xen/lowlevel/checkpoint/checkpoint.h
index 24db54faba..36455fbf75 100644
--- a/tools/python/xen/lowlevel/checkpoint/checkpoint.h
+++ b/tools/python/xen/lowlevel/checkpoint/checkpoint.h
@@ -19,7 +19,7 @@ typedef enum {
typedef struct {
xc_interface *xch;
- int xce; /* event channel handle */
+ xc_evtchn *xce; /* event channel handle */
struct xs_handle* xsh; /* xenstore handle */
int watching_shutdown; /* state of watch on @releaseDomain */
diff --git a/tools/python/xen/lowlevel/checkpoint/libcheckpoint.c b/tools/python/xen/lowlevel/checkpoint/libcheckpoint.c
index d7fad711de..f4d3e7fd1a 100644
--- a/tools/python/xen/lowlevel/checkpoint/libcheckpoint.c
+++ b/tools/python/xen/lowlevel/checkpoint/libcheckpoint.c
@@ -48,7 +48,7 @@ char* checkpoint_error(checkpoint_state* s)
void checkpoint_init(checkpoint_state* s)
{
s->xch = NULL;
- s->xce = -1;
+ s->xce = NULL;
s->xsh = NULL;
s->watching_shutdown = 0;
@@ -89,8 +89,8 @@ int checkpoint_open(checkpoint_state* s, unsigned int domid)
return -1;
}
- s->xce = xc_evtchn_open();
- if (s->xce < 0) {
+ s->xce = xc_evtchn_open(NULL, 0);
+ if (s->xce == NULL) {
checkpoint_close(s);
s->errstr = "could not open event channel handle";
@@ -149,9 +149,9 @@ void checkpoint_close(checkpoint_state* s)
xc_interface_close(s->xch);
s->xch = NULL;
}
- if (s->xce >= 0) {
+ if (s->xce != NULL) {
xc_evtchn_close(s->xce);
- s->xce = -1;
+ s->xce = NULL;
}
if (s->xsh) {
xs_daemon_close(s->xsh);
@@ -360,7 +360,7 @@ static int setup_suspend_evtchn(checkpoint_state* s)
static void release_suspend_evtchn(checkpoint_state *s)
{
/* TODO: teach xen to clean up if port is unbound */
- if (s->xce >= 0 && s->suspend_evtchn >= 0) {
+ if (s->xce != NULL && s->suspend_evtchn >= 0) {
xc_suspend_evtchn_release(s->xch, s->xce, s->domid, s->suspend_evtchn);
s->suspend_evtchn = -1;
}
diff --git a/tools/xcutils/xc_save.c b/tools/xcutils/xc_save.c
index 59380c4dbb..debb1bb89e 100644
--- a/tools/xcutils/xc_save.c
+++ b/tools/xcutils/xc_save.c
@@ -25,7 +25,7 @@
static struct suspendinfo {
xc_interface *xch;
- int xce; /* event channel handle */
+ xc_evtchn *xce; /* event channel handle */
int suspend_evtchn;
int domid;
unsigned int flags;
@@ -183,13 +183,12 @@ main(int argc, char **argv)
max_f = atoi(argv[4]);
si.flags = atoi(argv[5]);
- si.suspend_evtchn = si.xce = -1;
+ si.suspend_evtchn = -1;
- si.xce = xc_evtchn_open();
- if (si.xce < 0)
+ si.xce = xc_evtchn_open(NULL, 0);
+ if (si.xce == NULL)
warnx("failed to open event channel handle");
-
- if (si.xce > 0)
+ else
{
port = xs_suspend_evtchn_port(si.domid);
diff --git a/tools/xenmon/xenbaked.c b/tools/xenmon/xenbaked.c
index 478fac2bcb..985f1dd123 100644
--- a/tools/xenmon/xenbaked.c
+++ b/tools/xenmon/xenbaked.c
@@ -268,7 +268,7 @@ static void log_event(int event_id)
}
int virq_port;
-int xce_handle = -1;
+xc_evtchn *xce_handle = NULL;
/* Returns the event channel handle. */
/* Stolen from xenstore code */
@@ -280,16 +280,16 @@ static int eventchn_init(void)
if (0)
return -1;
- xce_handle = xc_evtchn_open();
+ xce_handle = xc_evtchn_open(NULL, 0);
- if (xce_handle < 0)
+ if (xce_handle == NULL)
perror("Failed to open evtchn device");
if ((rc = xc_evtchn_bind_virq(xce_handle, VIRQ_TBUF)) == -1)
perror("Failed to bind to domain exception virq port");
virq_port = rc;
- return xce_handle;
+ return xce_handle == NULL ? -1 : 0;
}
static void wait_for_event(void)
@@ -300,7 +300,7 @@ static void wait_for_event(void)
struct timeval tv;
int evtchn_fd;
- if (xce_handle < 0) {
+ if (xce_handle == NULL) {
nanosleep(&opts.poll_sleep, NULL);
return;
}
diff --git a/tools/xenpaging/mem_event.h b/tools/xenpaging/mem_event.h
index 9f7bdf008a..807b21816b 100644
--- a/tools/xenpaging/mem_event.h
+++ b/tools/xenpaging/mem_event.h
@@ -40,7 +40,7 @@
typedef struct mem_event {
domid_t domain_id;
- int xce_handle;
+ xc_evtchn *xce_handle;
int port;
mem_event_back_ring_t back_ring;
mem_event_shared_page_t *shared_page;
diff --git a/tools/xenpaging/policy_default.c b/tools/xenpaging/policy_default.c
index ea32407ca4..e1e727991d 100644
--- a/tools/xenpaging/policy_default.c
+++ b/tools/xenpaging/policy_default.c
@@ -70,7 +70,7 @@ int policy_init(xenpaging_t *paging)
int policy_choose_victim(xenpaging_t *paging, domid_t domain_id,
xenpaging_victim_t *victim)
{
- struct xc_interface *xch = paging->xc_handle;
+ xc_interface *xch = paging->xc_handle;
unsigned long wrap = current_gfn;
ASSERT(victim != NULL);
diff --git a/tools/xenpaging/xc.c b/tools/xenpaging/xc.c
index 3b9c836aa0..d1a62ff77f 100644
--- a/tools/xenpaging/xc.c
+++ b/tools/xenpaging/xc.c
@@ -65,9 +65,9 @@ int xc_mem_paging_flush_ioemu_cache(domid_t domain_id)
return rc;
}
-int xc_wait_for_event_or_timeout(xc_interface *xch, int xce_handle, unsigned long ms)
+int xc_wait_for_event_or_timeout(xc_interface *xch, xc_evtchn *xce, unsigned long ms)
{
- struct pollfd fd = { .fd = xce_handle, .events = POLLIN | POLLERR };
+ struct pollfd fd = { .fd = xc_evtchn_fd(xce), .events = POLLIN | POLLERR };
int port;
int rc;
@@ -83,14 +83,14 @@ int xc_wait_for_event_or_timeout(xc_interface *xch, int xce_handle, unsigned lon
if ( rc == 1 )
{
- port = xc_evtchn_pending(xce_handle);
+ port = xc_evtchn_pending(xce);
if ( port == -1 )
{
ERROR("Failed to read port from event channel");
goto err;
}
- rc = xc_evtchn_unmask(xce_handle, port);
+ rc = xc_evtchn_unmask(xce, port);
if ( rc != 0 )
{
ERROR("Failed to unmask event channel port");
@@ -106,9 +106,9 @@ int xc_wait_for_event_or_timeout(xc_interface *xch, int xce_handle, unsigned lon
return -errno;
}
-int xc_wait_for_event(xc_interface *xch, int xce_handle)
+int xc_wait_for_event(xc_interface *xch, xc_evtchn *xce)
{
- return xc_wait_for_event_or_timeout(xch, xce_handle, -1);
+ return xc_wait_for_event_or_timeout(xch, xce, -1);
}
int xc_get_platform_info(xc_interface *xc_handle, domid_t domain_id,
diff --git a/tools/xenpaging/xc.h b/tools/xenpaging/xc.h
index 5febb89ef3..41cf310c47 100644
--- a/tools/xenpaging/xc.h
+++ b/tools/xenpaging/xc.h
@@ -53,8 +53,8 @@ typedef struct xc_platform_info {
int alloc_bitmap(unsigned long **bitmap, unsigned long bitmap_size);
int xc_mem_paging_flush_ioemu_cache(domid_t domain_id);
-int xc_wait_for_event(xc_interface *xch, int xce_handle);
-int xc_wait_for_event_or_timeout(xc_interface *xch, int xce_handle, unsigned long ms);
+int xc_wait_for_event(xc_interface *xch, xc_evtchn *xce);
+int xc_wait_for_event_or_timeout(xc_interface *xch, xc_evtchn *xce, unsigned long ms);
int xc_get_platform_info(xc_interface *xc_handle, domid_t domain_id,
xc_platform_info_t *platform_info);
diff --git a/tools/xenpaging/xenpaging.c b/tools/xenpaging/xenpaging.c
index 74e4f56589..508068f9c5 100644
--- a/tools/xenpaging/xenpaging.c
+++ b/tools/xenpaging/xenpaging.c
@@ -144,8 +144,8 @@ xenpaging_t *xenpaging_init(domid_t domain_id)
}
/* Open event channel */
- paging->mem_event.xce_handle = xc_evtchn_open();
- if ( paging->mem_event.xce_handle < 0 )
+ paging->mem_event.xce_handle = xc_evtchn_open(NULL, 0);
+ if ( paging->mem_event.xce_handle == NULL )
{
ERROR("Failed to open event channel");
goto err;
@@ -246,7 +246,7 @@ xenpaging_t *xenpaging_init(domid_t domain_id)
int xenpaging_teardown(xenpaging_t *paging)
{
int rc;
- struct xc_interface *xch;
+ xc_interface *xch;
if ( paging == NULL )
return 0;
@@ -274,7 +274,7 @@ int xenpaging_teardown(xenpaging_t *paging)
{
ERROR("Error closing event channel");
}
- paging->mem_event.xce_handle = -1;
+ paging->mem_event.xce_handle = NULL;
/* Close connection to Xen */
rc = xc_interface_close(xch);
@@ -338,7 +338,7 @@ static int put_response(mem_event_t *mem_event, mem_event_response_t *rsp)
int xenpaging_evict_page(xenpaging_t *paging,
xenpaging_victim_t *victim, int fd, int i)
{
- struct xc_interface *xch = paging->xc_handle;
+ xc_interface *xch = paging->xc_handle;
void *page;
unsigned long gfn;
int ret;
@@ -412,7 +412,7 @@ static int xenpaging_resume_page(xenpaging_t *paging, mem_event_response_t *rsp,
static int xenpaging_populate_page(xenpaging_t *paging,
uint64_t *gfn, int fd, int i)
{
- struct xc_interface *xch = paging->xc_handle;
+ xc_interface *xch = paging->xc_handle;
unsigned long _gfn;
void *page;
int ret;
@@ -467,7 +467,7 @@ static int xenpaging_populate_page(xenpaging_t *paging,
static int evict_victim(xenpaging_t *paging, domid_t domain_id,
xenpaging_victim_t *victim, int fd, int i)
{
- struct xc_interface *xch = paging->xc_handle;
+ xc_interface *xch = paging->xc_handle;
int j = 0;
int ret;
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index b043ac45f8..1749740482 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -52,7 +52,7 @@
#include "hashtable.h"
-extern int xce_handle; /* in xenstored_domain.c */
+extern xc_evtchn *xce_handle; /* in xenstored_domain.c */
static bool verbose = false;
LIST_HEAD(connections);
@@ -323,7 +323,7 @@ static int initialize_set(fd_set *inset, fd_set *outset, int sock, int ro_sock,
set_fd(ro_sock, inset, &max);
set_fd(reopen_log_pipe[0], inset, &max);
- if (xce_handle != -1)
+ if (xce_handle != NULL)
set_fd(xc_evtchn_fd(xce_handle), inset, &max);
list_for_each_entry(conn, &connections, list) {
@@ -1901,7 +1901,7 @@ int main(int argc, char *argv[])
signal(SIGHUP, trigger_reopen_log);
- if (xce_handle != -1)
+ if (xce_handle != NULL)
evtchn_fd = xc_evtchn_fd(xce_handle);
/* Get ready to listen to the tools. */
diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_domain.c
index 7aa87cd022..654185d4bb 100644
--- a/tools/xenstore/xenstored_domain.c
+++ b/tools/xenstore/xenstored_domain.c
@@ -36,7 +36,7 @@
static xc_interface **xc_handle;
static evtchn_port_t virq_port;
-int xce_handle = -1;
+xc_evtchn *xce_handle = NULL;
struct domain
{
@@ -580,8 +580,7 @@ static int dom0_init(void)
return 0;
}
-/* Returns the event channel handle. */
-int domain_init(void)
+void domain_init(void)
{
int rc;
@@ -595,9 +594,9 @@ int domain_init(void)
talloc_set_destructor(xc_handle, close_xc_handle);
- xce_handle = xc_evtchn_open();
+ xce_handle = xc_evtchn_open(NULL, 0);
- if (xce_handle < 0)
+ if (xce_handle == NULL)
barf_perror("Failed to open evtchn device");
if (dom0_init() != 0)
@@ -606,8 +605,6 @@ int domain_init(void)
if ((rc = xc_evtchn_bind_virq(xce_handle, VIRQ_DOM_EXC)) == -1)
barf_perror("Failed to bind to domain exception virq port");
virq_port = rc;
-
- return xce_handle;
}
void domain_entry_inc(struct connection *conn, struct node *node)
diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_domain.h
index f42a9f50ad..6a1e8be09b 100644
--- a/tools/xenstore/xenstored_domain.h
+++ b/tools/xenstore/xenstored_domain.h
@@ -40,8 +40,7 @@ void do_set_target(struct connection *conn, struct buffered_data *in);
/* domid */
void do_get_domain_path(struct connection *conn, const char *domid_str);
-/* Returns the event channel handle */
-int domain_init(void);
+void domain_init(void);
/* Returns the implicit path of a connection (only domains have this) */
const char *get_implicit_path(const struct connection *conn);
diff --git a/tools/xentrace/xentrace.c b/tools/xentrace/xentrace.c
index 9e07f3f2c4..e380531e35 100644
--- a/tools/xentrace/xentrace.c
+++ b/tools/xentrace/xentrace.c
@@ -73,7 +73,7 @@ settings_t opts;
int interrupted = 0; /* gets set if we get a SIGHUP */
static xc_interface *xc_handle;
-static int event_fd = -1;
+static xc_evtchn *xce_handle = NULL;
static int virq_port = -1;
static int outfd = 1;
@@ -576,14 +576,13 @@ static void event_init(void)
{
int rc;
- rc = xc_evtchn_open();
- if (rc < 0) {
+ xce_handle = xc_evtchn_open(NULL, 0);
+ if (xce_handle == NULL) {
perror("event channel open");
exit(EXIT_FAILURE);
}
- event_fd = rc;
- rc = xc_evtchn_bind_virq(event_fd, VIRQ_TBUF);
+ rc = xc_evtchn_bind_virq(xce_handle, VIRQ_TBUF);
if (rc == -1) {
PERROR("failed to bind to VIRQ port");
exit(EXIT_FAILURE);
@@ -598,7 +597,7 @@ static void event_init(void)
static void wait_for_event_or_timeout(unsigned long milliseconds)
{
int rc;
- struct pollfd fd = { .fd = event_fd,
+ struct pollfd fd = { .fd = xc_evtchn_fd(xce_handle),
.events = POLLIN | POLLERR };
int port;
@@ -611,7 +610,7 @@ static void wait_for_event_or_timeout(unsigned long milliseconds)
}
if (rc == 1) {
- port = xc_evtchn_pending(event_fd);
+ port = xc_evtchn_pending(xce_handle);
if (port == -1) {
PERROR("failed to read port from evtchn");
exit(EXIT_FAILURE);
@@ -622,7 +621,7 @@ static void wait_for_event_or_timeout(unsigned long milliseconds)
port, virq_port);
exit(EXIT_FAILURE);
}
- rc = xc_evtchn_unmask(event_fd, port);
+ rc = xc_evtchn_unmask(xce_handle, port);
if (rc == -1) {
PERROR("failed to write port to evtchn");
exit(EXIT_FAILURE);