Skip to contentSkip to conversation

xc_evtchn_*() interfaces

PATCH In review John Levon 2 participants 6 messages Jun 14, 2006

lore
Share & tools
lore

John Levon

author
#0 lore raw

PATCH 1/1 xc_evtchn_*() interfaces

# HG changeset patch
# User [email protected]
# Node ID 6cecc40cc954897022eb8fb1b4b4a9b8cd6249d3
# Parent cede50ca17044ac7cee52ccd708043d3b249a0cc
Introduce xc_evtchn_*() interface for interacting with /dev/xen/evtchn. No longer open the device as non-blocking: all reads immediately follow a select() on the device indicating it's ready to read.

tools/console/daemon/io.c +28 -37
diff -r cede50ca1704 -r 6cecc40cc954 tools/console/daemon/io.c
@@ -24,8 +24,8 @@
 #include "io.h"
 #include <xenctrl.h>
 #include <xs.h>
-#include <xen/linux/evtchn.h>
 #include <xen/io/console.h>
+#include <xenctrl.h>
 
 #include <malloc.h>
 #include <stdlib.h>
@@ -36,7 +36,6 @@
 #include <unistd.h>
 #include <termios.h>
 #include <stdarg.h>
-#include <sys/ioctl.h>
 #include <sys/mman.h>
 
 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
@@ -64,18 +63,11 @@ struct domain
 	char *conspath;
 	int ring_ref;
 	evtchn_port_t local_port;
-	int evtchn_fd;
+	int xce_handle;
 	struct xencons_interface *interface;
 };
 
 static struct domain *dom_head;
