direct-io.hg

changeset 7239:62190db89326

Merged.
author emellor@ewan
date Thu Oct 06 19:43:11 2005 +0100 (2005-10-06)
parents f5320ac7ed31 76a7a7aa27e4
children 48df3efaf61c
files tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Thu Oct 06 19:41:29 2005 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Thu Oct 06 19:43:11 2005 +0100
     1.3 @@ -44,9 +44,9 @@
     1.4  #include <linux/poll.h>
     1.5  #include <linux/irq.h>
     1.6  #include <linux/init.h>
     1.7 -#define XEN_EVTCHN_MASK_OPS
     1.8 +#include <linux/gfp.h>
     1.9  #include <asm-xen/evtchn.h>
    1.10 -#include <linux/gfp.h>
    1.11 +#include <asm-xen/linux-public/evtchn.h>
    1.12  
    1.13  struct per_user_data {
    1.14  	/* Notification ring, accessed via /dev/xen/evtchn. */
    1.15 @@ -78,7 +78,8 @@ void evtchn_device_upcall(int port)
    1.16  			u->ring[EVTCHN_RING_MASK(u->ring_prod)] = (u16)port;
    1.17  			if (u->ring_cons == u->ring_prod++) {
    1.18  				wake_up_interruptible(&u->evtchn_wait);
    1.19 -				kill_fasync(&u->evtchn_async_queue, SIGIO, POLL_IN);
    1.20 +				kill_fasync(&u->evtchn_async_queue,
    1.21 +					    SIGIO, POLL_IN);
    1.22  			}
    1.23  		} else {
    1.24  			u->ring_overflow = 1;
    1.25 @@ -208,38 +209,118 @@ static ssize_t evtchn_write(struct file 
    1.26  static int evtchn_ioctl(struct inode *inode, struct file *file,
    1.27                          unsigned int cmd, unsigned long arg)
    1.28  {
    1.29 -	int rc = 0;
    1.30 +	int rc;
    1.31  	struct per_user_data *u = file->private_data;
    1.32 +	evtchn_op_t op = { 0 };
    1.33  
    1.34  	spin_lock_irq(&port_user_lock);
    1.35      
    1.36  	switch (cmd) {
    1.37 -	case EVTCHN_RESET:
    1.38 +	case IOCTL_EVTCHN_BIND_VIRQ: {
    1.39 +		struct ioctl_evtchn_bind_virq bind;
    1.40 +
    1.41 +		rc = -EFAULT;
    1.42 +		if (copy_from_user(&bind, (void *)arg, sizeof(bind)))
    1.43 +			break;
    1.44 +
    1.45 +		op.cmd              = EVTCHNOP_bind_virq;
    1.46 +		op.u.bind_virq.virq = bind.virq;
    1.47 +		op.u.bind_virq.vcpu = 0;
    1.48 +		rc = HYPERVISOR_event_channel_op(&op);
    1.49 +		if (rc != 0)
    1.50 +			break;
    1.51 +
    1.52 +		rc = op.u.bind_virq.port;
    1.53 +		port_user[rc] = u;
    1.54 +		unmask_evtchn(rc);
    1.55 +		break;
    1.56 +	}
    1.57 +
    1.58 +	case IOCTL_EVTCHN_BIND_INTERDOMAIN: {
    1.59 +		struct ioctl_evtchn_bind_interdomain bind;
    1.60 +
    1.61 +		rc = -EFAULT;
    1.62 +		if (copy_from_user(&bind, (void *)arg, sizeof(bind)))
    1.63 +			break;
    1.64 +
    1.65 +		op.cmd                      = EVTCHNOP_bind_interdomain;
    1.66 +		op.u.bind_interdomain.dom1  = DOMID_SELF;
    1.67 +		op.u.bind_interdomain.dom2  = bind.remote_domain;
    1.68 +		op.u.bind_interdomain.port1 = 0;
    1.69 +		op.u.bind_interdomain.port2 = bind.remote_port;
    1.70 +		rc = HYPERVISOR_event_channel_op(&op);
    1.71 +		if (rc != 0)
    1.72 +			break;
    1.73 +
    1.74 +		rc = op.u.bind_interdomain.port1;
    1.75 +		port_user[rc] = u;
    1.76 +		unmask_evtchn(rc);
    1.77 +		break;
    1.78 +	}
    1.79 +
    1.80 +	case IOCTL_EVTCHN_BIND_UNBOUND_PORT: {
    1.81 +		struct ioctl_evtchn_bind_unbound_port bind;
    1.82 +
    1.83 +		rc = -EFAULT;
    1.84 +		if (copy_from_user(&bind, (void *)arg, sizeof(bind)))
    1.85 +			break;
    1.86 +
    1.87 +		op.cmd                        = EVTCHNOP_alloc_unbound;
    1.88 +		op.u.alloc_unbound.dom        = DOMID_SELF;
    1.89 +		op.u.alloc_unbound.remote_dom = bind.remote_domain;
    1.90 +		rc = HYPERVISOR_event_channel_op(&op);
    1.91 +		if (rc != 0)
    1.92 +			break;
    1.93 +
    1.94 +		rc = op.u.alloc_unbound.port;
    1.95 +		port_user[rc] = u;
    1.96 +		unmask_evtchn(rc);
    1.97 +		break;
    1.98 +	}
    1.99 +
   1.100 +	case IOCTL_EVTCHN_UNBIND: {
   1.101 +		struct ioctl_evtchn_unbind unbind;
   1.102 +
   1.103 +		rc = -EFAULT;
   1.104 +		if (copy_from_user(&unbind, (void *)arg, sizeof(unbind)))
   1.105 +			break;
   1.106 +
   1.107 +		if (unbind.port >= NR_EVENT_CHANNELS) {
   1.108 +			rc = -EINVAL;
   1.109 +		} else if (port_user[unbind.port] != u) {
   1.110 +			rc = -ENOTCONN;
   1.111 +		} else {
   1.112 +			port_user[unbind.port] = NULL;
   1.113 +			mask_evtchn(unbind.port);
   1.114 +			rc = 0;
   1.115 +		}
   1.116 +		break;
   1.117 +	}
   1.118 +
   1.119 +	case IOCTL_EVTCHN_NOTIFY: {
   1.120 +		struct ioctl_evtchn_notify notify;
   1.121 +
   1.122 +		rc = -EFAULT;
   1.123 +		if (copy_from_user(&notify, (void *)arg, sizeof(notify)))
   1.124 +			break;
   1.125 +
   1.126 +		if (notify.port >= NR_EVENT_CHANNELS) {
   1.127 +			rc = -EINVAL;
   1.128 +		} else if (port_user[notify.port] != u) {
   1.129 +			rc = -ENOTCONN;
   1.130 +		} else {
   1.131 +			notify_remote_via_evtchn(notify.port);
   1.132 +			rc = 0;
   1.133 +		}
   1.134 +		break;
   1.135 +	}
   1.136 +
   1.137 +	case IOCTL_EVTCHN_RESET: {
   1.138  		/* Initialise the ring to empty. Clear errors. */
   1.139  		u->ring_cons = u->ring_prod = u->ring_overflow = 0;
   1.140 -		break;
   1.141 -
   1.142 -	case EVTCHN_BIND:
   1.143 -		if (arg >= NR_EVENT_CHANNELS) {
   1.144 -			rc = -EINVAL;
   1.145 -		} else if (port_user[arg] != NULL) {
   1.146 -			rc = -EISCONN;
   1.147 -		} else {
   1.148 -			port_user[arg] = u;
   1.149 -			unmask_evtchn(arg);
   1.150 -		}
   1.151 +		rc = 0;
   1.152  		break;
   1.153 -
   1.154 -	case EVTCHN_UNBIND:
   1.155 -		if (arg >= NR_EVENT_CHANNELS) {
   1.156 -			rc = -EINVAL;
   1.157 -		} else if (port_user[arg] != u) {
   1.158 -			rc = -ENOTCONN;
   1.159 -		} else {
   1.160 -			port_user[arg] = NULL;
   1.161 -			mask_evtchn(arg);
   1.162 -		}
   1.163 -		break;
   1.164 +	}
   1.165  
   1.166  	default:
   1.167  		rc = -ENOSYS;
   1.168 @@ -295,6 +376,7 @@ static int evtchn_release(struct inode *
   1.169  {
   1.170  	int i;
   1.171  	struct per_user_data *u = filp->private_data;
   1.172 +	evtchn_op_t op = { 0 };
   1.173  
   1.174  	spin_lock_irq(&port_user_lock);
   1.175  
   1.176 @@ -302,11 +384,16 @@ static int evtchn_release(struct inode *
   1.177  
   1.178  	for (i = 0; i < NR_EVENT_CHANNELS; i++)
   1.179  	{
   1.180 -		if (port_user[i] == u)
   1.181 -		{
   1.182 -			port_user[i] = NULL;
   1.183 -			mask_evtchn(i);
   1.184 -		}
   1.185 +		if (port_user[i] != u)
   1.186 +			continue;
   1.187 +
   1.188 +		port_user[i] = NULL;
   1.189 +		mask_evtchn(i);
   1.190 +
   1.191 +		op.cmd          = EVTCHNOP_close;
   1.192 +		op.u.close.dom  = DOMID_SELF;
   1.193 +		op.u.close.port = i;
   1.194 +		BUG_ON(HYPERVISOR_event_channel_op(&op));
   1.195  	}
   1.196  
   1.197  	spin_unlock_irq(&port_user_lock);
     2.1 --- a/linux-2.6-xen-sparse/include/asm-xen/evtchn.h	Thu Oct 06 19:41:29 2005 +0100
     2.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/evtchn.h	Thu Oct 06 19:43:11 2005 +0100
     2.3 @@ -129,21 +129,6 @@ static inline void notify_remote_via_evt
     2.4  	(void)HYPERVISOR_event_channel_op(&op);
     2.5  }
     2.6  
     2.7 -/*
     2.8 - * CHARACTER-DEVICE DEFINITIONS
     2.9 - */
    2.10 -
    2.11 -/* /dev/xen/evtchn resides at device number major=10, minor=201 */
    2.12 -#define EVTCHN_MINOR 201
    2.13 -
    2.14 -/* /dev/xen/evtchn ioctls: */
    2.15 -/* EVTCHN_RESET: Clear and reinit the event buffer. Clear error condition. */
    2.16 -#define EVTCHN_RESET  _IO('E', 1)
    2.17 -/* EVTCHN_BIND: Bind to teh specified event-channel port. */
    2.18 -#define EVTCHN_BIND   _IO('E', 2)
    2.19 -/* EVTCHN_UNBIND: Unbind from the specified event-channel port. */
    2.20 -#define EVTCHN_UNBIND _IO('E', 3)
    2.21 -
    2.22  #endif /* __ASM_EVTCHN_H__ */
    2.23  
    2.24  /*
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/linux-public/evtchn.h	Thu Oct 06 19:43:11 2005 +0100
     3.3 @@ -0,0 +1,98 @@
     3.4 +/******************************************************************************
     3.5 + * evtchn.h
     3.6 + * 
     3.7 + * Interface to /dev/xen/evtchn.
     3.8 + * 
     3.9 + * Copyright (c) 2003-2005, K A Fraser
    3.10 + * 
    3.11 + * This file may be distributed separately from the Linux kernel, or
    3.12 + * incorporated into other software packages, subject to the following license:
    3.13 + * 
    3.14 + * Permission is hereby granted, free of charge, to any person obtaining a copy
    3.15 + * of this source file (the "Software"), to deal in the Software without
    3.16 + * restriction, including without limitation the rights to use, copy, modify,
    3.17 + * merge, publish, distribute, sublicense, and/or sell copies of the Software,
    3.18 + * and to permit persons to whom the Software is furnished to do so, subject to
    3.19 + * the following conditions:
    3.20 + * 
    3.21 + * The above copyright notice and this permission notice shall be included in
    3.22 + * all copies or substantial portions of the Software.
    3.23 + * 
    3.24 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    3.25 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    3.26 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    3.27 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    3.28 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    3.29 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
    3.30 + * IN THE SOFTWARE.
    3.31 + */
    3.32 +
    3.33 +#ifndef __LINUX_PUBLIC_EVTCHN_H__
    3.34 +#define __LINUX_PUBLIC_EVTCHN_H__
    3.35 +
    3.36 +/* /dev/xen/evtchn resides at device number major=10, minor=201 */
    3.37 +#define EVTCHN_MINOR 201
    3.38 +
    3.39 +/*
    3.40 + * Bind a fresh port to VIRQ @virq.
    3.41 + * Return allocated port.
    3.42 + */
    3.43 +#define IOCTL_EVTCHN_BIND_VIRQ				\
    3.44 +	_IOC(_IOC_NONE, 'E', 0, sizeof(struct ioctl_evtchn_bind_virq))
    3.45 +struct ioctl_evtchn_bind_virq {
    3.46 +	unsigned int virq;
    3.47 +};
    3.48 +
    3.49 +/*
    3.50 + * Bind a fresh port to remote <@remote_domain, @remote_port>.
    3.51 + * Return allocated port.
    3.52 + */
    3.53 +#define IOCTL_EVTCHN_BIND_INTERDOMAIN			\
    3.54 +	_IOC(_IOC_NONE, 'E', 1, sizeof(struct ioctl_evtchn_bind_interdomain))
    3.55 +struct ioctl_evtchn_bind_interdomain {
    3.56 +	unsigned int remote_domain, remote_port;
    3.57 +};
    3.58 +
    3.59 +/*
    3.60 + * Allocate a fresh port for binding to @remote_domain.
    3.61 + * Return allocated port.
    3.62 + */
    3.63 +#define IOCTL_EVTCHN_BIND_UNBOUND_PORT			\
    3.64 +	_IOC(_IOC_NONE, 'E', 2, sizeof(struct ioctl_evtchn_bind_unbound_port))
    3.65 +struct ioctl_evtchn_bind_unbound_port {
    3.66 +	unsigned int remote_domain;
    3.67 +};
    3.68 +
    3.69 +/*
    3.70 + * Unbind previously allocated @port.
    3.71 + */
    3.72 +#define IOCTL_EVTCHN_UNBIND				\
    3.73 +	_IOC(_IOC_NONE, 'E', 3, sizeof(struct ioctl_evtchn_unbind))
    3.74 +struct ioctl_evtchn_unbind {
    3.75 +	unsigned int port;
    3.76 +};
    3.77 +
    3.78 +/*
    3.79 + * Unbind previously allocated @port.
    3.80 + */
    3.81 +#define IOCTL_EVTCHN_NOTIFY				\
    3.82 +	_IOC(_IOC_NONE, 'E', 4, sizeof(struct ioctl_evtchn_notify))
    3.83 +struct ioctl_evtchn_notify {
    3.84 +	unsigned int port;
    3.85 +};
    3.86 +
    3.87 +/* Clear and reinitialise the event buffer. Clear error condition. */
    3.88 +#define IOCTL_EVTCHN_RESET				\
    3.89 +	_IOC(_IOC_NONE, 'E', 5, 0)
    3.90 +
    3.91 +#endif /* __LINUX_PUBLIC_EVTCHN_H__ */
    3.92 +
    3.93 +/*
    3.94 + * Local variables:
    3.95 + *  c-file-style: "linux"
    3.96 + *  indent-tabs-mode: t
    3.97 + *  c-indent-level: 8
    3.98 + *  c-basic-offset: 8
    3.99 + *  tab-width: 8
   3.100 + * End:
   3.101 + */
     4.1 --- a/linux-2.6-xen-sparse/include/asm-xen/linux-public/privcmd.h	Thu Oct 06 19:41:29 2005 +0100
     4.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/linux-public/privcmd.h	Thu Oct 06 19:43:11 2005 +0100
     4.3 @@ -3,7 +3,7 @@
     4.4   * 
     4.5   * Interface to /proc/xen/privcmd.
     4.6   * 
     4.7 - * Copyright (c) 2003-2004, K A Fraser
     4.8 + * Copyright (c) 2003-2005, K A Fraser
     4.9   * 
    4.10   * This file may be distributed separately from the Linux kernel, or
    4.11   * incorporated into other software packages, subject to the following license:
    4.12 @@ -27,39 +27,39 @@
    4.13   * IN THE SOFTWARE.
    4.14   */
    4.15  
    4.16 -#ifndef __PRIVCMD_H__
    4.17 -#define __PRIVCMD_H__
    4.18 +#ifndef __LINUX_PUBLIC_PRIVCMD_H__
    4.19 +#define __LINUX_PUBLIC_PRIVCMD_H__
    4.20  
    4.21  typedef struct privcmd_hypercall
    4.22  {
    4.23 -    unsigned long op;
    4.24 -    unsigned long arg[5];
    4.25 +	unsigned long op;
    4.26 +	unsigned long arg[5];
    4.27  } privcmd_hypercall_t;
    4.28  
    4.29  typedef struct privcmd_mmap_entry {
    4.30 -    unsigned long va;
    4.31 -    unsigned long mfn;
    4.32 -    unsigned long npages;
    4.33 +	unsigned long va;
    4.34 +	unsigned long mfn;
    4.35 +	unsigned long npages;
    4.36  } privcmd_mmap_entry_t; 
    4.37  
    4.38  typedef struct privcmd_mmap {
    4.39 -    int num;
    4.40 -    domid_t dom; /* target domain */
    4.41 -    privcmd_mmap_entry_t *entry;
    4.42 +	int num;
    4.43 +	domid_t dom; /* target domain */
    4.44 +	privcmd_mmap_entry_t *entry;
    4.45  } privcmd_mmap_t; 
    4.46  
    4.47  typedef struct privcmd_mmapbatch {
    4.48 -    int num;     /* number of pages to populate */
    4.49 -    domid_t dom; /* target domain */
    4.50 -    unsigned long addr;  /* virtual address */
    4.51 -    unsigned long *arr; /* array of mfns - top nibble set on err */
    4.52 +	int num;     /* number of pages to populate */
    4.53 +	domid_t dom; /* target domain */
    4.54 +	unsigned long addr;  /* virtual address */
    4.55 +	unsigned long *arr; /* array of mfns - top nibble set on err */
    4.56  } privcmd_mmapbatch_t; 
    4.57  
    4.58  typedef struct privcmd_blkmsg
    4.59  {
    4.60 -    unsigned long op;
    4.61 -    void         *buf;
    4.62 -    int           buf_size;
    4.63 +	unsigned long op;
    4.64 +	void         *buf;
    4.65 +	int           buf_size;
    4.66  } privcmd_blkmsg_t;
    4.67  
    4.68  /*
    4.69 @@ -67,16 +67,26 @@ typedef struct privcmd_blkmsg
    4.70   * @arg: &privcmd_hypercall_t
    4.71   * Return: Value returned from execution of the specified hypercall.
    4.72   */
    4.73 -#define IOCTL_PRIVCMD_HYPERCALL         \
    4.74 -    _IOC(_IOC_NONE, 'P', 0, sizeof(privcmd_hypercall_t))
    4.75 +#define IOCTL_PRIVCMD_HYPERCALL					\
    4.76 +	_IOC(_IOC_NONE, 'P', 0, sizeof(privcmd_hypercall_t))
    4.77 +
    4.78 +#define IOCTL_PRIVCMD_MMAP					\
    4.79 +	_IOC(_IOC_NONE, 'P', 2, sizeof(privcmd_mmap_t))
    4.80 +#define IOCTL_PRIVCMD_MMAPBATCH					\
    4.81 +	_IOC(_IOC_NONE, 'P', 3, sizeof(privcmd_mmapbatch_t))
    4.82 +#define IOCTL_PRIVCMD_GET_MACH2PHYS_START_MFN			\
    4.83 +	_IOC(_IOC_READ, 'P', 4, sizeof(unsigned long))
    4.84 +#define IOCTL_PRIVCMD_INITDOMAIN_STORE				\
    4.85 +	_IOC(_IOC_READ, 'P', 5, 0)
    4.86  
    4.87 -#define IOCTL_PRIVCMD_MMAP             \
    4.88 -    _IOC(_IOC_NONE, 'P', 2, sizeof(privcmd_mmap_t))
    4.89 -#define IOCTL_PRIVCMD_MMAPBATCH             \
    4.90 -    _IOC(_IOC_NONE, 'P', 3, sizeof(privcmd_mmapbatch_t))
    4.91 -#define IOCTL_PRIVCMD_GET_MACH2PHYS_START_MFN \
    4.92 -    _IOC(_IOC_READ, 'P', 4, sizeof(unsigned long))
    4.93 -#define IOCTL_PRIVCMD_INITDOMAIN_STORE \
    4.94 -    _IOC(_IOC_READ, 'P', 5, 0)
    4.95 +#endif /* __LINUX_PUBLIC_PRIVCMD_H__ */
    4.96  
    4.97 -#endif /* __PRIVCMD_H__ */
    4.98 +/*
    4.99 + * Local variables:
   4.100 + *  c-file-style: "linux"
   4.101 + *  indent-tabs-mode: t
   4.102 + *  c-indent-level: 8
   4.103 + *  c-basic-offset: 8
   4.104 + *  tab-width: 8
   4.105 + * End:
   4.106 + */
     5.1 --- a/tools/console/daemon/io.c	Thu Oct 06 19:41:29 2005 +0100
     5.2 +++ b/tools/console/daemon/io.c	Thu Oct 06 19:43:11 2005 +0100
     5.3 @@ -1,4 +1,4 @@
     5.4 -/*\
     5.5 +/*
     5.6   *  Copyright (C) International Business Machines  Corp., 2005
     5.7   *  Author(s): Anthony Liguori <aliguori@us.ibm.com>
     5.8   *
     5.9 @@ -16,14 +16,15 @@
    5.10   *  You should have received a copy of the GNU General Public License
    5.11   *  along with this program; if not, write to the Free Software
    5.12   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.13 -\*/
    5.14 + */
    5.15  
    5.16  #define _GNU_SOURCE
    5.17  
    5.18  #include "utils.h"
    5.19  #include "io.h"
    5.20 -#include "xenctrl.h"
    5.21 -#include "xs.h"
    5.22 +#include <xenctrl.h>
    5.23 +#include <xs.h>
    5.24 +#include <xen/linux/evtchn.h>
    5.25  
    5.26  #include <malloc.h>
    5.27  #include <stdlib.h>
    5.28 @@ -80,6 +81,13 @@ struct ring_head
    5.29  #define XENCONS_FULL(ring) (((ring)->prod - (ring)->cons) == XENCONS_RING_SIZE)
    5.30  #define XENCONS_SPACE(ring) (XENCONS_RING_SIZE - ((ring)->prod - (ring)->cons))
    5.31  
    5.32 +static void evtchn_notify(struct domain *dom)
    5.33 +{
    5.34 +	struct ioctl_evtchn_notify notify;
    5.35 +	notify.port = dom->local_port;
    5.36 +	(void)ioctl(dom->evtchn_fd, IOCTL_EVTCHN_NOTIFY, &notify);
    5.37 +}
    5.38 +
    5.39  static void buffer_append(struct domain *dom)
    5.40  {
    5.41  	struct buffer *buffer = &dom->buffer;
    5.42 @@ -120,7 +128,7 @@ static void buffer_append(struct domain 
    5.43  	}
    5.44  
    5.45  	if (notify)
    5.46 -		xc_evtchn_send(xc, dom->local_port);
    5.47 +		evtchn_notify(dom);
    5.48  }
    5.49  
    5.50  static bool buffer_empty(struct buffer *buffer)
    5.51 @@ -225,16 +233,14 @@ int xs_gather(struct xs_handle *xs, cons
    5.52  	return ret;
    5.53  }
    5.54  
    5.55 -#define EVENTCHN_BIND		_IO('E', 2)
    5.56 -#define EVENTCHN_UNBIND 	_IO('E', 3)
    5.57 -
    5.58  static int domain_create_ring(struct domain *dom)
    5.59  {
    5.60 -	int err, local_port, ring_ref;
    5.61 +	int err, remote_port, ring_ref, rc;
    5.62 +	struct ioctl_evtchn_bind_interdomain bind;
    5.63  
    5.64  	err = xs_gather(xs, dom->conspath,
    5.65  			"ring-ref", "%u", &ring_ref,
    5.66 -			"port", "%i", &local_port,
    5.67 +			"port", "%i", &remote_port,
    5.68  			NULL);
    5.69  	if (err)
    5.70  		goto out;
    5.71 @@ -252,26 +258,28 @@ static int domain_create_ring(struct dom
    5.72  		dom->ring_ref = ring_ref;
    5.73  	}
    5.74  
    5.75 -	if (local_port != dom->local_port) {
    5.76 -		dom->local_port = -1;
    5.77 -		if (dom->evtchn_fd != -1)
    5.78 -			close(dom->evtchn_fd);
    5.79 -		/* Opening evtchn independently for each console is a bit
    5.80 -		 * wastefule, but that's how the code is structured... */
    5.81 -		dom->evtchn_fd = open("/dev/xen/evtchn", O_RDWR);
    5.82 -		if (dom->evtchn_fd == -1) {
    5.83 -			err = errno;
    5.84 -			goto out;
    5.85 -		}
    5.86 +	dom->local_port = -1;
    5.87 +	if (dom->evtchn_fd != -1)
    5.88 +		close(dom->evtchn_fd);
    5.89 +
    5.90 +	/* Opening evtchn independently for each console is a bit
    5.91 +	 * wasteful, but that's how the code is structured... */
    5.92 +	dom->evtchn_fd = open("/dev/xen/evtchn", O_RDWR);
    5.93 +	if (dom->evtchn_fd == -1) {
    5.94 +		err = errno;
    5.95 +		goto out;
    5.96 +	}
    5.97   
    5.98 -		if (ioctl(dom->evtchn_fd, EVENTCHN_BIND, local_port) == -1) {
    5.99 -			err = errno;
   5.100 -			close(dom->evtchn_fd);
   5.101 -			dom->evtchn_fd = -1;
   5.102 -			goto out;
   5.103 -		}
   5.104 -		dom->local_port = local_port;
   5.105 +	bind.remote_domain = dom->domid;
   5.106 +	bind.remote_port   = remote_port;
   5.107 +	rc = ioctl(dom->evtchn_fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
   5.108 +	if (rc == -1) {
   5.109 +		err = errno;
   5.110 +		close(dom->evtchn_fd);
   5.111 +		dom->evtchn_fd = -1;
   5.112 +		goto out;
   5.113  	}
   5.114 +	dom->local_port = rc;
   5.115  
   5.116   out:
   5.117  	return err;
   5.118 @@ -439,7 +447,7 @@ static void handle_tty_read(struct domai
   5.119  			inring->buf[XENCONS_IDX(inring->prod)] = msg[i];
   5.120  			inring->prod++;
   5.121  		}
   5.122 -		xc_evtchn_send(xc, dom->local_port);
   5.123 +		evtchn_notify(dom);
   5.124  	} else {
   5.125  		close(dom->tty_fd);
   5.126  		dom->tty_fd = -1;
     6.1 --- a/tools/debugger/pdb/pdb_xen.c	Thu Oct 06 19:41:29 2005 +0100
     6.2 +++ b/tools/debugger/pdb/pdb_xen.c	Thu Oct 06 19:43:11 2005 +0100
     6.3 @@ -43,11 +43,7 @@ pdb_close (int xc_handle)
     6.4  
     6.5  
     6.6  #include <sys/ioctl.h>
     6.7 -
     6.8 -/* /dev/xen/evtchn ioctls */
     6.9 -#define EVTCHN_RESET  _IO('E', 1)                   /* clear & reinit buffer */
    6.10 -#define EVTCHN_BIND   _IO('E', 2)                   /* bind to event channel */
    6.11 -#define EVTCHN_UNBIND _IO('E', 3)               /* unbind from event channel */
    6.12 +#include <xen/linux/evtchn.h>
    6.13  
    6.14  int
    6.15  xen_evtchn_bind (int evtchn_fd, int idx)
     7.1 --- a/tools/ioemu/target-i386-dm/helper2.c	Thu Oct 06 19:41:29 2005 +0100
     7.2 +++ b/tools/ioemu/target-i386-dm/helper2.c	Thu Oct 06 19:43:11 2005 +0100
     7.3 @@ -49,11 +49,14 @@
     7.4  
     7.5  #include <xenctrl.h>
     7.6  #include <xen/io/ioreq.h>
     7.7 +#include <xen/linux/evtchn.h>
     7.8  
     7.9  #include "cpu.h"
    7.10  #include "exec-all.h"
    7.11  #include "vl.h"
    7.12  
    7.13 +extern int domid;
    7.14 +
    7.15  void *shared_vram;
    7.16  
    7.17  shared_iopage_t *shared_page = NULL;
    7.18 @@ -119,7 +122,7 @@ target_ulong cpu_get_phys_page_debug(CPU
    7.19  //the evtchn fd for polling
    7.20  int evtchn_fd = -1;
    7.21  //the evtchn port for polling the notification, should be inputed as bochs's parameter
    7.22 -u16 ioreq_port = 0;
    7.23 +u16 ioreq_remote_port, ioreq_local_port;
    7.24  
    7.25  //some functions to handle the io req packet
    7.26  void
    7.27 @@ -156,9 +159,9 @@ ioreq_t* cpu_get_ioreq(void)
    7.28  	int rc;
    7.29  	u16 buf[2];
    7.30  	rc = read(evtchn_fd, buf, 2);
    7.31 -	if (rc == 2 && buf[0] == ioreq_port){//got only one matched 16bit port index
    7.32 +	if (rc == 2 && buf[0] == ioreq_local_port){//got only one matched 16bit port index
    7.33  		// unmask the wanted port again
    7.34 -		write(evtchn_fd, &ioreq_port, 2);
    7.35 +		write(evtchn_fd, &ioreq_local_port, 2);
    7.36  
    7.37  		//get the io packet from shared memory
    7.38  		return __cpu_get_ioreq();
    7.39 @@ -417,7 +420,6 @@ do_interrupt(CPUState *env, int vector)
    7.40  void
    7.41  destroy_vmx_domain(void)
    7.42  {
    7.43 -    extern int domid;
    7.44      extern FILE* logfile;
    7.45      char destroy_cmd[20];
    7.46      sprintf(destroy_cmd, "xm destroy %d", domid);
    7.47 @@ -484,11 +486,9 @@ int main_loop(void)
    7.48                      do_ioapic();
    7.49  #endif
    7.50  		if (env->send_event) {
    7.51 -			int ret;
    7.52 -			ret = xc_evtchn_send(xc_handle, ioreq_port);
    7.53 -			if (ret == -1) {
    7.54 -				fprintf(logfile, "evtchn_send failed on port: %d\n", ioreq_port);
    7.55 -			}
    7.56 +			struct ioctl_evtchn_notify notify;
    7.57 +			notify.port = ioreq_local_port;
    7.58 +			(void)ioctl(evtchn_fd, IOCTL_EVTCHN_NOTIFY, &notify);
    7.59  		}
    7.60  	}
    7.61          destroy_vmx_domain();
    7.62 @@ -499,7 +499,6 @@ static void
    7.63  qemu_vmx_reset(void *unused)
    7.64  {
    7.65      char cmd[255];
    7.66 -    extern int domid;
    7.67  
    7.68      /* pause domain first, to avoid repeated reboot request*/ 
    7.69      xc_domain_pause (xc_handle, domid);
    7.70 @@ -512,6 +511,8 @@ CPUState *
    7.71  cpu_init()
    7.72  {
    7.73  	CPUX86State *env;
    7.74 +	struct ioctl_evtchn_bind_interdomain bind;
    7.75 +	int rc;
    7.76        
    7.77          cpu_exec_init();
    7.78          qemu_register_reset(qemu_vmx_reset, NULL);
    7.79 @@ -532,12 +533,14 @@ cpu_init()
    7.80  		return NULL;
    7.81  	}
    7.82  
    7.83 -	fprintf(logfile, "listening to port: %d\n", ioreq_port);
    7.84 -	/*unmask the wanted port -- bind*/
    7.85 -	if (ioctl(evtchn_fd, ('E'<<8)|2, ioreq_port) == -1) {
    7.86 +	bind.remote_domain = domid;
    7.87 +	bind.remote_port   = ioreq_remote_port;
    7.88 +	rc = ioctl(evtchn_fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
    7.89 +	if (rc == -1) {
    7.90  		perror("ioctl");
    7.91  		return NULL;
    7.92  	}
    7.93 +	ioreq_local_port = rc;
    7.94  
    7.95  	return env;
    7.96  }
     8.1 --- a/tools/ioemu/vl.c	Thu Oct 06 19:41:29 2005 +0100
     8.2 +++ b/tools/ioemu/vl.c	Thu Oct 06 19:43:11 2005 +0100
     8.3 @@ -2806,9 +2806,9 @@ int main(int argc, char **argv)
     8.4  
     8.5              case QEMU_OPTION_p:
     8.6                  {
     8.7 -                  extern short ioreq_port;
     8.8 -                  ioreq_port = atoi(optarg);
     8.9 -                  printf("port: %d\n", ioreq_port);
    8.10 +                  extern short ioreq_remote_port;
    8.11 +                  ioreq_remote_port = atoi(optarg);
    8.12 +                  printf("port: %d\n", ioreq_remote_port);
    8.13                  }
    8.14                  break;
    8.15              case QEMU_OPTION_l:
     9.1 --- a/tools/libxc/xc_evtchn.c	Thu Oct 06 19:41:29 2005 +0100
     9.2 +++ b/tools/libxc/xc_evtchn.c	Thu Oct 06 19:43:11 2005 +0100
     9.3 @@ -33,95 +33,22 @@ static int do_evtchn_op(int xc_handle, e
     9.4  
     9.5  
     9.6  int xc_evtchn_alloc_unbound(int xc_handle,
     9.7 -                            u32 remote_dom,
     9.8                              u32 dom,
     9.9 -                            int *port)
    9.10 +                            u32 remote_dom)
    9.11  {
    9.12      int         rc;
    9.13      evtchn_op_t op = {
    9.14          .cmd = EVTCHNOP_alloc_unbound,
    9.15 -        .u.alloc_unbound.remote_dom = (domid_t)remote_dom,
    9.16 -        .u.alloc_unbound.dom  = (domid_t)dom,
    9.17 -        .u.alloc_unbound.port = (port != NULL) ? *port : 0 };
    9.18 +        .u.alloc_unbound.dom = (domid_t)dom,
    9.19 +        .u.alloc_unbound.remote_dom = (domid_t)remote_dom };
    9.20  
    9.21      if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
    9.22 -    {
    9.23 -        if ( port != NULL )
    9.24 -            *port = op.u.alloc_unbound.port;
    9.25 -    }
    9.26 -    
    9.27 -    return rc;
    9.28 -}
    9.29 -
    9.30 -
    9.31 -int xc_evtchn_bind_interdomain(int xc_handle,
    9.32 -                               u32 dom1,
    9.33 -                               u32 dom2,
    9.34 -                               int *port1,
    9.35 -                               int *port2)
    9.36 -{
    9.37 -    int         rc;
    9.38 -    evtchn_op_t op = {
    9.39 -        .cmd = EVTCHNOP_bind_interdomain,
    9.40 -        .u.bind_interdomain.dom1  = (domid_t)dom1,
    9.41 -        .u.bind_interdomain.dom2  = (domid_t)dom2,
    9.42 -        .u.bind_interdomain.port1 = (port1 != NULL) ? *port1 : 0,
    9.43 -        .u.bind_interdomain.port2 = (port2 != NULL) ? *port2 : 0 };
    9.44 -
    9.45 -    if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
    9.46 -    {
    9.47 -        if ( port1 != NULL )
    9.48 -            *port1 = op.u.bind_interdomain.port1;
    9.49 -        if ( port2 != NULL )
    9.50 -            *port2 = op.u.bind_interdomain.port2;
    9.51 -    }
    9.52 +        rc = op.u.alloc_unbound.port;
    9.53      
    9.54      return rc;
    9.55  }
    9.56  
    9.57  
    9.58 -int xc_evtchn_bind_virq(int xc_handle,
    9.59 -                        int virq,
    9.60 -                        int *port)
    9.61 -{
    9.62 -    int         rc;
    9.63 -    evtchn_op_t op = {
    9.64 -        .cmd = EVTCHNOP_bind_virq,
    9.65 -        .u.bind_virq.virq = (u32)virq,
    9.66 -        .u.bind_virq.vcpu = 0 };
    9.67 -
    9.68 -    if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
    9.69 -    {
    9.70 -        if ( port != NULL )
    9.71 -            *port = op.u.bind_virq.port;
    9.72 -    }
    9.73 -    
    9.74 -    return rc;
    9.75 -}
    9.76 -
    9.77 -
    9.78 -int xc_evtchn_close(int xc_handle,
    9.79 -                    u32 dom,
    9.80 -                    int port)
    9.81 -{
    9.82 -    evtchn_op_t op = {
    9.83 -        .cmd          = EVTCHNOP_close,
    9.84 -        .u.close.dom  = (domid_t)dom,
    9.85 -        .u.close.port = port };
    9.86 -    return do_evtchn_op(xc_handle, &op);
    9.87 -}
    9.88 -
    9.89 -
    9.90 -int xc_evtchn_send(int xc_handle,
    9.91 -                   int local_port)
    9.92 -{
    9.93 -    evtchn_op_t op = {
    9.94 -        .cmd = EVTCHNOP_send,
    9.95 -        .u.send.local_port = local_port };
    9.96 -    return do_evtchn_op(xc_handle, &op);
    9.97 -}
    9.98 -
    9.99 -
   9.100  int xc_evtchn_status(int xc_handle,
   9.101                       u32 dom,
   9.102                       int port,
    10.1 --- a/tools/libxc/xenctrl.h	Thu Oct 06 19:41:29 2005 +0100
    10.2 +++ b/tools/libxc/xenctrl.h	Thu Oct 06 19:43:11 2005 +0100
    10.3 @@ -306,68 +306,14 @@ typedef evtchn_status_t xc_evtchn_status
    10.4   * well-known port within a domain to receive events on.
    10.5   *
    10.6   * @parm xc_handle a handle to an open hypervisor interface
    10.7 + * @parm dom the ID of the local domain (the 'allocatee')
    10.8   * @parm remote_dom the ID of the domain who will later bind
    10.9 - * @parm dom the ID of the local domain (the 'allocatee')
   10.10 - * @parm port a pointer to a port.  This is an in/out parameter.  If *port is
   10.11 - *            0, then a new port will be assigned, if port is > 0 then that
   10.12 - *            port is allocated if the port is unallocated.
   10.13 - * @return 0 on success, -1 on failure
   10.14 + * @return allocated port (in @dom) on success, -1 on failure
   10.15   */
   10.16  int xc_evtchn_alloc_unbound(int xc_handle,
   10.17 -                            u32 remote_dom,
   10.18                              u32 dom,
   10.19 -                            int *port);
   10.20 -
   10.21 -/**
   10.22 - * This function creates a pair of ports between two domains.  A port can only
   10.23 - * be bound once within a domain.
   10.24 - *
   10.25 - * @parm xc_handle a handle to an open hypervisor interface
   10.26 - * @parm dom1 one of the two domains to connect.  Can be DOMID_SELF.
   10.27 - * @parm dom2 the other domain to connect.  Can be DOMID_SELF.
   10.28 - * @parm port1 an in/out parameter.  If > 0, then try to connect *port.  If
   10.29 - *             0, then allocate a new port and store the port in *port.
   10.30 - * @parm port2 the port connected on port2.  This parameter behaves the same
   10.31 - *             way as port1.
   10.32 - * @return 0 on success, -1 on error.
   10.33 - */
   10.34 -int xc_evtchn_bind_interdomain(int xc_handle,
   10.35 -                               u32 dom1,
   10.36 -                               u32 dom2,
   10.37 -                               int *port1,
   10.38 -                               int *port2);
   10.39 -int xc_evtchn_bind_virq(int xc_handle,
   10.40 -                        int virq,
   10.41 -                        int *port);
   10.42 +                            u32 remote_dom);
   10.43  
   10.44 -/**
   10.45 - * This function will close a single port on an event channel.
   10.46 - *
   10.47 - * @parm xc_handle a handle to an open hypervisor interface
   10.48 - * @parm dom the domain that the port exists on.  May be DOMID_SELF.
   10.49 - * @parm port the port to close
   10.50 - * @return 0 on success, -1 on error
   10.51 - */
   10.52 -int xc_evtchn_close(int xc_handle,
   10.53 -                    u32 dom,   /* may be DOMID_SELF */
   10.54 -                    int port);
   10.55 -
   10.56 -/**
   10.57 - * This function generates a notify event on a bound port.
   10.58 - *
   10.59 - * Notifies can be read within Linux by opening /dev/xen/evtchn and reading
   10.60 - * a 16 bit value.  The result will be the port the event occurred on.  When
   10.61 - * events occur, the port is masked until the 16 bit port value is written back
   10.62 - * to the file.  When /dev/xen/evtchn is opened, it has to be bound via an
   10.63 - * ioctl to each port to listen on.  The ioctl for binding is _IO('E', 2).  The
   10.64 - * parameter is the port to listen on.
   10.65 - *
   10.66 - * @parm xc_handle a handle to an open hypervisor interface
   10.67 - * @parm local_port the port to generate the notify on
   10.68 - * @return 0 on success, -1 on error
   10.69 - */
   10.70 -int xc_evtchn_send(int xc_handle,
   10.71 -                   int local_port);
   10.72  int xc_evtchn_status(int xc_handle,
   10.73                       u32 dom, /* may be DOMID_SELF */
   10.74                       int port,
    11.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Thu Oct 06 19:41:29 2005 +0100
    11.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Thu Oct 06 19:43:11 2005 +0100
    11.3 @@ -433,105 +433,20 @@ static PyObject *pyxc_evtchn_alloc_unbou
    11.4      XcObject *xc = (XcObject *)self;
    11.5  
    11.6      u32 dom = DOMID_SELF, remote_dom;
    11.7 -    int port = 0;
    11.8 +    int port;
    11.9  
   11.10 -    static char *kwd_list[] = { "remote_dom", "dom", "port", NULL };
   11.11 +    static char *kwd_list[] = { "remote_dom", "dom", NULL };
   11.12  
   11.13 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|ii", kwd_list,
   11.14 -                                      &remote_dom, &dom, &port) )
   11.15 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list,
   11.16 +                                      &remote_dom, &dom) )
   11.17          return NULL;
   11.18  
   11.19 -    if ( xc_evtchn_alloc_unbound(xc->xc_handle, remote_dom, dom, &port) != 0 )
   11.20 +    if ( (port = xc_evtchn_alloc_unbound(xc->xc_handle, dom, remote_dom)) < 0 )
   11.21          return PyErr_SetFromErrno(xc_error);
   11.22  
   11.23      return PyInt_FromLong(port);
   11.24  }
   11.25  
   11.26 -static PyObject *pyxc_evtchn_bind_interdomain(PyObject *self,
   11.27 -                                              PyObject *args,
   11.28 -                                              PyObject *kwds)
   11.29 -{
   11.30 -    XcObject *xc = (XcObject *)self;
   11.31 -
   11.32 -    u32 dom1 = DOMID_SELF, dom2 = DOMID_SELF;
   11.33 -    int port1 = 0, port2 = 0;
   11.34 -
   11.35 -    static char *kwd_list[] = { "dom1", "dom2", "port1", "port2", NULL };
   11.36 -
   11.37 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iiii", kwd_list, 
   11.38 -                                      &dom1, &dom2, &port1, &port2) )
   11.39 -        return NULL;
   11.40 -
   11.41 -    if ( xc_evtchn_bind_interdomain(xc->xc_handle, dom1, 
   11.42 -                                    dom2, &port1, &port2) != 0 )
   11.43 -        return PyErr_SetFromErrno(xc_error);
   11.44 -
   11.45 -    return Py_BuildValue("{s:i,s:i}", 
   11.46 -                         "port1", port1,
   11.47 -                         "port2", port2);
   11.48 -}
   11.49 -
   11.50 -static PyObject *pyxc_evtchn_bind_virq(PyObject *self,
   11.51 -                                       PyObject *args,
   11.52 -                                       PyObject *kwds)
   11.53 -{
   11.54 -    XcObject *xc = (XcObject *)self;
   11.55 -
   11.56 -    int virq, port;
   11.57 -
   11.58 -    static char *kwd_list[] = { "virq", NULL };
   11.59 -
   11.60 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &virq) )
   11.61 -        return NULL;
   11.62 -
   11.63 -    if ( xc_evtchn_bind_virq(xc->xc_handle, virq, &port) != 0 )
   11.64 -        return PyErr_SetFromErrno(xc_error);
   11.65 -
   11.66 -    return PyInt_FromLong(port);
   11.67 -}
   11.68 -
   11.69 -static PyObject *pyxc_evtchn_close(PyObject *self,
   11.70 -                                   PyObject *args,
   11.71 -                                   PyObject *kwds)
   11.72 -{
   11.73 -    XcObject *xc = (XcObject *)self;
   11.74 -
   11.75 -    u32 dom = DOMID_SELF;
   11.76 -    int port;
   11.77 -
   11.78 -    static char *kwd_list[] = { "port", "dom", NULL };
   11.79 -
   11.80 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list, 
   11.81 -                                      &port, &dom) )
   11.82 -        return NULL;
   11.83 -
   11.84 -    if ( xc_evtchn_close(xc->xc_handle, dom, port) != 0 )
   11.85 -        return PyErr_SetFromErrno(xc_error);
   11.86 -
   11.87 -    Py_INCREF(zero);
   11.88 -    return zero;
   11.89 -}
   11.90 -
   11.91 -static PyObject *pyxc_evtchn_send(PyObject *self,
   11.92 -                                  PyObject *args,
   11.93 -                                  PyObject *kwds)
   11.94 -{
   11.95 -    XcObject *xc = (XcObject *)self;
   11.96 -
   11.97 -    int port;
   11.98 -
   11.99 -    static char *kwd_list[] = { "port", NULL };
  11.100 -
  11.101 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &port) )
  11.102 -        return NULL;
  11.103 -
  11.104 -    if ( xc_evtchn_send(xc->xc_handle, port) != 0 )
  11.105 -        return PyErr_SetFromErrno(xc_error);
  11.106 -
  11.107 -    Py_INCREF(zero);
  11.108 -    return zero;
  11.109 -}
  11.110 -
  11.111  static PyObject *pyxc_evtchn_status(PyObject *self,
  11.112                                      PyObject *args,
  11.113                                      PyObject *kwds)
  11.114 @@ -1032,38 +947,6 @@ static PyMethodDef pyxc_methods[] = {
  11.115        " dom [int]: Remote domain to accept connections from.\n\n"
  11.116        "Returns: [int] Unbound event-channel port.\n" },
  11.117  
  11.118 -    { "evtchn_bind_interdomain", 
  11.119 -      (PyCFunction)pyxc_evtchn_bind_interdomain, 
  11.120 -      METH_VARARGS | METH_KEYWORDS, "\n"
  11.121 -      "Open an event channel between two domains.\n"
  11.122 -      " dom1 [int, SELF]: First domain to be connected.\n"
  11.123 -      " dom2 [int, SELF]: Second domain to be connected.\n\n"
  11.124 -      "Returns: [dict] dictionary is empty on failure.\n"
  11.125 -      " port1 [int]: Port-id for endpoint at dom1.\n"
  11.126 -      " port2 [int]: Port-id for endpoint at dom2.\n" },
  11.127 -
  11.128 -    { "evtchn_bind_virq", 
  11.129 -      (PyCFunction)pyxc_evtchn_bind_virq, 
  11.130 -      METH_VARARGS | METH_KEYWORDS, "\n"
  11.131 -      "Bind an event channel to the specified VIRQ.\n"
  11.132 -      " virq [int]: VIRQ to bind.\n\n"
  11.133 -      "Returns: [int] Bound event-channel port.\n" },
  11.134 -
  11.135 -    { "evtchn_close", 
  11.136 -      (PyCFunction)pyxc_evtchn_close, 
  11.137 -      METH_VARARGS | METH_KEYWORDS, "\n"
  11.138 -      "Close an event channel. If interdomain, sets remote end to 'unbound'.\n"
  11.139 -      " dom  [int, SELF]: Dom-id of one endpoint of the channel.\n"
  11.140 -      " port [int]:       Port-id of one endpoint of the channel.\n\n"
  11.141 -      "Returns: [int] 0 on success; -1 on error.\n" },
  11.142 -
  11.143 -    { "evtchn_send", 
  11.144 -      (PyCFunction)pyxc_evtchn_send, 
  11.145 -      METH_VARARGS | METH_KEYWORDS, "\n"
  11.146 -      "Send an event along a locally-connected event channel.\n"
  11.147 -      " port [int]: Port-id of a local channel endpoint.\n\n"
  11.148 -      "Returns: [int] 0 on success; -1 on error.\n" },
  11.149 -
  11.150      { "evtchn_status", 
  11.151        (PyCFunction)pyxc_evtchn_status, 
  11.152        METH_VARARGS | METH_KEYWORDS, "\n"
    12.1 --- a/tools/python/xen/xend/XendCheckpoint.py	Thu Oct 06 19:41:29 2005 +0100
    12.2 +++ b/tools/python/xen/xend/XendCheckpoint.py	Thu Oct 06 19:43:11 2005 +0100
    12.3 @@ -126,8 +126,8 @@ def restore(xd, fd):
    12.4              raise XendError(
    12.5                  "not a valid guest state file: pfn count out of range")
    12.6  
    12.7 -        store_evtchn = dominfo.store_channel.port2
    12.8 -        console_evtchn = dominfo.console_channel.port2
    12.9 +        store_evtchn = dominfo.store_channel
   12.10 +        console_evtchn = dominfo.console_channel
   12.11  
   12.12          cmd = [PATH_XC_RESTORE, str(xc.handle()), str(fd),
   12.13                 str(dominfo.getDomid()), str(nr_pfns),
   12.14 @@ -146,7 +146,7 @@ def restore(xd, fd):
   12.15                            dominfo.getDomainPath())
   12.16                  IntroduceDomain(dominfo.getDomid(),
   12.17                                  store_mfn,
   12.18 -                                dominfo.store_channel.port1,
   12.19 +                                dominfo.store_channel,
   12.20                                  dominfo.getDomainPath())
   12.21              else:
   12.22                  m = re.match(r"^(console-mfn) (\d+)$", line)
    13.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Oct 06 19:41:29 2005 +0100
    13.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Oct 06 19:43:11 2005 +0100
    13.3 @@ -32,8 +32,6 @@ import errno
    13.4  import xen.lowlevel.xc
    13.5  from xen.util.blkif import blkdev_uname_to_file
    13.6  
    13.7 -from xen.xend.server import channel
    13.8 -
    13.9  from xen.xend import image
   13.10  from xen.xend import scheduler
   13.11  from xen.xend import sxp
   13.12 @@ -785,32 +783,6 @@ class XendDomainInfo:
   13.13                            self.domid, self.info['name'])
   13.14  
   13.15  
   13.16 -    def closeChannel(self, chan, entry):
   13.17 -        """Close the given channel, if set, and remove the given entry in the
   13.18 -        store.  Nothrow guarantee."""
   13.19 -        
   13.20 -        if chan:
   13.21 -            chan.close()
   13.22 -        try:
   13.23 -            self.removeDom(entry)
   13.24 -        except:
   13.25 -            log.exception('Removing entry %s failed', entry)
   13.26 -        
   13.27 -
   13.28 -    def closeStoreChannel(self):
   13.29 -        """Close the store channel, if any.  Nothrow guarantee."""
   13.30 -
   13.31 -        self.closeChannel(self.store_channel, "store/port")
   13.32 -        self.store_channel = None
   13.33 -
   13.34 -
   13.35 -    def closeConsoleChannel(self):
   13.36 -        """Close the console channel, if any.  Nothrow guarantee."""
   13.37 -
   13.38 -        self.closeChannel(self.console_channel, "console/port")
   13.39 -        self.console_channel = None
   13.40 -
   13.41 -
   13.42      ## public:
   13.43  
   13.44      def setConsoleRef(self, ref):
   13.45 @@ -964,12 +936,8 @@ class XendDomainInfo:
   13.46              sxpr.append(['up_time', str(up_time) ])
   13.47              sxpr.append(['start_time', str(self.info['start_time']) ])
   13.48  
   13.49 -        if self.store_channel:
   13.50 -            sxpr.append(self.store_channel.sxpr())
   13.51          if self.store_mfn:
   13.52              sxpr.append(['store_mfn', self.store_mfn])
   13.53 -        if self.console_channel:
   13.54 -            sxpr.append(['console_channel', self.console_channel.sxpr()])
   13.55          if self.console_mfn:
   13.56              sxpr.append(['console_mfn', self.console_mfn])
   13.57  
   13.58 @@ -1077,7 +1045,7 @@ class XendDomainInfo:
   13.59          self.create_channel()
   13.60          self.image.createImage()
   13.61          IntroduceDomain(self.domid, self.store_mfn,
   13.62 -                        self.store_channel.port1, self.dompath)
   13.63 +                        self.store_channel, self.dompath)
   13.64  
   13.65  
   13.66      ## public:
   13.67 @@ -1087,8 +1055,6 @@ class XendDomainInfo:
   13.68          guarantee."""
   13.69  
   13.70          self.release_devices()
   13.71 -        self.closeStoreChannel()
   13.72 -        self.closeConsoleChannel()
   13.73  
   13.74          if self.image:
   13.75              try:
   13.76 @@ -1168,35 +1134,22 @@ class XendDomainInfo:
   13.77          
   13.78          @param path under which port is stored in db
   13.79          """
   13.80 -        port = 0
   13.81          if path:
   13.82              try:
   13.83 -                port = int(self.readDom(path))
   13.84 +                return int(self.readDom(path))
   13.85              except:
   13.86                  # The port is not yet set, i.e. the channel has not yet been
   13.87                  # created.
   13.88                  pass
   13.89  
   13.90 -        # Stale port information from above causes an Invalid Argument to be
   13.91 -        # thrown by the eventChannel call below.  To recover, we throw away
   13.92 -        # port if it turns out to be bad, and just create a new channel.
   13.93 -        # If creating a new channel with two new ports fails, then something
   13.94 -        # else is going wrong, so we bail.
   13.95 -        while True:
   13.96 -            try:
   13.97 -                ret = channel.eventChannel(0, self.domid, port1 = port,
   13.98 -                                           port2 = 0)
   13.99 -                break
  13.100 -            except:
  13.101 -                log.exception("Exception in eventChannel(0, %d, %d, %d)",
  13.102 -                              self.domid, port, 0)
  13.103 -                if port == 0:
  13.104 -                    raise
  13.105 -                else:
  13.106 -                    port = 0
  13.107 -                    log.error("Recovering from above exception.")
  13.108 -        self.storeDom(path, ret.port1)
  13.109 -        return ret
  13.110 +        try:
  13.111 +            port = xc.evtchn_alloc_unbound(dom=self.domid, remote_dom=0)
  13.112 +        except:
  13.113 +            log.exception("Exception in alloc_unbound(%d)", self.domid)
  13.114 +            raise
  13.115 +
  13.116 +        self.storeDom(path, port)
  13.117 +        return port
  13.118  
  13.119      def create_channel(self):
  13.120          """Create the channels to the domain.
  13.121 @@ -1423,11 +1376,11 @@ class XendDomainInfo:
  13.122  
  13.123  
  13.124      def initStoreConnection(self):
  13.125 -        ref = xc.init_store(self.store_channel.port2)
  13.126 +        ref = xc.init_store(self.store_channel)
  13.127          if ref and ref >= 0:
  13.128              self.setStoreRef(ref)
  13.129              try:
  13.130 -                IntroduceDomain(self.domid, ref, self.store_channel.port1,
  13.131 +                IntroduceDomain(self.domid, ref, self.store_channel,
  13.132                                  self.dompath)
  13.133              except RuntimeError, ex:
  13.134                  if ex.args[0] == errno.EISCONN:
    14.1 --- a/tools/python/xen/xend/image.py	Thu Oct 06 19:41:29 2005 +0100
    14.2 +++ b/tools/python/xen/xend/image.py	Thu Oct 06 19:43:11 2005 +0100
    14.3 @@ -25,8 +25,6 @@ from xen.xend import sxp
    14.4  from xen.xend.XendError import VmError
    14.5  from xen.xend.XendLogging import log
    14.6  
    14.7 -from xen.xend.server import channel
    14.8 -
    14.9  
   14.10  xc = xen.lowlevel.xc.new()
   14.11  
   14.12 @@ -168,11 +166,11 @@ class LinuxImageHandler(ImageHandler):
   14.13  
   14.14      def buildDomain(self):
   14.15          if self.vm.store_channel:
   14.16 -            store_evtchn = self.vm.store_channel.port2
   14.17 +            store_evtchn = self.vm.store_channel
   14.18          else:
   14.19              store_evtchn = 0
   14.20          if self.vm.console_channel:
   14.21 -            console_evtchn = self.vm.console_channel.port2
   14.22 +            console_evtchn = self.vm.console_channel
   14.23          else:
   14.24              console_evtchn = 0
   14.25  
   14.26 @@ -228,16 +226,17 @@ class VmxImageHandler(ImageHandler):
   14.27  
   14.28      def buildDomain(self):
   14.29          # Create an event channel
   14.30 -        self.device_channel = channel.eventChannel(0, self.vm.getDomid())
   14.31 -        log.info("VMX device model port: %d", self.device_channel.port2)
   14.32 +        self.device_channel = xc.evtchn_alloc_unbound(dom=self.vm.getDomid(),
   14.33 +                                                      remote_dom=0)
   14.34 +        log.info("VMX device model port: %d", self.device_channel)
   14.35          if self.vm.store_channel:
   14.36 -            store_evtchn = self.vm.store_channel.port2
   14.37 +            store_evtchn = self.vm.store_channel
   14.38          else:
   14.39              store_evtchn = 0
   14.40  
   14.41          log.debug("dom            = %d", self.vm.getDomid())
   14.42          log.debug("image          = %s", self.kernel)
   14.43 -        log.debug("control_evtchn = %d", self.device_channel.port2)
   14.44 +        log.debug("control_evtchn = %d", self.device_channel)
   14.45          log.debug("store_evtchn   = %d", store_evtchn)
   14.46          log.debug("memsize        = %d", self.vm.getMemoryTarget() / 1024)
   14.47          log.debug("flags          = %d", self.flags)
   14.48 @@ -245,7 +244,7 @@ class VmxImageHandler(ImageHandler):
   14.49  
   14.50          ret = xc.vmx_build(dom            = self.vm.getDomid(),
   14.51                             image          = self.kernel,
   14.52 -                           control_evtchn = self.device_channel.port2,
   14.53 +                           control_evtchn = self.device_channel,
   14.54                             store_evtchn   = store_evtchn,
   14.55                             memsize        = self.vm.getMemoryTarget() / 1024,
   14.56                             flags          = self.flags,
   14.57 @@ -334,7 +333,7 @@ class VmxImageHandler(ImageHandler):
   14.58          if len(vnc):
   14.59              args = args + vnc
   14.60          args = args + ([ "-d",  "%d" % self.vm.getDomid(),
   14.61 -                  "-p", "%d" % self.device_channel.port1,
   14.62 +                  "-p", "%d" % self.device_channel,
   14.63                    "-m", "%s" % (self.vm.getMemoryTarget() / 1024)])
   14.64          args = args + self.dmargs
   14.65          env = dict(os.environ)
   14.66 @@ -358,8 +357,6 @@ class VmxImageHandler(ImageHandler):
   14.67          return vncconnect
   14.68  
   14.69      def destroy(self):
   14.70 -        if self.device_channel:
   14.71 -            self.device_channel.close()
   14.72          import signal
   14.73          if not self.pid:
   14.74              return
    15.1 --- a/tools/python/xen/xend/server/channel.py	Thu Oct 06 19:41:29 2005 +0100
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,76 +0,0 @@
    15.4 -#============================================================================
    15.5 -# This library is free software; you can redistribute it and/or
    15.6 -# modify it under the terms of version 2.1 of the GNU Lesser General Public
    15.7 -# License as published by the Free Software Foundation.
    15.8 -#
    15.9 -# This library is distributed in the hope that it will be useful,
   15.10 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.11 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15.12 -# Lesser General Public License for more details.
   15.13 -#
   15.14 -# You should have received a copy of the GNU Lesser General Public
   15.15 -# License along with this library; if not, write to the Free Software
   15.16 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   15.17 -#============================================================================
   15.18 -# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
   15.19 -# Copyright (C) 2005 XenSource Ltd
   15.20 -#============================================================================
   15.21 -
   15.22 -import xen.lowlevel.xc
   15.23 -
   15.24 -from xen.xend.XendLogging import log
   15.25 -
   15.26 -
   15.27 -xc = xen.lowlevel.xc.new()
   15.28 -
   15.29 -
   15.30 -class EventChannel:
   15.31 -    """An event channel between domains.
   15.32 -    """
   15.33 -
   15.34 -    def __init__(self, dom1, dom2, port1, port2):
   15.35 -        self.dom1 = dom1
   15.36 -        self.dom2 = dom2
   15.37 -        self.port1 = port1
   15.38 -        self.port2 = port2
   15.39 -
   15.40 -
   15.41 -    def close(self):
   15.42 -        """Close the event channel.  Nothrow guarantee.
   15.43 -        """
   15.44 -        def evtchn_close(dom, port):
   15.45 -            try:
   15.46 -                xc.evtchn_close(dom=dom, port=port)
   15.47 -            except Exception:
   15.48 -                log.exception("Exception closing event channel %d, %d.", dom,
   15.49 -                              port)
   15.50 -            
   15.51 -        evtchn_close(self.dom1, self.port1)
   15.52 -        evtchn_close(self.dom2, self.port2)
   15.53 -
   15.54 -
   15.55 -    def sxpr(self):
   15.56 -        return ['event-channel',
   15.57 -                ['dom1',  self.dom1  ],
   15.58 -                ['port1', self.port1 ],
   15.59 -                ['dom2',  self.dom2  ],
   15.60 -                ['port2', self.port2 ]
   15.61 -                ]
   15.62 -
   15.63 -
   15.64 -    def __repr__(self):
   15.65 -        return ("<EventChannel dom1:%d:%d dom2:%d:%d>"
   15.66 -                % (self.dom1, self.port1, self.dom2, self.port2))
   15.67 -
   15.68 -
   15.69 -def eventChannel(dom1, dom2, port1 = 0, port2 = 0):
   15.70 -    """Create an event channel between domains.
   15.71 -        
   15.72 -    @return EventChannel (None on error)
   15.73 -    """
   15.74 -    v = xc.evtchn_bind_interdomain(dom1=dom1, dom2=dom2,
   15.75 -                                   port1=port1, port2=port2)
   15.76 -    if v and v.get('port1'):
   15.77 -        return EventChannel(dom1, dom2, v['port1'], v['port2'])
   15.78 -    else:
   15.79 -        return None
    16.1 --- a/tools/xenstore/Makefile	Thu Oct 06 19:41:29 2005 +0100
    16.2 +++ b/tools/xenstore/Makefile	Thu Oct 06 19:43:11 2005 +0100
    16.3 @@ -29,7 +29,7 @@ CLIENTS_OBJS := $(patsubst xenstore-%,xe
    16.4  
    16.5  all: libxenstore.so xenstored $(CLIENTS) xs_tdb_dump
    16.6  
    16.7 -testcode: xs_test xenstored_test xs_random xs_dom0_test
    16.8 +testcode: xs_test xenstored_test xs_random
    16.9  
   16.10  xenstored: xenstored_core.o xenstored_watch.o xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o tdb.o
   16.11  	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxenctrl -o $@
   16.12 @@ -74,7 +74,7 @@ libxenstore.so: xs.opic xs_lib.opic
   16.13  clean: testsuite-clean
   16.14  	rm -f *.o *.opic *.so
   16.15  	rm -f xenstored xs_random xs_stress xs_crashme
   16.16 -	rm -f xs_test xenstored_test xs_dom0_test
   16.17 +	rm -f xs_test xenstored_test
   16.18  	$(RM) $(PROG_DEP)
   16.19  
   16.20  print-dir:
   16.21 @@ -120,9 +120,6 @@ stresstest: xs_stress xenstored_test $(T
   16.22  	rm -rf $(TESTDIR)/store $(TESTDIR)/transactions
   16.23  	export $(TESTENV); PID=`./xenstored_test --output-pid --trace-file=/tmp/trace`; ./xs_stress 5000; ret=$$?; kill $$PID; exit $$ret
   16.24  
   16.25 -xs_dom0_test: xs_dom0_test.o utils.o
   16.26 -	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxenctrl -o $@
   16.27 -
   16.28  TAGS:
   16.29  	etags `find . -name '*.[ch]'`
   16.30  
    17.1 --- a/tools/xenstore/fake_libxc.c	Thu Oct 06 19:41:29 2005 +0100
    17.2 +++ b/tools/xenstore/fake_libxc.c	Thu Oct 06 19:43:11 2005 +0100
    17.3 @@ -36,12 +36,11 @@ static int xs_test_pid;
    17.4  static u16 port;
    17.5  
    17.6  /* The event channel maps to a signal, shared page to an mmapped file. */
    17.7 -int xc_evtchn_send(int xc_handle __attribute__((unused)), int local_port)
    17.8 +void evtchn_notify(int local_port)
    17.9  {
   17.10  	assert(local_port == port);
   17.11  	if (kill(xs_test_pid, SIGUSR2) != 0)
   17.12  		barf_perror("fake event channel failed");
   17.13 -	return 0;
   17.14  }
   17.15  
   17.16  void *xc_map_foreign_range(int xc_handle, u32 dom __attribute__((unused)),
   17.17 @@ -107,15 +106,6 @@ int xc_domain_getinfo(int xc_handle __at
   17.18  	return 1;
   17.19  }
   17.20  
   17.21 -int xc_evtchn_bind_virq(int xc_handle __attribute__((unused)),
   17.22 -			int virq __attribute__((unused)),
   17.23 -			int *port)
   17.24 -{
   17.25 -	if (port)
   17.26 -		*port = 0;
   17.27 -	return 0;
   17.28 -}
   17.29 -
   17.30  static void send_to_fd(int signo __attribute__((unused)))
   17.31  {
   17.32  	int saved_errno = errno;
    18.1 --- a/tools/xenstore/xenstored_core.c	Thu Oct 06 19:41:29 2005 +0100
    18.2 +++ b/tools/xenstore/xenstored_core.c	Thu Oct 06 19:43:11 2005 +0100
    18.3 @@ -52,6 +52,8 @@
    18.4  #include "xenctrl.h"
    18.5  #include "tdb.h"
    18.6  
    18.7 +int event_fd;
    18.8 +
    18.9  static bool verbose;
   18.10  LIST_HEAD(connections);
   18.11  static int tracefd = -1;
   18.12 @@ -309,8 +311,7 @@ static int destroy_conn(void *_conn)
   18.13  	return 0;
   18.14  }
   18.15  
   18.16 -static int initialize_set(fd_set *inset, fd_set *outset, int sock, int ro_sock,
   18.17 -			  int event_fd)
   18.18 +static int initialize_set(fd_set *inset, fd_set *outset, int sock, int ro_sock)
   18.19  {
   18.20  	struct connection *i;
   18.21  	int max;
   18.22 @@ -1464,7 +1465,7 @@ static struct option options[] = {
   18.23  
   18.24  int main(int argc, char *argv[])
   18.25  {
   18.26 -	int opt, *sock, *ro_sock, event_fd, max;
   18.27 +	int opt, *sock, *ro_sock, max;
   18.28  	struct sockaddr_un addr;
   18.29  	fd_set inset, outset;
   18.30  	bool dofork = true;
   18.31 @@ -1568,7 +1569,7 @@ int main(int argc, char *argv[])
   18.32  #endif
   18.33  
   18.34  	/* Get ready to listen to the tools. */
   18.35 -	max = initialize_set(&inset, &outset, *sock, *ro_sock, event_fd);
   18.36 +	max = initialize_set(&inset, &outset, *sock, *ro_sock);
   18.37  
   18.38  	/* Main loop. */
   18.39  	/* FIXME: Rewrite so noone can starve. */
   18.40 @@ -1588,7 +1589,7 @@ int main(int argc, char *argv[])
   18.41  			accept_connection(*ro_sock, false);
   18.42  
   18.43  		if (FD_ISSET(event_fd, &inset))
   18.44 -			handle_event(event_fd);
   18.45 +			handle_event();
   18.46  
   18.47  		list_for_each_entry(i, &connections, list) {
   18.48  			if (i->domain)
   18.49 @@ -1624,7 +1625,6 @@ int main(int argc, char *argv[])
   18.50  			}
   18.51  		}
   18.52  
   18.53 -		max = initialize_set(&inset, &outset, *sock, *ro_sock,
   18.54 -				     event_fd);
   18.55 +		max = initialize_set(&inset, &outset, *sock, *ro_sock);
   18.56  	}
   18.57  }
    19.1 --- a/tools/xenstore/xenstored_core.h	Thu Oct 06 19:41:29 2005 +0100
    19.2 +++ b/tools/xenstore/xenstored_core.h	Thu Oct 06 19:43:11 2005 +0100
    19.3 @@ -173,4 +173,6 @@ void trace_destroy(const void *data, con
    19.4  void trace_watch_timeout(const struct connection *conn, const char *node, const char *token);
    19.5  void trace(const char *fmt, ...);
    19.6  
    19.7 +extern int event_fd;
    19.8 +
    19.9  #endif /* _XENSTORED_CORE_H */
    20.1 --- a/tools/xenstore/xenstored_domain.c	Thu Oct 06 19:41:29 2005 +0100
    20.2 +++ b/tools/xenstore/xenstored_domain.c	Thu Oct 06 19:43:11 2005 +0100
    20.3 @@ -36,6 +36,8 @@
    20.4  #include "xenstored_watch.h"
    20.5  #include "xenstored_test.h"
    20.6  
    20.7 +#include <xen/linux/evtchn.h>
    20.8 +
    20.9  static int *xc_handle;
   20.10  static int eventchn_fd;
   20.11  static int virq_port;
   20.12 @@ -77,8 +79,16 @@ struct ringbuf_head
   20.13  	char buf[0];
   20.14  } __attribute__((packed));
   20.15  
   20.16 -#define EVENTCHN_BIND		_IO('E', 2)
   20.17 -#define EVENTCHN_UNBIND 	_IO('E', 3)
   20.18 +#ifndef TESTING
   20.19 +static void evtchn_notify(int port)
   20.20 +{
   20.21 +	struct ioctl_evtchn_notify notify;
   20.22 +	notify.port = port;
   20.23 +	(void)ioctl(event_fd, IOCTL_EVTCHN_NOTIFY, &notify);
   20.24 +}
   20.25 +#else
   20.26 +extern void evtchn_notify(int port);
   20.27 +#endif
   20.28  
   20.29  /* FIXME: Mark connection as broken (close it?) when this happens. */
   20.30  static bool check_buffer(const struct ringbuf_head *h)
   20.31 @@ -165,9 +175,7 @@ static int writechn(struct connection *c
   20.32  	memcpy(dest, data, len);
   20.33  	mb();
   20.34  	update_output_chunk(conn->domain->output, len);
   20.35 -	/* FIXME: Probably not neccessary. */
   20.36 -	mb();
   20.37 -	xc_evtchn_send(*xc_handle, conn->domain->port);
   20.38 +	evtchn_notify(conn->domain->port);
   20.39  	return len;
   20.40  }
   20.41  
   20.42 @@ -200,21 +208,24 @@ static int readchn(struct connection *co
   20.43  
   20.44  	/* If it was full, tell them we've taken some. */
   20.45  	if (was_full)
   20.46 -		xc_evtchn_send(*xc_handle, conn->domain->port);
   20.47 +		evtchn_notify(conn->domain->port);
   20.48  	return len;
   20.49  }
   20.50  
   20.51  static int destroy_domain(void *_domain)
   20.52  {
   20.53  	struct domain *domain = _domain;
   20.54 +	struct ioctl_evtchn_unbind unbind;
   20.55  
   20.56  	list_del(&domain->list);
   20.57  
   20.58 -	if (domain->port &&
   20.59 -	    (ioctl(eventchn_fd, EVENTCHN_UNBIND, domain->port) != 0))
   20.60 -		eprintf("> Unbinding port %i failed!\n", domain->port);
   20.61 +	if (domain->port) {
   20.62 +		unbind.port = domain->port;
   20.63 +		if (ioctl(eventchn_fd, IOCTL_EVTCHN_UNBIND, &unbind) == -1)
   20.64 +			eprintf("> Unbinding port %i failed!\n", domain->port);
   20.65 +	}
   20.66  
   20.67 -	if(domain->page)
   20.68 +	if (domain->page)
   20.69  		munmap(domain->page, getpagesize());
   20.70  
   20.71  	return 0;
   20.72 @@ -247,7 +258,7 @@ static void domain_cleanup(void)
   20.73  }
   20.74  
   20.75  /* We scan all domains rather than use the information given here. */
   20.76 -void handle_event(int event_fd)
   20.77 +void handle_event(void)
   20.78  {
   20.79  	u16 port;
   20.80  
   20.81 @@ -278,6 +289,9 @@ static struct domain *new_domain(void *c
   20.82  				 const char *path)
   20.83  {
   20.84  	struct domain *domain;
   20.85 +	struct ioctl_evtchn_bind_interdomain bind;
   20.86 +	int rc;
   20.87 +
   20.88  	domain = talloc(context, struct domain);
   20.89  	domain->port = 0;
   20.90  	domain->shutdown = 0;
   20.91 @@ -298,10 +312,13 @@ static struct domain *new_domain(void *c
   20.92  	domain->output = domain->page + getpagesize()/2;
   20.93  
   20.94  	/* Tell kernel we're interested in this event. */
   20.95 -	if (ioctl(eventchn_fd, EVENTCHN_BIND, port) != 0)
   20.96 +	bind.remote_domain = domid;
   20.97 +	bind.remote_port   = port;
   20.98 +	rc = ioctl(eventchn_fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
   20.99 +	if (rc == -1)
  20.100  		return NULL;
  20.101  
  20.102 -	domain->port = port;
  20.103 +	domain->port = rc;
  20.104  	domain->conn = new_connection(writechn, readchn);
  20.105  	domain->conn->domain = domain;
  20.106  	return domain;
  20.107 @@ -445,6 +462,8 @@ void restore_existing_connections(void)
  20.108  int domain_init(void)
  20.109  {
  20.110  	struct stat st;
  20.111 +	struct ioctl_evtchn_bind_virq bind;
  20.112 +	int rc;
  20.113  
  20.114  	/* The size of the ringbuffer: half a page minus head structure. */
  20.115  	ringbuf_datasize = getpagesize() / 2 - sizeof(struct ringbuf_head);
  20.116 @@ -482,11 +501,11 @@ int domain_init(void)
  20.117  	if (eventchn_fd < 0)
  20.118  		barf_perror("Failed to open evtchn device");
  20.119  
  20.120 -	if (xc_evtchn_bind_virq(*xc_handle, VIRQ_DOM_EXC, &virq_port))
  20.121 -		barf_perror("Failed to bind to domain exception virq");
  20.122 -
  20.123 -	if (ioctl(eventchn_fd, EVENTCHN_BIND, virq_port) != 0)
  20.124 +	bind.virq = VIRQ_DOM_EXC;
  20.125 +	rc = ioctl(eventchn_fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
  20.126 +	if (rc == -1)
  20.127  		barf_perror("Failed to bind to domain exception virq port");
  20.128 +	virq_port = rc;
  20.129  
  20.130  	return eventchn_fd;
  20.131  }
    21.1 --- a/tools/xenstore/xenstored_domain.h	Thu Oct 06 19:41:29 2005 +0100
    21.2 +++ b/tools/xenstore/xenstored_domain.h	Thu Oct 06 19:43:11 2005 +0100
    21.3 @@ -20,7 +20,7 @@
    21.4  #ifndef _XENSTORED_DOMAIN_H
    21.5  #define _XENSTORED_DOMAIN_H
    21.6  
    21.7 -void handle_event(int event_fd);
    21.8 +void handle_event(void);
    21.9  
   21.10  /* domid, mfn, eventchn, path */
   21.11  void do_introduce(struct connection *conn, struct buffered_data *in);
    22.1 --- a/tools/xenstore/xs_dom0_test.c	Thu Oct 06 19:41:29 2005 +0100
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,43 +0,0 @@
    22.4 -/* Test introduction of domain 0 */
    22.5 -#include <linux/ioctl.h>
    22.6 -#include <sys/ioctl.h>
    22.7 -#include "xs.h"
    22.8 -#include "utils.h"
    22.9 -#include <xenctrl.h>
   22.10 -#include <xen/linux/privcmd.h>
   22.11 -#include <stdio.h>
   22.12 -#include <unistd.h>
   22.13 -#include <sys/mman.h>
   22.14 -
   22.15 -int main()
   22.16 -{
   22.17 -	int h, local = 0, kernel = 0;
   22.18 -	long err;
   22.19 -	void *page;
   22.20 -
   22.21 -	h = xc_interface_open();
   22.22 -	if (h < 0)
   22.23 -		barf_perror("Failed to open xc");
   22.24 -
   22.25 -	if (xc_evtchn_bind_interdomain(h, DOMID_SELF, 0, &local, &kernel) != 0)
   22.26 -		barf_perror("Failed to bind interdomain");
   22.27 -
   22.28 -	printf("Got ports %i & %i\n", local, kernel);
   22.29 -
   22.30 -	err = ioctl(h, IOCTL_PRIVCMD_INITDOMAIN_STORE, kernel);
   22.31 -	if (err < 0)
   22.32 -		barf_perror("Failed to initialize store");
   22.33 -	printf("Got mfn %li\n", err);
   22.34 -
   22.35 -	page = xc_map_foreign_range(h, 0, getpagesize(), PROT_READ|PROT_WRITE,
   22.36 -				    err);
   22.37 -	if (!page)
   22.38 -		barf_perror("Failed to map page %li", err);
   22.39 -	printf("Mapped page at %p\n", page);
   22.40 -	printf("Page says %s\n", (char *)page);
   22.41 -	munmap(page, getpagesize());
   22.42 -	printf("unmapped\n");
   22.43 -	
   22.44 -	return 0;
   22.45 -}
   22.46 -	
    23.1 --- a/xen/common/event_channel.c	Thu Oct 06 19:41:29 2005 +0100
    23.2 +++ b/xen/common/event_channel.c	Thu Oct 06 19:43:11 2005 +0100
    23.3 @@ -36,7 +36,13 @@
    23.4  #define evtchn_from_port(d,p) \
    23.5      (&(bucket_from_port(d,p))[(p)&(EVTCHNS_PER_BUCKET-1)])
    23.6  
    23.7 -#define ERROR_EXIT(_errno) do { rc = (_errno); goto out; } while ( 0 )
    23.8 +#define ERROR_EXIT(_errno)                                          \
    23.9 +    do {                                                            \
   23.10 +        DPRINTK("EVTCHNOP failure: domain %d, error %d, line %d\n", \
   23.11 +                current->domain->domain_id, (_errno), __LINE__);    \
   23.12 +        rc = (_errno);                                              \
   23.13 +        goto out;                                                   \
   23.14 +    } while ( 0 )
   23.15  
   23.16  static int get_free_port(struct domain *d)
   23.17  {