ia64/xen-unstable

changeset 6624:29808fef9148

merge?
author cl349@firebug.cl.cam.ac.uk
date Sat Sep 03 18:24:46 2005 +0000 (2005-09-03)
parents dbded18962a4 f27205ea60ef
children 563732d616e4
files .hgignore linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c linux-2.6-xen-sparse/drivers/xen/xenbus/Makefile linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_dev.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c linux-2.6-xen-sparse/include/asm-xen/linux-public/xenbus_dev.h linux-2.6-xen-sparse/mm/memory.c tools/firmware/rombios/rombios.c tools/firmware/vmxassist/Makefile tools/firmware/vmxassist/setup.c tools/firmware/vmxassist/vm86.c tools/firmware/vmxassist/vmxloader.c tools/ioemu/exec.c tools/ioemu/hw/pcnet.c tools/ioemu/target-i386-dm/helper2.c tools/ioemu/vl.c tools/libxc/xc_linux_save.c tools/libxc/xenguest.h tools/python/xen/xend/XendCheckpoint.py tools/python/xen/xend/XendDomain.py tools/xcutils/xc_save.c tools/xenstore/Makefile tools/xenstore/xenstore_client.c tools/xenstore/xs.c tools/xenstore/xs.h tools/xenstore/xs_lib.c tools/xenstore/xs_lib.h xen/Rules.mk xen/arch/x86/vmx.c xen/arch/x86/vmx_intercept.c xen/arch/x86/vmx_io.c xen/arch/x86/vmx_platform.c xen/common/memory.c xen/include/asm-x86/vmx.h xen/include/asm-x86/vmx_platform.h xen/include/public/io/ioreq.h
line diff
     1.1 --- a/.hgignore	Sat Sep 03 18:15:39 2005 +0000
     1.2 +++ b/.hgignore	Sat Sep 03 18:24:46 2005 +0000
     1.3 @@ -153,8 +153,12 @@
     1.4  ^tools/xenstat/xentop/xentop$
     1.5  ^tools/xenstore/testsuite/tmp/.*$
     1.6  ^tools/xenstore/xen$
     1.7 +^tools/xenstore/xenbus_dev.h$
     1.8  ^tools/xenstore/xenstored$
     1.9  ^tools/xenstore/xenstored_test$
    1.10 +^tools/xenstore/xenstore-read$
    1.11 +^tools/xenstore/xenstore-rm$
    1.12 +^tools/xenstore/xenstore-write$
    1.13  ^tools/xenstore/xs_dom0_test$
    1.14  ^tools/xenstore/xs_random$
    1.15  ^tools/xenstore/xs_stress$
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Sat Sep 03 18:15:39 2005 +0000
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Sat Sep 03 18:24:46 2005 +0000
     2.3 @@ -350,6 +350,8 @@ static int evtchn_release(struct inode *
     2.4  
     2.5      spin_unlock_irq(&port_user_lock);
     2.6  
     2.7 +    kfree(u);
     2.8 +
     2.9      return 0;
    2.10  }
    2.11  
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/Makefile	Sat Sep 03 18:15:39 2005 +0000
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/Makefile	Sat Sep 03 18:24:46 2005 +0000
     3.3 @@ -4,3 +4,4 @@ xenbus-objs =
     3.4  xenbus-objs += xenbus_comms.o
     3.5  xenbus-objs += xenbus_xs.o
     3.6  xenbus-objs += xenbus_probe.o 
     3.7 +xenbus-objs += xenbus_dev.o 
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c	Sat Sep 03 18:15:39 2005 +0000
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c	Sat Sep 03 18:24:46 2005 +0000
     4.3 @@ -212,7 +212,7 @@ int xb_init_comms(void)
     4.4  		xen_start_info.store_evtchn, wake_waiting,
     4.5  		0, "xenbus", &xb_waitq);
     4.6  	if (err) {
     4.7 -		xprintk("XENBUS request irq failed %i\n", err);
     4.8 +		printk(KERN_ERR "XENBUS request irq failed %i\n", err);
     4.9  		unbind_evtchn_from_irq(xen_start_info.store_evtchn);
    4.10  		return err;
    4.11  	}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_dev.c	Sat Sep 03 18:24:46 2005 +0000
     5.3 @@ -0,0 +1,186 @@
     5.4 +/*
     5.5 + * xenbus_dev.c
     5.6 + * 
     5.7 + * Driver giving user-space access to the kernel's xenbus connection
     5.8 + * to xenstore.
     5.9 + * 
    5.10 + * Copyright (c) 2005, Christian Limpach
    5.11 + * 
    5.12 + * This file may be distributed separately from the Linux kernel, or
    5.13 + * incorporated into other software packages, subject to the following license:
    5.14 + * 
    5.15 + * Permission is hereby granted, free of charge, to any person obtaining a copy
    5.16 + * of this source file (the "Software"), to deal in the Software without
    5.17 + * restriction, including without limitation the rights to use, copy, modify,
    5.18 + * merge, publish, distribute, sublicense, and/or sell copies of the Software,
    5.19 + * and to permit persons to whom the Software is furnished to do so, subject to
    5.20 + * the following conditions:
    5.21 + * 
    5.22 + * The above copyright notice and this permission notice shall be included in
    5.23 + * all copies or substantial portions of the Software.
    5.24 + * 
    5.25 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    5.26 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    5.27 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    5.28 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    5.29 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    5.30 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
    5.31 + * IN THE SOFTWARE.
    5.32 + */
    5.33 +
    5.34 +#include <linux/config.h>
    5.35 +#include <linux/kernel.h>
    5.36 +#include <linux/errno.h>
    5.37 +#include <linux/uio.h>
    5.38 +#include <linux/notifier.h>
    5.39 +#include <linux/wait.h>
    5.40 +#include <linux/fs.h>
    5.41 +
    5.42 +#include "xenstored.h"
    5.43 +#include "xenbus_comms.h"
    5.44 +
    5.45 +#include <asm/uaccess.h>
    5.46 +#include <asm-xen/xenbus.h>
    5.47 +#include <asm-xen/linux-public/xenbus_dev.h>
    5.48 +#include <asm-xen/xen_proc.h>
    5.49 +
    5.50 +struct xenbus_dev_data {
    5.51 +	int in_transaction;
    5.52 +};
    5.53 +
    5.54 +static struct proc_dir_entry *xenbus_dev_intf;
    5.55 +
    5.56 +void *xs_talkv(enum xsd_sockmsg_type type, const struct kvec *iovec,
    5.57 +	       unsigned int num_vecs, unsigned int *len);
    5.58 +
    5.59 +static int xenbus_dev_talkv(struct xenbus_dev_data *u, unsigned long data)
    5.60 +{
    5.61 +	struct xenbus_dev_talkv xt;
    5.62 +	unsigned int len;
    5.63 +	void *resp, *base;
    5.64 +	struct kvec *iovec;
    5.65 +	int ret = -EFAULT, v = 0;
    5.66 +
    5.67 +	if (copy_from_user(&xt, (void *)data, sizeof(xt)))
    5.68 +		return -EFAULT;
    5.69 +
    5.70 +	iovec = kmalloc(xt.num_vecs * sizeof(struct kvec), GFP_KERNEL);
    5.71 +	if (iovec == NULL)
    5.72 +		return -ENOMEM;
    5.73 +
    5.74 +	if (copy_from_user(iovec, xt.iovec,
    5.75 +			   xt.num_vecs * sizeof(struct kvec)))
    5.76 +		goto out;
    5.77 +
    5.78 +	for (v = 0; v < xt.num_vecs; v++) {
    5.79 +		base = iovec[v].iov_base;
    5.80 +		iovec[v].iov_base = kmalloc(iovec[v].iov_len, GFP_KERNEL);
    5.81 +		if (iovec[v].iov_base == NULL ||
    5.82 +		    copy_from_user(iovec[v].iov_base, base, iovec[v].iov_len))
    5.83 +		{
    5.84 +			if (iovec[v].iov_base)
    5.85 +				kfree(iovec[v].iov_base);
    5.86 +			else
    5.87 +				ret = -ENOMEM;
    5.88 +			v--;
    5.89 +			goto out;
    5.90 +		}
    5.91 +	}
    5.92 +
    5.93 +	resp = xs_talkv(xt.type, iovec, xt.num_vecs, &len);
    5.94 +	if (IS_ERR(resp)) {
    5.95 +		ret = PTR_ERR(resp);
    5.96 +		goto out;
    5.97 +	}
    5.98 +
    5.99 +	switch (xt.type) {
   5.100 +	case XS_TRANSACTION_START:
   5.101 +		u->in_transaction = 1;
   5.102 +		break;
   5.103 +	case XS_TRANSACTION_END:
   5.104 +		u->in_transaction = 0;
   5.105 +		break;
   5.106 +	default:
   5.107 +		break;
   5.108 +	}
   5.109 +
   5.110 +	ret = len;
   5.111 +	if (len > xt.len)
   5.112 +		len = xt.len;
   5.113 +
   5.114 +	if (copy_to_user(xt.buf, resp, len))
   5.115 +		ret = -EFAULT;
   5.116 +
   5.117 +	kfree(resp);
   5.118 + out:
   5.119 +	while (v-- > 0)
   5.120 +		kfree(iovec[v].iov_base);
   5.121 +	kfree(iovec);
   5.122 +	return ret;
   5.123 +}
   5.124 +
   5.125 +static int xenbus_dev_ioctl(struct inode *inode, struct file *filp,
   5.126 +			    unsigned int cmd, unsigned long data)
   5.127 +{
   5.128 +	struct xenbus_dev_data *u = filp->private_data;
   5.129 +	int ret = -ENOSYS;
   5.130 +
   5.131 +	switch (cmd) {
   5.132 +	case IOCTL_XENBUS_DEV_TALKV:
   5.133 +		ret = xenbus_dev_talkv(u, data);
   5.134 +		break;
   5.135 +	default:
   5.136 +		ret = -EINVAL;
   5.137 +		break;
   5.138 +	}
   5.139 +	return ret;
   5.140 +}
   5.141 +
   5.142 +static int xenbus_dev_open(struct inode *inode, struct file *filp)
   5.143 +{
   5.144 +	struct xenbus_dev_data *u;
   5.145 +
   5.146 +	u = kmalloc(sizeof(*u), GFP_KERNEL);
   5.147 +	if (u == NULL)
   5.148 +		return -ENOMEM;
   5.149 +
   5.150 +	memset(u, 0, sizeof(*u));
   5.151 +
   5.152 +	filp->private_data = u;
   5.153 +
   5.154 +	down(&xenbus_lock);
   5.155 +
   5.156 +	return 0;
   5.157 +}
   5.158 +
   5.159 +static int xenbus_dev_release(struct inode *inode, struct file *filp)
   5.160 +{
   5.161 +	struct xenbus_dev_data *u = filp->private_data;
   5.162 +
   5.163 +	if (u->in_transaction)
   5.164 +		xenbus_transaction_end(1);
   5.165 +
   5.166 +	up(&xenbus_lock);
   5.167 +
   5.168 +	kfree(u);
   5.169 +
   5.170 +	return 0;
   5.171 +}
   5.172 +
   5.173 +static struct file_operations xenbus_dev_file_ops = {
   5.174 +	ioctl: xenbus_dev_ioctl,
   5.175 +	open: xenbus_dev_open,
   5.176 +	release: xenbus_dev_release
   5.177 +};
   5.178 +
   5.179 +static int __init
   5.180 +xenbus_dev_init(void)
   5.181 +{
   5.182 +	xenbus_dev_intf = create_xen_proc_entry("xenbus", 0400);
   5.183 +	if (xenbus_dev_intf)
   5.184 +		xenbus_dev_intf->proc_fops = &xenbus_dev_file_ops;
   5.185 +
   5.186 +	return 0;
   5.187 +}
   5.188 +
   5.189 +__initcall(xenbus_dev_init);
     6.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Sat Sep 03 18:15:39 2005 +0000
     6.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Sat Sep 03 18:24:46 2005 +0000
     6.3 @@ -106,10 +106,10 @@ void xenbus_debug_write(const char *str,
     6.4  }
     6.5  
     6.6  /* Send message to xs, get kmalloc'ed reply.  ERR_PTR() on error. */
     6.7 -static void *xs_talkv(enum xsd_sockmsg_type type,
     6.8 -		      const struct kvec *iovec,
     6.9 -		      unsigned int num_vecs,
    6.10 -		      unsigned int *len)
    6.11 +void *xs_talkv(enum xsd_sockmsg_type type,
    6.12 +	       const struct kvec *iovec,
    6.13 +	       unsigned int num_vecs,
    6.14 +	       unsigned int *len)
    6.15  {
    6.16  	struct xsd_sockmsg msg;
    6.17  	void *ret = NULL;
    6.18 @@ -557,7 +557,7 @@ static int watch_thread(void *unused)
    6.19  			BUG_ON(!w);
    6.20  			w->callback(w, node);
    6.21  			kfree(node);
    6.22 -		} else
    6.23 +		} else if (node)
    6.24  			printk(KERN_WARNING "XENBUS xs_read_watch: %li\n",
    6.25  			       PTR_ERR(node));
    6.26  		up(&xenbus_lock);
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/linux-public/xenbus_dev.h	Sat Sep 03 18:24:46 2005 +0000
     7.3 @@ -0,0 +1,47 @@
     7.4 +/*
     7.5 + * xenbus_dev.h
     7.6 + * 
     7.7 + * Copyright (c) 2005, Christian Limpach
     7.8 + * 
     7.9 + * This file may be distributed separately from the Linux kernel, or
    7.10 + * incorporated into other software packages, subject to the following license:
    7.11 + * 
    7.12 + * Permission is hereby granted, free of charge, to any person obtaining a copy
    7.13 + * of this source file (the "Software"), to deal in the Software without
    7.14 + * restriction, including without limitation the rights to use, copy, modify,
    7.15 + * merge, publish, distribute, sublicense, and/or sell copies of the Software,
    7.16 + * and to permit persons to whom the Software is furnished to do so, subject to
    7.17 + * the following conditions:
    7.18 + * 
    7.19 + * The above copyright notice and this permission notice shall be included in
    7.20 + * all copies or substantial portions of the Software.
    7.21 + * 
    7.22 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    7.23 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    7.24 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    7.25 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    7.26 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    7.27 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
    7.28 + * IN THE SOFTWARE.
    7.29 + */
    7.30 +
    7.31 +#ifndef _XENBUS_DEV_H_
    7.32 +#define _XENBUS_DEV_H_
    7.33 +
    7.34 +struct xenbus_dev_talkv {
    7.35 +	enum xsd_sockmsg_type type;
    7.36 +	const struct kvec *iovec;
    7.37 +	unsigned int num_vecs;
    7.38 +	char *buf;
    7.39 +	unsigned int len;
    7.40 +};
    7.41 +
    7.42 +/*
    7.43 + * @cmd: IOCTL_XENBUS_DEV_TALKV
    7.44 + * @arg: struct xenbus_dev_talkv
    7.45 + * Return: 0 on success, error code on failure.
    7.46 + */
    7.47 +#define	IOCTL_XENBUS_DEV_TALKV \
    7.48 +	_IOC(_IOC_NONE, 'X', 0, sizeof(struct xenbus_dev_talkv))
    7.49 +
    7.50 +#endif /* _XENBUS_DEV_H_ */
     8.1 --- a/tools/xenstore/Makefile	Sat Sep 03 18:15:39 2005 +0000
     8.2 +++ b/tools/xenstore/Makefile	Sat Sep 03 18:24:46 2005 +0000
     8.3 @@ -24,16 +24,28 @@ TESTDIR  = `pwd`/testsuite/tmp
     8.4  TESTFLAGS= -DTESTING
     8.5  TESTENV  = XENSTORED_ROOTDIR=$(TESTDIR) XENSTORED_RUNDIR=$(TESTDIR)
     8.6  
     8.7 -all: xen xenstored libxenstore.so
     8.8 +CLIENTS := xenstore-read xenstore-rm xenstore-write
     8.9 +CLIENTS_OBJS := $(patsubst xenstore-%,xenstore_%.o,$(CLIENTS))
    8.10 +
    8.11 +all: xen xenbus_dev.h libxenstore.so xenstored $(CLIENTS)
    8.12  
    8.13  testcode: xen xs_test xenstored_test xs_random xs_dom0_test
    8.14  
    8.15  xen:
    8.16  	ln -sf $(XEN_ROOT)/xen/include/public $@
    8.17  
    8.18 +xenbus_dev.h:
    8.19 +	ln -sf $(XEN_ROOT)/linux-2.6-xen-sparse/include/asm-xen/linux-public/xenbus_dev.h $@
    8.20 +
    8.21  xenstored: xenstored_core.o xenstored_watch.o xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o
    8.22  	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxenctrl -o $@
    8.23  
    8.24 +$(CLIENTS): xenstore-%: xenstore_%.o
    8.25 +	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxenctrl -L. -lxenstore -o $@
    8.26 +
    8.27 +$(CLIENTS_OBJS): xenstore_%.o: xenstore_client.c
    8.28 +	$(COMPILE.c) -DCLIENT_$(*F) -o $@ $<
    8.29 +
    8.30  xenstored_test: xenstored_core_test.o xenstored_watch_test.o xenstored_domain_test.o xenstored_transaction_test.o xs_lib.o talloc_test.o fake_libxc.o utils.o
    8.31  	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
    8.32  
    8.33 @@ -111,12 +123,13 @@ TAGS:
    8.34  tarball: clean
    8.35  	cd .. && tar -c -j -v -h -f xenstore.tar.bz2 xenstore/
    8.36  
    8.37 -install: xenstored libxenstore.so
    8.38 +install: libxenstore.so xenstored $(CLIENTS)
    8.39  	$(INSTALL_DIR) -p $(DESTDIR)/var/run/xenstored
    8.40  	$(INSTALL_DIR) -p $(DESTDIR)/var/lib/xenstored
    8.41  	$(INSTALL_DIR) -p $(DESTDIR)/usr/sbin
    8.42  	$(INSTALL_DIR) -p $(DESTDIR)/usr/include
    8.43  	$(INSTALL_PROG) xenstored $(DESTDIR)/usr/sbin
    8.44 +	$(INSTALL_PROG) $(CLIENTS) $(DESTDIR)/usr/bin
    8.45  	$(INSTALL_DIR) -p $(DESTDIR)/usr/$(LIBDIR)
    8.46  	$(INSTALL_DATA) libxenstore.so $(DESTDIR)/usr/$(LIBDIR)
    8.47  	$(INSTALL_DATA) xs.h $(DESTDIR)/usr/include
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/tools/xenstore/xenstore_client.c	Sat Sep 03 18:24:46 2005 +0000
     9.3 @@ -0,0 +1,130 @@
     9.4 +/*
     9.5 + * This file is subject to the terms and conditions of the GNU General
     9.6 + * Public License.  See the file "COPYING" in the main directory of
     9.7 + * this archive for more details.
     9.8 + *
     9.9 + * Copyright (C) 2005 by Christian Limpach
    9.10 + *
    9.11 + */
    9.12 +
    9.13 +#include <err.h>
    9.14 +#include <fcntl.h>
    9.15 +#include <getopt.h>
    9.16 +#include <stdio.h>
    9.17 +#include <stdlib.h>
    9.18 +#include <string.h>
    9.19 +#include <xs.h>
    9.20 +
    9.21 +static void
    9.22 +usage(const char *progname)
    9.23 +{
    9.24 +#if defined(CLIENT_read)
    9.25 +    errx(1, "Usage: %s [-h] [-p] key [...]", progname);
    9.26 +#elif defined(CLIENT_write)
    9.27 +    errx(1, "Usage: %s [-h] key value [...]", progname);
    9.28 +#elif defined(CLIENT_rm)
    9.29 +    errx(1, "Usage: %s [-h] key [...]", progname);
    9.30 +#endif
    9.31 +}
    9.32 +
    9.33 +int
    9.34 +main(int argc, char **argv)
    9.35 +{
    9.36 +    struct xs_handle *xsh;
    9.37 +    bool success;
    9.38 +    int ret = 0;
    9.39 +#if defined(CLIENT_read)
    9.40 +    char *val;
    9.41 +    int prefix = 0;
    9.42 +#endif
    9.43 +
    9.44 +    xsh = xs_domain_open();
    9.45 +    if (xsh == NULL)
    9.46 +	err(1, "xs_domain_open");
    9.47 +
    9.48 +    while (1) {
    9.49 +	int c, index = 0;
    9.50 +	static struct option long_options[] = {
    9.51 +	    {"help", 0, 0, 'h'},
    9.52 +#if defined(CLIENT_read)
    9.53 +	    {"prefix", 0, 0, 'p'},
    9.54 +#endif
    9.55 +	    {0, 0, 0, 0}
    9.56 +	};
    9.57 +
    9.58 +	c = getopt_long(argc, argv, "h"
    9.59 +#if defined(CLIENT_read)
    9.60 +			"p"
    9.61 +#endif
    9.62 +			, long_options, &index);
    9.63 +	if (c == -1)
    9.64 +	    break;
    9.65 +
    9.66 +	switch (c) {
    9.67 +	case 'h':
    9.68 +	    usage(argv[0]);
    9.69 +	    /* NOTREACHED */
    9.70 +#if defined(CLIENT_read)
    9.71 +	case 'p':
    9.72 +	    prefix = 1;
    9.73 +	    break;
    9.74 +#endif
    9.75 +	}
    9.76 +    }
    9.77 +
    9.78 +    if (optind == argc) {
    9.79 +	usage(argv[0]);
    9.80 +	/* NOTREACHED */
    9.81 +    }
    9.82 +#if defined(CLIENT_write)
    9.83 +    if ((argc - optind) % 1) {
    9.84 +	usage(argv[0]);
    9.85 +	/* NOTREACHED */
    9.86 +    }
    9.87 +#endif
    9.88 +
    9.89 +    /* XXX maybe find longest common prefix */
    9.90 +    success = xs_transaction_start(xsh, "/");
    9.91 +    if (!success)
    9.92 +	errx(1, "couldn't start transaction");
    9.93 +
    9.94 +    while (optind < argc) {
    9.95 +#if defined(CLIENT_read)
    9.96 +	val = xs_read(xsh, argv[optind], NULL);
    9.97 +	if (val == NULL) {
    9.98 +	    warnx("couldn't read path %s", argv[optind]);
    9.99 +	    ret = 1;
   9.100 +	    goto out;
   9.101 +	}
   9.102 +	if (prefix)
   9.103 +	    printf("%s: ", argv[optind]);
   9.104 +	printf("%s\n", val);
   9.105 +	free(val);
   9.106 +	optind++;
   9.107 +#elif defined(CLIENT_write)
   9.108 +	success = xs_write(xsh, argv[optind], argv[optind + 1],
   9.109 +			   strlen(argv[optind + 1]), O_CREAT);
   9.110 +	if (!success) {
   9.111 +	    warnx("could not write path %s", argv[optind]);
   9.112 +	    ret = 1;
   9.113 +	    goto out;
   9.114 +	}
   9.115 +	optind += 2;
   9.116 +#elif defined(CLIENT_rm)
   9.117 +	success = xs_rm(xsh, argv[optind]);
   9.118 +	if (!success) {
   9.119 +	    warnx("could not remove path %s", argv[optind]);
   9.120 +	    ret = 1;
   9.121 +	    goto out;
   9.122 +	}
   9.123 +	optind++;
   9.124 +#endif
   9.125 +    }
   9.126 +
   9.127 + out:
   9.128 +    success = xs_transaction_end(xsh, ret ? true : false);
   9.129 +    if (!success)
   9.130 +	errx(1, "couldn't end transaction");
   9.131 +
   9.132 +    return ret;
   9.133 +}
    10.1 --- a/tools/xenstore/xs.c	Sat Sep 03 18:15:39 2005 +0000
    10.2 +++ b/tools/xenstore/xs.c	Sat Sep 03 18:24:46 2005 +0000
    10.3 @@ -31,14 +31,17 @@
    10.4  #include <signal.h>
    10.5  #include <stdint.h>
    10.6  #include <errno.h>
    10.7 +#include <sys/ioctl.h>
    10.8  #include "xs.h"
    10.9  #include "xenstored.h"
   10.10  #include "xs_lib.h"
   10.11  #include "utils.h"
   10.12 +#include "xenbus_dev.h"
   10.13  
   10.14  struct xs_handle
   10.15  {
   10.16  	int fd;
   10.17 +	enum { SOCK, DEV } type;
   10.18  };
   10.19  
   10.20  /* Get the socket from the store daemon handle.
   10.21 @@ -65,13 +68,35 @@ static struct xs_handle *get_socket(cons
   10.22  		h = malloc(sizeof(*h));
   10.23  		if (h) {
   10.24  			h->fd = sock;
   10.25 +			h->type = SOCK;
   10.26  			return h;
   10.27  		}
   10.28  	}
   10.29  
   10.30  	saved_errno = errno;
   10.31  	close(sock);
   10.32 -	free(h);
   10.33 +	errno = saved_errno;
   10.34 +	return NULL;
   10.35 +}
   10.36 +
   10.37 +static struct xs_handle *get_dev(const char *connect_to)
   10.38 +{
   10.39 +	int fd, saved_errno;
   10.40 +	struct xs_handle *h = NULL;
   10.41 +
   10.42 +	fd = open(connect_to, O_RDONLY);
   10.43 +	if (fd < 0)
   10.44 +		return NULL;
   10.45 +
   10.46 +	h = malloc(sizeof(*h));
   10.47 +	if (h) {
   10.48 +		h->fd = fd;
   10.49 +		h->type = DEV;
   10.50 +		return h;
   10.51 +	}
   10.52 +
   10.53 +	saved_errno = errno;
   10.54 +	close(fd);
   10.55  	errno = saved_errno;
   10.56  	return NULL;
   10.57  }
   10.58 @@ -86,6 +111,11 @@ struct xs_handle *xs_daemon_open_readonl
   10.59  	return get_socket(xs_daemon_socket_ro());
   10.60  }
   10.61  
   10.62 +struct xs_handle *xs_domain_open(void)
   10.63 +{
   10.64 +	return get_dev(xs_domain_dev());
   10.65 +}
   10.66 +
   10.67  void xs_daemon_close(struct xs_handle *h)
   10.68  {
   10.69  	if (h->fd >= 0)
   10.70 @@ -160,9 +190,9 @@ static void *read_reply(int fd, enum xsd
   10.71  }
   10.72  
   10.73  /* Send message to xs, get malloc'ed reply.  NULL and set errno on error. */
   10.74 -static void *xs_talkv(struct xs_handle *h, enum xsd_sockmsg_type type,
   10.75 -		      const struct iovec *iovec, unsigned int num_vecs,
   10.76 -		      unsigned int *len)
   10.77 +static void *xs_talkv_sock(struct xs_handle *h, enum xsd_sockmsg_type type,
   10.78 +			   const struct iovec *iovec, unsigned int num_vecs,
   10.79 +			   unsigned int *len)
   10.80  {
   10.81  	struct xsd_sockmsg msg;
   10.82  	void *ret = NULL;
   10.83 @@ -223,6 +253,54 @@ close_fd:
   10.84  	return NULL;
   10.85  }
   10.86  
   10.87 +/* Send message to xs, get malloc'ed reply.  NULL and set errno on error. */
   10.88 +static void *xs_talkv_dev(struct xs_handle *h, enum xsd_sockmsg_type type,
   10.89 +			  const struct iovec *iovec, unsigned int num_vecs,
   10.90 +			  unsigned int *len)
   10.91 +{
   10.92 +	struct xenbus_dev_talkv dt;
   10.93 +	char *buf;
   10.94 +	int err, buflen = 1024;
   10.95 +
   10.96 + again:
   10.97 +	buf = malloc(buflen);
   10.98 +	if (buf == NULL) {
   10.99 +		errno = ENOMEM;
  10.100 +		return NULL;
  10.101 +	}
  10.102 +	dt.type = type;
  10.103 +	dt.iovec = (struct kvec *)iovec;
  10.104 +	dt.num_vecs = num_vecs;
  10.105 +	dt.buf = buf;
  10.106 +	dt.len = buflen;
  10.107 +	err = ioctl(h->fd, IOCTL_XENBUS_DEV_TALKV, &dt);
  10.108 +	if (err < 0) {
  10.109 +		free(buf);
  10.110 +		errno = err;
  10.111 +		return NULL;
  10.112 +	}
  10.113 +	if (err > buflen) {
  10.114 +		free(buf);
  10.115 +		buflen = err;
  10.116 +		goto again;
  10.117 +	}
  10.118 +	if (len)
  10.119 +		*len = err;
  10.120 +	return buf;
  10.121 +}
  10.122 +
  10.123 +/* Send message to xs, get malloc'ed reply.  NULL and set errno on error. */
  10.124 +static void *xs_talkv(struct xs_handle *h, enum xsd_sockmsg_type type,
  10.125 +		      const struct iovec *iovec, unsigned int num_vecs,
  10.126 +		      unsigned int *len)
  10.127 +{
  10.128 +	if (h->type == SOCK)
  10.129 +		return xs_talkv_sock(h, type, iovec, num_vecs, len);
  10.130 +	if (h->type == DEV)
  10.131 +		return xs_talkv_dev(h, type, iovec, num_vecs, len);
  10.132 +	return NULL;
  10.133 +}
  10.134 +
  10.135  /* free(), but don't change errno. */
  10.136  static void free_no_errno(void *p)
  10.137  {
    11.1 --- a/tools/xenstore/xs.h	Sat Sep 03 18:15:39 2005 +0000
    11.2 +++ b/tools/xenstore/xs.h	Sat Sep 03 18:24:46 2005 +0000
    11.3 @@ -30,6 +30,7 @@ struct xs_handle;
    11.4   * Returns a handle or NULL.
    11.5   */
    11.6  struct xs_handle *xs_daemon_open(void);
    11.7 +struct xs_handle *xs_domain_open(void);
    11.8  
    11.9  /* Connect to the xs daemon (readonly for non-root clients).
   11.10   * Returns a handle or NULL.
    12.1 --- a/tools/xenstore/xs_lib.c	Sat Sep 03 18:15:39 2005 +0000
    12.2 +++ b/tools/xenstore/xs_lib.c	Sat Sep 03 18:24:46 2005 +0000
    12.3 @@ -66,6 +66,12 @@ const char *xs_daemon_transactions(void)
    12.4  	return buf;
    12.5  }
    12.6  
    12.7 +const char *xs_domain_dev(void)
    12.8 +{
    12.9 +	char *s = getenv("XENSTORED_DOMAIN_DEV");
   12.10 +	return (s ? s : "/proc/xen/xenbus");
   12.11 +}
   12.12 +
   12.13  /* Simple routines for writing to sockets, etc. */
   12.14  bool xs_write_all(int fd, const void *data, unsigned int len)
   12.15  {
    13.1 --- a/tools/xenstore/xs_lib.h	Sat Sep 03 18:15:39 2005 +0000
    13.2 +++ b/tools/xenstore/xs_lib.h	Sat Sep 03 18:24:46 2005 +0000
    13.3 @@ -48,6 +48,7 @@ const char *xs_daemon_socket(void);
    13.4  const char *xs_daemon_socket_ro(void);
    13.5  const char *xs_daemon_store(void);
    13.6  const char *xs_daemon_transactions(void);
    13.7 +const char *xs_domain_dev(void);
    13.8  
    13.9  /* Simple write function: loops for you. */
   13.10  bool xs_write_all(int fd, const void *data, unsigned int len);