-
-static void evtchn_notify(struct domain *dom)
-{
-	struct ioctl_evtchn_notify notify;
-	notify.port = dom->local_port;
-	(void)ioctl(dom->evtchn_fd, IOCTL_EVTCHN_NOTIFY, &notify);
-}
 
 static void buffer_append(struct domain *dom)
 {
@@ -106,7 +98,7 @@ static void buffer_append(struct domain 
 
 	mb();
 	intf->out_cons = cons;
-	evtchn_notify(dom);
+	xc_evtchn_notify(dom->xce_handle, dom->local_port);
 
 	if (buffer->max_capacity &&
 	    buffer->size > buffer->max_capacity) {
@@ -234,7 +226,6 @@ static int domain_create_ring(struct dom
 static int domain_create_ring(struct domain *dom)
 {
 	int err, remote_port, ring_ref, rc;
-	struct ioctl_evtchn_bind_interdomain bind;
 
 	err = xs_gather(xs, dom->conspath,
 			"ring-ref", "%u", &ring_ref,
@@ -258,24 +249,24 @@ static int domain_create_ring(struct dom
 	}
 
 	dom->local_port = -1;
-	if (dom->evtchn_fd != -1)
-		close(dom->evtchn_fd);
+	if (dom->xce_handle != -1)
+		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->evtchn_fd = open("/dev/xen/evtchn", O_RDWR);
-	if (dom->evtchn_fd == -1) {
+	dom->xce_handle = xc_evtchn_open();
+	if (dom->xce_handle == -1) {
 		err = errno;
 		goto out;
 	}
  
-	bind.remote_domain = dom->domid;
-	bind.remote_port   = remote_port;
-	rc = ioctl(dom->evtchn_fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
+	rc = xc_evtchn_bind_interdomain(dom->xce_handle,
+		dom->domid, remote_port);
+
 	if (rc == -1) {
 		err = errno;
-		close(dom->evtchn_fd);
-		dom->evtchn_fd = -1;
+		xc_evtchn_close(dom->xce_handle);
+		dom->xce_handle = -1;
 		goto out;
 	}
 	dom->local_port = rc;
@@ -285,8 +276,8 @@ static int domain_create_ring(struct dom
 
 		if (dom->tty_fd == -1) {
 			err = errno;
-			close(dom->evtchn_fd);
-			dom->evtchn_fd = -1;
+			xc_evtchn_close(dom->xce_handle);
+			dom->xce_handle = -1;
 			dom->local_port = -1;
 			goto out;
 		}
@@ -344,7 +335,7 @@ static struct domain *create_domain(int 
 	dom->ring_ref = -1;
 	dom->local_port = -1;
 	dom->interface = NULL;
-	dom->evtchn_fd = -1;
+	dom->xce_handle = -1;
 
 	if (!watch_domain(dom, true))
 		goto out;
@@ -409,9 +400,9 @@ static void shutdown_domain(struct domai
 	if (d->interface != NULL)
 		munmap(d->interface, getpagesize());
 	d->interface = NULL;
-	if (d->evtchn_fd != -1)
-		close(d->evtchn_fd);
-	d->evtchn_fd = -1;
+	if (d->xce_handle != -1)
+		xc_evtchn_close(d->xce_handle);
+	d->xce_handle = -1;
 	cleanup_domain(d);
 }
 
@@ -483,7 +474,7 @@ static void handle_tty_read(struct domai
 		}
 		wmb();
 		intf->in_prod = prod;
-		evtchn_notify(dom);
+		xc_evtchn_notify(dom->xce_handle, dom->local_port);
 	} else {
 		close(dom->tty_fd);
 		dom->tty_fd = -1;
@@ -516,14 +507,14 @@ static void handle_tty_write(struct doma
 
 static void handle_ring_read(struct domain *dom)
 {
-	evtchn_port_t v;
-
-	if (!read_sync(dom->evtchn_fd, &v, sizeof(v)))
+	evtchn_port_t port;
+
+	if ((port = xc_evtchn_pending(dom->xce_handle)) == -1)
 		return;
 
 	buffer_append(dom);
 
-	(void)write_sync(dom->evtchn_fd, &v, sizeof(v));
+	(void)xc_evtchn_unmask(dom->xce_handle, port);
 }
 
 static void handle_xs(void)
@@ -566,9 +557,9 @@ void handle_io(void)
 		max_fd = MAX(xs_fileno(xs), max_fd);
 
 		for (d = dom_head; d; d = d->next) {
-			if (d->evtchn_fd != -1) {
-				FD_SET(d->evtchn_fd, &readfds);
-				max_fd = MAX(d->evtchn_fd, max_fd);
+			if (d->xce_handle != -1) {
+				FD_SET(d->xce_handle, &readfds);
+				max_fd = MAX(d->xce_handle, max_fd);
 			}
 
 			if (d->tty_fd != -1) {
@@ -588,8 +579,8 @@ void handle_io(void)
 
 		for (d = dom_head; d; d = n) {
 			n = d->next;
-			if (d->evtchn_fd != -1 &&
-			    FD_ISSET(d->evtchn_fd, &readfds))
+			if (d->xce_handle != -1 &&
+			    FD_ISSET(d->xce_handle, &readfds))
 				handle_ring_read(d);
 
 			if (d->tty_fd != -1) {
tools/console/daemon/utils.c +0 -26
diff -r cede50ca1704 -r 6cecc40cc954 tools/console/daemon/utils.c
@@ -38,32 +38,6 @@
 
 struct xs_handle *xs;
 int xc;
-
-bool _read_write_sync(int fd, void *data, size_t size, bool do_read)
-{
-	size_t offset = 0;
-	ssize_t len;
-
-	while (offset < size) {
-		if (do_read) {
-			len = read(fd, data + offset, size - offset);
-		} else {
-			len = write(fd, data + offset, size - offset);
-		}
-
-		if (len < 1) {
-			if (len == -1 && (errno == EAGAIN || errno == EINTR)) {
-				continue;
-			} else {
-				return false;
-			}
-		} else {
-			offset += len;
-		}
-	}
-
-	return true;
-}
 
 static void child_exit(int sig)
 {
tools/console/daemon/utils.h +0 -3
diff -r cede50ca1704 -r 6cecc40cc954 tools/console/daemon/utils.h
@@ -29,9 +29,6 @@
 
 void daemonize(const char *pidfile);
 bool xen_setup(void);
-#define read_sync(fd, buffer, size) _read_write_sync(fd, buffer, size, true)
-#define write_sync(fd, buffer, size) _read_write_sync(fd, buffer, size, false)
-bool _read_write_sync(int fd, void *data, size_t size, bool do_read);
 
 extern struct xs_handle *xs;
 extern int xc;
tools/ioemu/target-i386-dm/helper2.c +15 -24
diff -r cede50ca1704 -r 6cecc40cc954 tools/ioemu/target-i386-dm/helper2.c
@@ -47,11 +47,9 @@
 
 #include <limits.h>
 #include <fcntl.h>
-#include <sys/ioctl.h>
 
 #include <xenctrl.h>
 #include <xen/hvm/ioreq.h>
-#include <xen/linux/evtchn.h>
 
 #include "cpu.h"
 #include "exec-all.h"
@@ -123,7 +121,7 @@ target_ulong cpu_get_phys_page_debug(CPU
 }
 
 //the evtchn fd for polling
-int evtchn_fd = -1;
+int xce_handle = -1;
 
 //which vcpu we are serving
 int send_vcpu = 0;
@@ -170,11 +168,10 @@ static ioreq_t* __cpu_get_ioreq(int vcpu
 //retval--the number of ioreq packet
 static ioreq_t* cpu_get_ioreq(void)
 {
-    int i, rc;
+    int i;
     evtchn_port_t port;
 
-    rc = read(evtchn_fd, &port, sizeof(port));
-    if ( rc == sizeof(port) ) {
+    if ( (port = xc_evtchn_pending(xce_handle)) != -1 ) {
         for ( i = 0; i < vcpus; i++ )
             if ( shared_page->vcpu_iodata[i].dm_eport == port )
                 break;
@@ -184,8 +181,7 @@ static ioreq_t* cpu_get_ioreq(void)
             exit(1);
         }
 
-        // unmask the wanted port again
-        write(evtchn_fd, &port, sizeof(port));
+	xc_evtchn_unmask(xce_handle, port);
 
         //get the io packet from shared memory
         send_vcpu = i;
@@ -440,8 +436,8 @@ int main_loop(void)
 
     /* Watch stdin (fd 0) to see when it has input. */
     FD_ZERO(&wakeup_rfds);
-    FD_SET(evtchn_fd, &wakeup_rfds);
-    highest_fds = evtchn_fd;
+    FD_SET(xce_handle, &wakeup_rfds);
+    highest_fds = xce_handle;
     env->send_event = 0;
 
     while (1) {
@@ -466,20 +462,18 @@ int main_loop(void)
         }
         rfds = wakeup_rfds;
         FD_ZERO(&wakeup_rfds);
-        FD_SET(evtchn_fd, &wakeup_rfds);
+        FD_SET(xce_handle, &wakeup_rfds);
 
         tun_receive_handler(&rfds);
-        if ( FD_ISSET(evtchn_fd, &rfds) ) {
+        if ( FD_ISSET(xce_handle, &rfds) ) {
             cpu_handle_ioreq(env);
         }
         main_loop_wait(0);
 
         if (env->send_event) {
-            struct ioctl_evtchn_notify notify;
-
             env->send_event = 0;
-            notify.port = shared_page->vcpu_iodata[send_vcpu].dm_eport;
-            (void)ioctl(evtchn_fd, IOCTL_EVTCHN_NOTIFY, &notify);
+            (void)xc_evtchn_notify(xce_handle,
+                 shared_page->vcpu_iodata[send_vcpu].dm_eport);
         }
     }
     destroy_hvm_domain();
@@ -511,7 +505,6 @@ CPUState * cpu_init()
 CPUState * cpu_init()
 {
     CPUX86State *env;
-    struct ioctl_evtchn_bind_interdomain bind;
     int i, rc;
 
     cpu_exec_init();
@@ -523,21 +516,19 @@ CPUState * cpu_init()
 
     cpu_single_env = env;
 
-    if (evtchn_fd != -1)//the evtchn has been opened by another cpu object
+    if (xce_handle != -1)//the evtchn has been opened by another cpu object
         return NULL;
 
-    //use nonblock reading not polling, may change in future.
-    evtchn_fd = open("/dev/xen/evtchn", O_RDWR|O_NONBLOCK);
-    if (evtchn_fd == -1) {
+    xce_handle = xc_evtchn_open();
+    if (xce_handle == -1) {
         fprintf(logfile, "open evtchn device error %d\n", errno);
         return NULL;
     }
 
     /* FIXME: how about if we overflow the page here? */
-    bind.remote_domain = domid;
     for ( i = 0; i < vcpus; i++ ) {
-        bind.remote_port = shared_page->vcpu_iodata[i].vp_eport;
-        rc = ioctl(evtchn_fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
+        rc = xc_evtchn_bind_interdomain(xce_handle, domid,
+            shared_page->vcpu_iodata[i].vp_eport);
         if ( rc == -1 ) {
             fprintf(logfile, "bind interdomain ioctl error %d\n", errno);
             return NULL;
tools/libxc/xc_linux.c +113 -0

119 lines not on this page · raw message

tools/libxc/xenctrl.h +48 -0

52 lines not on this page · raw message

tools/xenmon/xenbaked.c +13 -39

106 lines not on this page · raw message

tools/xenstore/fake_libxc.c +2 -2
diff -r cede50ca1704 -r 6cecc40cc954 tools/xenstore/fake_libxc.c
@@ -37,7 +37,7 @@ static evtchn_port_t port;
 static evtchn_port_t port;
 
 /* The event channel maps to a signal, shared page to an mmapped file. */
-void evtchn_notify(int local_port)
+void xc_evtchn_notify(int xce_handle, int local_port)
 {
 	assert(local_port == port);
 	if (kill(xs_test_pid, SIGUSR2) != 0)
@@ -124,7 +124,7 @@ void fake_ack_event(void)
 	signal(SIGUSR2, send_to_fd);
 }
 
-int fake_open_eventchn(void)
+int xc_evtchn_open(void)
 {
 	int fds[2];
 
tools/xenstore/xenstored_core.c +3 -3
diff -r cede50ca1704 -r 6cecc40cc954 tools/xenstore/xenstored_core.c
@@ -54,7 +54,7 @@
 #include "hashtable.h"
 
 
-extern int eventchn_fd; /* in xenstored_domain.c */
+extern int xce_handle; /* in xenstored_domain.c */
 
 static bool verbose = false;
 LIST_HEAD(connections);
@@ -353,7 +353,7 @@ static int initialize_set(fd_set *inset,
 
 	set_fd(sock,               inset, &max);
 	set_fd(ro_sock,            inset, &max);
-	set_fd(eventchn_fd,        inset, &max);
+	set_fd(xce_handle,         inset, &max);
 	set_fd(reopen_log_pipe[0], inset, &max);
 	list_for_each_entry(i, &connections, list) {
 		if (i->domain)
@@ -1934,7 +1934,7 @@ int main(int argc, char *argv[])
 		if (FD_ISSET(*ro_sock, &inset))
 			accept_connection(*ro_sock, false);
 
-		if (eventchn_fd > 0 && FD_ISSET(eventchn_fd, &inset))
+		if (xce_handle > 0 && FD_ISSET(xce_handle, &inset))
 			handle_event();
 
 		list_for_each_entry(i, &connections, list) {
tools/xenstore/xenstored_domain.c +13 -66

178 lines not on this page · raw message

#1 lore raw
Quoted 2 lines · John Levon

No longer open the device as non-blocking: all reads immediately follow a select() on the device indicating it's ready to read.

Why change this?

-- Keir

author
#2 lore raw
Quoted 4 lines · Keir Fraser
Quoted 2 lines

No longer open the device as non-blocking: all reads immediately follow a select() on the device indicating it's ready to read.

Why change this?

Because not all users specified O_NONBLOCK, so to keep the exact same code would mean complicating the API a little bit. As there is no extant code that actually takes advantage of O_NONBLOCK, it's pointless having the extra code (note that xenstore would actually die if it ever got EAGAIN...)

regards
john

#3 lore raw
Quoted 10 lines · John Levon
Quoted 4 lines
Quoted 2 lines

No longer open the device as non-blocking: all reads immediately follow a select() on the device indicating it's ready to read.

Why change this?

Because not all users specified O_NONBLOCK, so to keep the exact same code would mean complicating the API a little bit. As there is no extant code that actually takes advantage of O_NONBLOCK, it's pointless having the extra code (note that xenstore would actually die if it ever got EAGAIN...)

Okay, that makes sense.

Looking at the patch, one nit I have is that the 'event-channel handle' (xce_handle) abstraction is broken by the fact that interface users add the handle to fd sets. Either we should just own up to the fact that xce_handle really is just xce_fd, and thus call it that, or else add a xc_evtchn_fd() interface for getting a pollable fd from a xce_handle. Do you have a preference?

-- Keir

author
#4 lore raw
Quoted 4 lines · Keir Fraser

Looking at the patch, one nit I have is that the 'event-channel handle' (xce_handle) abstraction is broken by the fact that interface users add the handle to fd sets. Either we should just own up to the fact that xce_handle really is just xce_fd, and thus call it that, or else add a

I had a feeling you'd say that.

Quoted 1 line

xc_evtchn_fd() interface for getting a pollable fd from a xce_handle.

I'd prefer this. I'll work on fixing this up.

regards,
john

author
#5 lore raw

PATCH 1/1 xc_evtchn_*() interfaces (take 2)

In reply to John Levon

# HG changeset patch
# User [email protected]
# Node ID 09743c3e8825a19931c4e863285d638274a7f94b
# Parent cede50ca17044ac7cee52ccd708043d3b249a0cc
Introduce xc_evtchn_*() interface for interacting with /dev/xen/evtchn. No longer open the device as non-blocking: all reads immediately follow a select() on the device indicating it's ready to read.

tools/console/daemon/io.c +29 -37
diff -r cede50ca1704 -r 09743c3e8825 tools/console/daemon/io.c
@@ -24,8 +24,8 @@
 #include "io.h"
 #include <xenctrl.h>
 #include <xs.h>
-#include <xen/linux/evtchn.h>
 #include <xen/io/console.h>
+#include <xenctrl.h>
 
 #include <malloc.h>
 #include <stdlib.h>
@@ -36,7 +36,6 @@
 #include <unistd.h>
 #include <termios.h>
 #include <stdarg.h>
-#include <sys/ioctl.h>
 #include <sys/mman.h>
 
 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
@@ -64,18 +63,11 @@ struct domain
 	char *conspath;
 	int ring_ref;
 	evtchn_port_t local_port;
-	int evtchn_fd;
+	int xce_handle;
 	struct xencons_interface *interface;
 };
 
 static struct domain *dom_head;
-
-static void evtchn_notify(struct domain *dom)
-{
-	struct ioctl_evtchn_notify notify;
-	notify.port = dom->local_port;
-	(void)ioctl(dom->evtchn_fd, IOCTL_EVTCHN_NOTIFY, &notify);
-}
 
 static void buffer_append(struct domain *dom)
 {
@@ -106,7 +98,7 @@ static void buffer_append(struct domain 
 
 	mb();
 	intf->out_cons = cons;
-	evtchn_notify(dom);
+	xc_evtchn_notify(dom->xce_handle, dom->local_port);
 
 	if (buffer->max_capacity &&
 	    buffer->size > buffer->max_capacity) {
@@ -234,7 +226,6 @@ static int domain_create_ring(struct dom
 static int domain_create_ring(struct domain *dom)
 {
 	int err, remote_port, ring_ref, rc;
-	struct ioctl_evtchn_bind_interdomain bind;
 
 	err = xs_gather(xs, dom->conspath,
 			"ring-ref", "%u", &ring_ref,
@@ -258,24 +249,24 @@ static int domain_create_ring(struct dom
 	}
 
 	dom->local_port = -1;
-	if (dom->evtchn_fd != -1)
-		close(dom->evtchn_fd);
+	if (dom->xce_handle != -1)
+		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->evtchn_fd = open("/dev/xen/evtchn", O_RDWR);
-	if (dom->evtchn_fd == -1) {
+	dom->xce_handle = xc_evtchn_open();
+	if (dom->xce_handle == -1) {
 		err = errno;
 		goto out;
 	}
  
-	bind.remote_domain = dom->domid;
-	bind.remote_port   = remote_port;
-	rc = ioctl(dom->evtchn_fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
+	rc = xc_evtchn_bind_interdomain(dom->xce_handle,
+		dom->domid, remote_port);
+
 	if (rc == -1) {
 		err = errno;
-		close(dom->evtchn_fd);
-		dom->evtchn_fd = -1;
+		xc_evtchn_close(dom->xce_handle);
+		dom->xce_handle = -1;
 		goto out;
 	}
 	dom->local_port = rc;
@@ -285,8 +276,8 @@ static int domain_create_ring(struct dom
 
 		if (dom->tty_fd == -1) {
 			err = errno;
-			close(dom->evtchn_fd);
-			dom->evtchn_fd = -1;
+			xc_evtchn_close(dom->xce_handle);
+			dom->xce_handle = -1;
 			dom->local_port = -1;
 			goto out;
 		}
@@ -344,7 +335,7 @@ static struct domain *create_domain(int 
 	dom->ring_ref = -1;
 	dom->local_port = -1;
 	dom->interface = NULL;
-	dom->evtchn_fd = -1;
+	dom->xce_handle = -1;
 
 	if (!watch_domain(dom, true))
 		goto out;
@@ -409,9 +400,9 @@ static void shutdown_domain(struct domai
 	if (d->interface != NULL)
 		munmap(d->interface, getpagesize());
 	d->interface = NULL;
-	if (d->evtchn_fd != -1)
-		close(d->evtchn_fd);
-	d->evtchn_fd = -1;
+	if (d->xce_handle != -1)
+		xc_evtchn_close(d->xce_handle);
+	d->xce_handle = -1;
 	cleanup_domain(d);
 }
 
@@ -483,7 +474,7 @@ static void handle_tty_read(struct domai
 		}
 		wmb();
 		intf->in_prod = prod;
-		evtchn_notify(dom);
+		xc_evtchn_notify(dom->xce_handle, dom->local_port);
 	} else {
 		close(dom->tty_fd);
 		dom->tty_fd = -1;
@@ -516,14 +507,14 @@ static void handle_tty_write(struct doma
 
 static void handle_ring_read(struct domain *dom)
 {
-	evtchn_port_t v;
-
-	if (!read_sync(dom->evtchn_fd, &v, sizeof(v)))
+	evtchn_port_t port;
+
+	if ((port = xc_evtchn_pending(dom->xce_handle)) == -1)
 		return;
 
 	buffer_append(dom);
 
-	(void)write_sync(dom->evtchn_fd, &v, sizeof(v));
+	(void)xc_evtchn_unmask(dom->xce_handle, port);
 }
 
 static void handle_xs(void)
@@ -566,9 +557,10 @@ void handle_io(void)
 		max_fd = MAX(xs_fileno(xs), max_fd);
 
 		for (d = dom_head; d; d = d->next) {
-			if (d->evtchn_fd != -1) {
-				FD_SET(d->evtchn_fd, &readfds);
-				max_fd = MAX(d->evtchn_fd, max_fd);
+			if (d->xce_handle != -1) {
+				int evtchn_fd = xc_evtchn_fd(d->xce_handle);
+				FD_SET(evtchn_fd, &readfds);
+				max_fd = MAX(evtchn_fd, max_fd);
 			}
 
 			if (d->tty_fd != -1) {
@@ -588,8 +580,8 @@ void handle_io(void)
 
 		for (d = dom_head; d; d = n) {
 			n = d->next;
-			if (d->evtchn_fd != -1 &&
-			    FD_ISSET(d->evtchn_fd, &readfds))
+			if (d->xce_handle != -1 &&
+			    FD_ISSET(xc_evtchn_fd(d->xce_handle), &readfds))
 				handle_ring_read(d);
 
 			if (d->tty_fd != -1) {
tools/console/daemon/utils.c +0 -26
diff -r cede50ca1704 -r 09743c3e8825 tools/console/daemon/utils.c
@@ -38,32 +38,6 @@
 
 struct xs_handle *xs;
 int xc;
-
-bool _read_write_sync(int fd, void *data, size_t size, bool do_read)
-{
-	size_t offset = 0;
-	ssize_t len;
-
-	while (offset < size) {
-		if (do_read) {
-			len = read(fd, data + offset, size - offset);
-		} else {
-			len = write(fd, data + offset, size - offset);
-		}
-
-		if (len < 1) {
-			if (len == -1 && (errno == EAGAIN || errno == EINTR)) {
-				continue;
-			} else {
-				return false;
-			}
-		} else {
-			offset += len;
-		}
-	}
-
-	return true;
-}
 
 static void child_exit(int sig)
 {
tools/console/daemon/utils.h +0 -3
diff -r cede50ca1704 -r 09743c3e8825 tools/console/daemon/utils.h
@@ -29,9 +29,6 @@
 
 void daemonize(const char *pidfile);
 bool xen_setup(void);
-#define read_sync(fd, buffer, size) _read_write_sync(fd, buffer, size, true)
-#define write_sync(fd, buffer, size) _read_write_sync(fd, buffer, size, false)
-bool _read_write_sync(int fd, void *data, size_t size, bool do_read);
 
 extern struct xs_handle *xs;
 extern int xc;
tools/ioemu/target-i386-dm/helper2.c +12 -20
diff -r cede50ca1704 -r 09743c3e8825 tools/ioemu/target-i386-dm/helper2.c
@@ -47,11 +47,9 @@
 
 #include <limits.h>
 #include <fcntl.h>
-#include <sys/ioctl.h>
 
 #include <xenctrl.h>
 #include <xen/hvm/ioreq.h>
-#include <xen/linux/evtchn.h>
 
 #include "cpu.h"
 #include "exec-all.h"
@@ -123,7 +121,7 @@ target_ulong cpu_get_phys_page_debug(CPU
 }
 
 //the evtchn fd for polling
-int evtchn_fd = -1;
+int xce_handle = -1;
 
 //which vcpu we are serving
 int send_vcpu = 0;
@@ -170,11 +168,10 @@ static ioreq_t* __cpu_get_ioreq(int vcpu
 //retval--the number of ioreq packet
 static ioreq_t* cpu_get_ioreq(void)
 {
-    int i, rc;
+    int i;
     evtchn_port_t port;
 
-    rc = read(evtchn_fd, &port, sizeof(port));
-    if ( rc == sizeof(port) ) {
+    if ( (port = xc_evtchn_pending(xce_handle)) != -1 ) {
         for ( i = 0; i < vcpus; i++ )
             if ( shared_page->vcpu_iodata[i].dm_eport == port )
                 break;
@@ -184,8 +181,7 @@ static ioreq_t* cpu_get_ioreq(void)
             exit(1);
         }
 
-        // unmask the wanted port again
-        write(evtchn_fd, &port, sizeof(port));
+	xc_evtchn_unmask(xce_handle, port);
 
         //get the io packet from shared memory
         send_vcpu = i;
@@ -436,6 +432,7 @@ int main_loop(void)
     extern int shutdown_requested;
     CPUState *env = global_env;
     int retval;
+    int evtchn_fd = xc_evtchn_fd(xce_handle);
     extern void main_loop_wait(int);
 
     /* Watch stdin (fd 0) to see when it has input. */
@@ -475,11 +472,9 @@ int main_loop(void)
         main_loop_wait(0);
 
         if (env->send_event) {
-            struct ioctl_evtchn_notify notify;
-
             env->send_event = 0;
-            notify.port = shared_page->vcpu_iodata[send_vcpu].dm_eport;
-            (void)ioctl(evtchn_fd, IOCTL_EVTCHN_NOTIFY, &notify);
+            (void)xc_evtchn_notify(xce_handle,
+                 shared_page->vcpu_iodata[send_vcpu].dm_eport);
         }
     }
     destroy_hvm_domain();
@@ -511,7 +506,6 @@ CPUState * cpu_init()
 CPUState * cpu_init()
 {
     CPUX86State *env;
-    struct ioctl_evtchn_bind_interdomain bind;
     int i, rc;
 
     cpu_exec_init();
@@ -523,21 +517,19 @@ CPUState * cpu_init()
 
     cpu_single_env = env;
 
-    if (evtchn_fd != -1)//the evtchn has been opened by another cpu object
+    if (xce_handle != -1)//the evtchn has been opened by another cpu object
         return NULL;
 
-    //use nonblock reading not polling, may change in future.
-    evtchn_fd = open("/dev/xen/evtchn", O_RDWR|O_NONBLOCK);
-    if (evtchn_fd == -1) {
+    xce_handle = xc_evtchn_open();
+    if (xce_handle == -1) {
         fprintf(logfile, "open evtchn device error %d\n", errno);
         return NULL;
     }
 
     /* FIXME: how about if we overflow the page here? */
-    bind.remote_domain = domid;
     for ( i = 0; i < vcpus; i++ ) {
-        bind.remote_port = shared_page->vcpu_iodata[i].vp_eport;
-        rc = ioctl(evtchn_fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
+        rc = xc_evtchn_bind_interdomain(xce_handle, domid,
+            shared_page->vcpu_iodata[i].vp_eport);
         if ( rc == -1 ) {
             fprintf(logfile, "bind interdomain ioctl error %d\n", errno);
             return NULL;
tools/libxc/xc_linux.c +118 -0

124 lines not on this page · raw message

tools/libxc/xenctrl.h +54 -0

58 lines not on this page · raw message

tools/xenmon/xenbaked.c +16 -39

110 lines not on this page · raw message

tools/xenstore/fake_libxc.c +2 -2
diff -r cede50ca1704 -r 09743c3e8825 tools/xenstore/fake_libxc.c
@@ -37,7 +37,7 @@ static evtchn_port_t port;
 static evtchn_port_t port;
 
 /* The event channel maps to a signal, shared page to an mmapped file. */
-void evtchn_notify(int local_port)
+void xc_evtchn_notify(int xce_handle, int local_port)
 {
 	assert(local_port == port);
 	if (kill(xs_test_pid, SIGUSR2) != 0)
@@ -124,7 +124,7 @@ void fake_ack_event(void)
 	signal(SIGUSR2, send_to_fd);
 }
 
-int fake_open_eventchn(void)
+int xc_evtchn_open(void)
 {
 	int fds[2];
 
tools/xenstore/xenstored_core.c +10 -3
diff -r cede50ca1704 -r 09743c3e8825 tools/xenstore/xenstored_core.c
@@ -54,7 +54,7 @@
 #include "hashtable.h"
 
 
-extern int eventchn_fd; /* in xenstored_domain.c */
+extern int xce_handle; /* in xenstored_domain.c */
 
 static bool verbose = false;
 LIST_HEAD(connections);
@@ -353,8 +353,11 @@ static int initialize_set(fd_set *inset,
 
 	set_fd(sock,               inset, &max);
 	set_fd(ro_sock,            inset, &max);
-	set_fd(eventchn_fd,        inset, &max);
 	set_fd(reopen_log_pipe[0], inset, &max);
+
+	if (xce_handle != -1)
+		set_fd(xc_evtchn_fd(xce_handle), inset, &max);
+
 	list_for_each_entry(i, &connections, list) {
 		if (i->domain)
 			continue;
@@ -1769,6 +1772,7 @@ int main(int argc, char *argv[])
 	bool outputpid = false;
 	bool no_domain_init = false;
 	const char *pidfile = NULL;
+	int evtchn_fd = -1;
 
 	while ((opt = getopt_long(argc, argv, "DE:F:HNPS:T:RLVW:", options,
 				  NULL)) != -1) {
@@ -1907,6 +1911,9 @@ int main(int argc, char *argv[])
 	signal(SIGUSR1, stop_failtest);
 #endif
 
+	if (xce_handle != -1)
+		evtchn_fd = xc_evtchn_fd(xce_handle);
+
 	/* Get ready to listen to the tools. */
 	max = initialize_set(&inset, &outset, *sock, *ro_sock);
 
@@ -1934,7 +1941,7 @@ int main(int argc, char *argv[])
 		if (FD_ISSET(*ro_sock, &inset))
 			accept_connection(*ro_sock, false);
 
-		if (eventchn_fd > 0 && FD_ISSET(eventchn_fd, &inset))
+		if (evtchn_fd != -1 && FD_ISSET(evtchn_fd, &inset))
 			handle_event();
 
 		list_for_each_entry(i, &connections, list) {
tools/xenstore/xenstored_domain.c +13 -66

178 lines not on this page · raw message