debuggers.hg

changeset 6644: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$
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Sat Sep 03 18:15:39 2005 +0000
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Sat Sep 03 18:24:46 2005 +0000
     4.3 @@ -350,6 +350,8 @@ static int evtchn_release(struct inode *
     4.4  
     4.5      spin_unlock_irq(&port_user_lock);
     4.6  
     4.7 +    kfree(u);
     4.8 +
     4.9      return 0;
    4.10  }
    4.11  
     5.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/Makefile	Sat Sep 03 18:15:39 2005 +0000
     5.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/Makefile	Sat Sep 03 18:24:46 2005 +0000
     5.3 @@ -4,3 +4,4 @@ xenbus-objs =
     5.4  xenbus-objs += xenbus_comms.o
     5.5  xenbus-objs += xenbus_xs.o
     5.6  xenbus-objs += xenbus_probe.o 
     5.7 +xenbus-objs += xenbus_dev.o 
     6.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c	Sat Sep 03 18:15:39 2005 +0000
     6.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c	Sat Sep 03 18:24:46 2005 +0000
     6.3 @@ -212,7 +212,7 @@ int xb_init_comms(void)
     6.4  		xen_start_info.store_evtchn, wake_waiting,
     6.5  		0, "xenbus", &xb_waitq);
     6.6  	if (err) {
     6.7 -		xprintk("XENBUS request irq failed %i\n", err);
     6.8 +		printk(KERN_ERR "XENBUS request irq failed %i\n", err);
     6.9  		unbind_evtchn_from_irq(xen_start_info.store_evtchn);
    6.10  		return err;
    6.11  	}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_dev.c	Sat Sep 03 18:24:46 2005 +0000
     7.3 @@ -0,0 +1,186 @@
     7.4 +/*
     7.5 + * xenbus_dev.c
     7.6 + * 
     7.7 + * Driver giving user-space access to the kernel's xenbus connection
     7.8 + * to xenstore.
     7.9 + * 
    7.10 + * Copyright (c) 2005, Christian Limpach
    7.11 + * 
    7.12 + * This file may be distributed separately from the Linux kernel, or
    7.13 + * incorporated into other software packages, subject to the following license:
    7.14 + * 
    7.15 + * Permission is hereby granted, free of charge, to any person obtaining a copy
    7.16 + * of this source file (the "Software"), to deal in the Software without
    7.17 + * restriction, including without limitation the rights to use, copy, modify,
    7.18 + * merge, publish, distribute, sublicense, and/or sell copies of the Software,
    7.19 + * and to permit persons to whom the Software is furnished to do so, subject to
    7.20 + * the following conditions:
    7.21 + * 
    7.22 + * The above copyright notice and this permission notice shall be included in
    7.23 + * all copies or substantial portions of the Software.
    7.24 + * 
    7.25 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    7.26 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    7.27 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    7.28 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    7.29 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    7.30 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
    7.31 + * IN THE SOFTWARE.
    7.32 + */
    7.33 +
    7.34 +#include <linux/config.h>
    7.35 +#include <linux/kernel.h>
    7.36 +#include <linux/errno.h>
    7.37 +#include <linux/uio.h>
    7.38 +#include <linux/notifier.h>
    7.39 +#include <linux/wait.h>
    7.40 +#include <linux/fs.h>
    7.41 +
    7.42 +#include "xenstored.h"
    7.43 +#include "xenbus_comms.h"
    7.44 +
    7.45 +#include <asm/uaccess.h>
    7.46 +#include <asm-xen/xenbus.h>
    7.47 +#include <asm-xen/linux-public/xenbus_dev.h>
    7.48 +#include <asm-xen/xen_proc.h>
    7.49 +
    7.50 +struct xenbus_dev_data {
    7.51 +	int in_transaction;
    7.52 +};
    7.53 +
    7.54 +static struct proc_dir_entry *xenbus_dev_intf;
    7.55 +
    7.56 +void *xs_talkv(enum xsd_sockmsg_type type, const struct kvec *iovec,
    7.57 +	       unsigned int num_vecs, unsigned int *len);
    7.58 +
    7.59 +static int xenbus_dev_talkv(struct xenbus_dev_data *u, unsigned long data)
    7.60 +{
    7.61 +	struct xenbus_dev_talkv xt;
    7.62 +	unsigned int len;
    7.63 +	void *resp, *base;
    7.64 +	struct kvec *iovec;
    7.65 +	int ret = -EFAULT, v = 0;
    7.66 +
    7.67 +	if (copy_from_user(&xt, (void *)data, sizeof(xt)))
    7.68 +		return -EFAULT;
    7.69 +
    7.70 +	iovec = kmalloc(xt.num_vecs * sizeof(struct kvec), GFP_KERNEL);
    7.71 +	if (iovec == NULL)
    7.72 +		return -ENOMEM;
    7.73 +
    7.74 +	if (copy_from_user(iovec, xt.iovec,
    7.75 +			   xt.num_vecs * sizeof(struct kvec)))
    7.76 +		goto out;
    7.77 +
    7.78 +	for (v = 0; v < xt.num_vecs; v++) {
    7.79 +		base = iovec[v].iov_base;
    7.80 +		iovec[v].iov_base = kmalloc(iovec[v].iov_len, GFP_KERNEL);
    7.81 +		if (iovec[v].iov_base == NULL ||
    7.82 +		    copy_from_user(iovec[v].iov_base, base, iovec[v].iov_len))
    7.83 +		{
    7.84 +			if (iovec[v].iov_base)
    7.85 +				kfree(iovec[v].iov_base);
    7.86 +			else
    7.87 +				ret = -ENOMEM;
    7.88 +			v--;
    7.89 +			goto out;
    7.90 +		}
    7.91 +	}
    7.92 +
    7.93 +	resp = xs_talkv(xt.type, iovec, xt.num_vecs, &len);
    7.94 +	if (IS_ERR(resp)) {
    7.95 +		ret = PTR_ERR(resp);
    7.96 +		goto out;
    7.97 +	}
    7.98 +
    7.99 +	switch (xt.type) {
   7.100 +	case XS_TRANSACTION_START:
   7.101 +		u->in_transaction = 1;
   7.102 +		break;
   7.103 +	case XS_TRANSACTION_END:
   7.104 +		u->in_transaction = 0;
   7.105 +		break;
   7.106 +	default:
   7.107 +		break;
   7.108 +	}
   7.109 +
   7.110 +	ret = len;
   7.111 +	if (len > xt.len)
   7.112 +		len = xt.len;
   7.113 +
   7.114 +	if (copy_to_user(xt.buf, resp, len))
   7.115 +		ret = -EFAULT;
   7.116 +
   7.117 +	kfree(resp);
   7.118 + out:
   7.119 +	while (v-- > 0)
   7.120 +		kfree(iovec[v].iov_base);
   7.121 +	kfree(iovec);
   7.122 +	return ret;
   7.123 +}
   7.124 +
   7.125 +static int xenbus_dev_ioctl(struct inode *inode, struct file *filp,
   7.126 +			    unsigned int cmd, unsigned long data)
   7.127 +{
   7.128 +	struct xenbus_dev_data *u = filp->private_data;
   7.129 +	int ret = -ENOSYS;
   7.130 +
   7.131 +	switch (cmd) {
   7.132 +	case IOCTL_XENBUS_DEV_TALKV:
   7.133 +		ret = xenbus_dev_talkv(u, data);
   7.134 +		break;
   7.135 +	default:
   7.136 +		ret = -EINVAL;
   7.137 +		break;
   7.138 +	}
   7.139 +	return ret;
   7.140 +}
   7.141 +
   7.142 +static int xenbus_dev_open(struct inode *inode, struct file *filp)
   7.143 +{
   7.144 +	struct xenbus_dev_data *u;
   7.145 +
   7.146 +	u = kmalloc(sizeof(*u), GFP_KERNEL);
   7.147 +	if (u == NULL)
   7.148 +		return -ENOMEM;
   7.149 +
   7.150 +	memset(u, 0, sizeof(*u));
   7.151 +
   7.152 +	filp->private_data = u;
   7.153 +
   7.154 +	down(&xenbus_lock);
   7.155 +
   7.156 +	return 0;
   7.157 +}
   7.158 +
   7.159 +static int xenbus_dev_release(struct inode *inode, struct file *filp)
   7.160 +{
   7.161 +	struct xenbus_dev_data *u = filp->private_data;
   7.162 +
   7.163 +	if (u->in_transaction)
   7.164 +		xenbus_transaction_end(1);
   7.165 +
   7.166 +	up(&xenbus_lock);
   7.167 +
   7.168 +	kfree(u);
   7.169 +
   7.170 +	return 0;
   7.171 +}
   7.172 +
   7.173 +static struct file_operations xenbus_dev_file_ops = {
   7.174 +	ioctl: xenbus_dev_ioctl,
   7.175 +	open: xenbus_dev_open,
   7.176 +	release: xenbus_dev_release
   7.177 +};
   7.178 +
   7.179 +static int __init
   7.180 +xenbus_dev_init(void)
   7.181 +{
   7.182 +	xenbus_dev_intf = create_xen_proc_entry("xenbus", 0400);
   7.183 +	if (xenbus_dev_intf)
   7.184 +		xenbus_dev_intf->proc_fops = &xenbus_dev_file_ops;
   7.185 +
   7.186 +	return 0;
   7.187 +}
   7.188 +
   7.189 +__initcall(xenbus_dev_init);
     8.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Sat Sep 03 18:15:39 2005 +0000
     8.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Sat Sep 03 18:24:46 2005 +0000
     8.3 @@ -106,10 +106,10 @@ void xenbus_debug_write(const char *str,
     8.4  }
     8.5  
     8.6  /* Send message to xs, get kmalloc'ed reply.  ERR_PTR() on error. */
     8.7 -static void *xs_talkv(enum xsd_sockmsg_type type,
     8.8 -		      const struct kvec *iovec,
     8.9 -		      unsigned int num_vecs,
    8.10 -		      unsigned int *len)
    8.11 +void *xs_talkv(enum xsd_sockmsg_type type,
    8.12 +	       const struct kvec *iovec,
    8.13 +	       unsigned int num_vecs,
    8.14 +	       unsigned int *len)
    8.15  {
    8.16  	struct xsd_sockmsg msg;
    8.17  	void *ret = NULL;
    8.18 @@ -557,7 +557,7 @@ static int watch_thread(void *unused)
    8.19  			BUG_ON(!w);
    8.20  			w->callback(w, node);
    8.21  			kfree(node);
    8.22 -		} else
    8.23 +		} else if (node)
    8.24  			printk(KERN_WARNING "XENBUS xs_read_watch: %li\n",
    8.25  			       PTR_ERR(node));
    8.26  		up(&xenbus_lock);
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/linux-public/xenbus_dev.h	Sat Sep 03 18:24:46 2005 +0000
     9.3 @@ -0,0 +1,47 @@
     9.4 +/*
     9.5 + * xenbus_dev.h
     9.6 + * 
     9.7 + * Copyright (c) 2005, Christian Limpach
     9.8 + * 
     9.9 + * This file may be distributed separately from the Linux kernel, or
    9.10 + * incorporated into other software packages, subject to the following license:
    9.11 + * 
    9.12 + * Permission is hereby granted, free of charge, to any person obtaining a copy
    9.13 + * of this source file (the "Software"), to deal in the Software without
    9.14 + * restriction, including without limitation the rights to use, copy, modify,
    9.15 + * merge, publish, distribute, sublicense, and/or sell copies of the Software,
    9.16 + * and to permit persons to whom the Software is furnished to do so, subject to
    9.17 + * the following conditions:
    9.18 + * 
    9.19 + * The above copyright notice and this permission notice shall be included in
    9.20 + * all copies or substantial portions of the Software.
    9.21 + * 
    9.22 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    9.23 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    9.24 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    9.25 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    9.26 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    9.27 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
    9.28 + * IN THE SOFTWARE.
    9.29 + */
    9.30 +
    9.31 +#ifndef _XENBUS_DEV_H_
    9.32 +#define _XENBUS_DEV_H_
    9.33 +
    9.34 +struct xenbus_dev_talkv {
    9.35 +	enum xsd_sockmsg_type type;
    9.36 +	const struct kvec *iovec;
    9.37 +	unsigned int num_vecs;
    9.38 +	char *buf;
    9.39 +	unsigned int len;
    9.40 +};
    9.41 +
    9.42 +/*
    9.43 + * @cmd: IOCTL_XENBUS_DEV_TALKV
    9.44 + * @arg: struct xenbus_dev_talkv
    9.45 + * Return: 0 on success, error code on failure.
    9.46 + */
    9.47 +#define	IOCTL_XENBUS_DEV_TALKV \
    9.48 +	_IOC(_IOC_NONE, 'X', 0, sizeof(struct xenbus_dev_talkv))
    9.49 +
    9.50 +#endif /* _XENBUS_DEV_H_ */
    25.1 --- a/tools/xenstore/Makefile	Sat Sep 03 18:15:39 2005 +0000
    25.2 +++ b/tools/xenstore/Makefile	Sat Sep 03 18:24:46 2005 +0000
    25.3 @@ -24,16 +24,28 @@ TESTDIR  = `pwd`/testsuite/tmp
    25.4  TESTFLAGS= -DTESTING
    25.5  TESTENV  = XENSTORED_ROOTDIR=$(TESTDIR) XENSTORED_RUNDIR=$(TESTDIR)
    25.6  
    25.7 -all: xen xenstored libxenstore.so
    25.8 +CLIENTS := xenstore-read xenstore-rm xenstore-write
    25.9 +CLIENTS_OBJS := $(patsubst xenstore-%,xenstore_%.o,$(CLIENTS))
   25.10 +
   25.11 +all: xen xenbus_dev.h libxenstore.so xenstored $(CLIENTS)
   25.12  
   25.13  testcode: xen xs_test xenstored_test xs_random xs_dom0_test
   25.14  
   25.15  xen:
   25.16  	ln -sf $(XEN_ROOT)/xen/include/public $@
   25.17  
   25.18 +xenbus_dev.h:
   25.19 +	ln -sf $(XEN_ROOT)/linux-2.6-xen-sparse/include/asm-xen/linux-public/xenbus_dev.h $@
   25.20 +
   25.21  xenstored: xenstored_core.o xenstored_watch.o xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o
   25.22  	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxenctrl -o $@
   25.23  
   25.24 +$(CLIENTS): xenstore-%: xenstore_%.o
   25.25 +	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxenctrl -L. -lxenstore -o $@
   25.26 +
   25.27 +$(CLIENTS_OBJS): xenstore_%.o: xenstore_client.c
   25.28 +	$(COMPILE.c) -DCLIENT_$(*F) -o $@ $<
   25.29 +
   25.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
   25.31  	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
   25.32  
   25.33 @@ -111,12 +123,13 @@ TAGS:
   25.34  tarball: clean
   25.35  	cd .. && tar -c -j -v -h -f xenstore.tar.bz2 xenstore/
   25.36  
   25.37 -install: xenstored libxenstore.so
   25.38 +install: libxenstore.so xenstored $(CLIENTS)
   25.39  	$(INSTALL_DIR) -p $(DESTDIR)/var/run/xenstored
   25.40  	$(INSTALL_DIR) -p $(DESTDIR)/var/lib/xenstored
   25.41  	$(INSTALL_DIR) -p $(DESTDIR)/usr/sbin
   25.42  	$(INSTALL_DIR) -p $(DESTDIR)/usr/include
   25.43  	$(INSTALL_PROG) xenstored $(DESTDIR)/usr/sbin
   25.44 +	$(INSTALL_PROG) $(CLIENTS) $(DESTDIR)/usr/bin
   25.45  	$(INSTALL_DIR) -p $(DESTDIR)/usr/$(LIBDIR)
   25.46  	$(INSTALL_DATA) libxenstore.so $(DESTDIR)/usr/$(LIBDIR)
   25.47  	$(INSTALL_DATA) xs.h $(DESTDIR)/usr/include
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/tools/xenstore/xenstore_client.c	Sat Sep 03 18:24:46 2005 +0000
    26.3 @@ -0,0 +1,130 @@
    26.4 +/*
    26.5 + * This file is subject to the terms and conditions of the GNU General
    26.6 + * Public License.  See the file "COPYING" in the main directory of
    26.7 + * this archive for more details.
    26.8 + *
    26.9 + * Copyright (C) 2005 by Christian Limpach
   26.10 + *
   26.11 + */
   26.12 +
   26.13 +#include <err.h>
   26.14 +#include <fcntl.h>
   26.15 +#include <getopt.h>
   26.16 +#include <stdio.h>
   26.17 +#include <stdlib.h>
   26.18 +#include <string.h>
   26.19 +#include <xs.h>
   26.20 +
   26.21 +static void
   26.22 +usage(const char *progname)
   26.23 +{
   26.24 +#if defined(CLIENT_read)
   26.25 +    errx(1, "Usage: %s [-h] [-p] key [...]", progname);
   26.26 +#elif defined(CLIENT_write)
   26.27 +    errx(1, "Usage: %s [-h] key value [...]", progname);
   26.28 +#elif defined(CLIENT_rm)
   26.29 +    errx(1, "Usage: %s [-h] key [...]", progname);
   26.30 +#endif
   26.31 +}
   26.32 +
   26.33 +int
   26.34 +main(int argc, char **argv)
   26.35 +{
   26.36 +    struct xs_handle *xsh;
   26.37 +    bool success;
   26.38 +    int ret = 0;
   26.39 +#if defined(CLIENT_read)
   26.40 +    char *val;
   26.41 +    int prefix = 0;
   26.42 +#endif
   26.43 +
   26.44 +    xsh = xs_domain_open();
   26.45 +    if (xsh == NULL)
   26.46 +	err(1, "xs_domain_open");
   26.47 +
   26.48 +    while (1) {
   26.49 +	int c, index = 0;
   26.50 +	static struct option long_options[] = {
   26.51 +	    {"help", 0, 0, 'h'},
   26.52 +#if defined(CLIENT_read)
   26.53 +	    {"prefix", 0, 0, 'p'},
   26.54 +#endif
   26.55 +	    {0, 0, 0, 0}
   26.56 +	};
   26.57 +
   26.58 +	c = getopt_long(argc, argv, "h"
   26.59 +#if defined(CLIENT_read)
   26.60 +			"p"
   26.61 +#endif
   26.62 +			, long_options, &index);
   26.63 +	if (c == -1)
   26.64 +	    break;
   26.65 +
   26.66 +	switch (c) {
   26.67 +	case 'h':
   26.68 +	    usage(argv[0]);
   26.69 +	    /* NOTREACHED */
   26.70 +#if defined(CLIENT_read)
   26.71 +	case 'p':
   26.72 +	    prefix = 1;
   26.73 +	    break;
   26.74 +#endif
   26.75 +	}
   26.76 +    }
   26.77 +
   26.78 +    if (optind == argc) {
   26.79 +	usage(argv[0]);
   26.80 +	/* NOTREACHED */
   26.81 +    }
   26.82 +#if defined(CLIENT_write)
   26.83 +    if ((argc - optind) % 1) {
   26.84 +	usage(argv[0]);
   26.85 +	/* NOTREACHED */
   26.86 +    }
   26.87 +#endif
   26.88 +
   26.89 +    /* XXX maybe find longest common prefix */
   26.90 +    success = xs_transaction_start(xsh, "/");
   26.91 +    if (!success)
   26.92 +	errx(1, "couldn't start transaction");
   26.93 +
   26.94 +    while (optind < argc) {
   26.95 +#if defined(CLIENT_read)
   26.96 +	val = xs_read(xsh, argv[optind], NULL);
   26.97 +	if (val == NULL) {
   26.98 +	    warnx("couldn't read path %s", argv[optind]);
   26.99 +	    ret = 1;
  26.100 +	    goto out;
  26.101 +	}
  26.102 +	if (prefix)
  26.103 +	    printf("%s: ", argv[optind]);
  26.104 +	printf("%s\n", val);
  26.105 +	free(val);
  26.106 +	optind++;
  26.107 +#elif defined(CLIENT_write)
  26.108 +	success = xs_write(xsh, argv[optind], argv[optind + 1],
  26.109 +			   strlen(argv[optind + 1]), O_CREAT);
  26.110 +	if (!success) {
  26.111 +	    warnx("could not write path %s", argv[optind]);
  26.112 +	    ret = 1;
  26.113 +	    goto out;
  26.114 +	}
  26.115 +	optind += 2;
  26.116 +#elif defined(CLIENT_rm)
  26.117 +	success = xs_rm(xsh, argv[optind]);
  26.118 +	if (!success) {
  26.119 +	    warnx("could not remove path %s", argv[optind]);
  26.120 +	    ret = 1;
  26.121 +	    goto out;
  26.122 +	}
  26.123 +	optind++;
  26.124 +#endif
  26.125 +    }
  26.126 +
  26.127 + out:
  26.128 +    success = xs_transaction_end(xsh, ret ? true : false);
  26.129 +    if (!success)
  26.130 +	errx(1, "couldn't end transaction");
  26.131 +
  26.132 +    return ret;
  26.133 +}
    27.1 --- a/tools/xenstore/xs.c	Sat Sep 03 18:15:39 2005 +0000
    27.2 +++ b/tools/xenstore/xs.c	Sat Sep 03 18:24:46 2005 +0000
    27.3 @@ -31,14 +31,17 @@
    27.4  #include <signal.h>
    27.5  #include <stdint.h>
    27.6  #include <errno.h>
    27.7 +#include <sys/ioctl.h>
    27.8  #include "xs.h"
    27.9  #include "xenstored.h"
   27.10  #include "xs_lib.h"
   27.11  #include "utils.h"
   27.12 +#include "xenbus_dev.h"
   27.13  
   27.14  struct xs_handle
   27.15  {
   27.16  	int fd;
   27.17 +	enum { SOCK, DEV } type;
   27.18  };
   27.19  
   27.20  /* Get the socket from the store daemon handle.
   27.21 @@ -65,13 +68,35 @@ static struct xs_handle *get_socket(cons
   27.22  		h = malloc(sizeof(*h));
   27.23  		if (h) {
   27.24  			h->fd = sock;
   27.25 +			h->type = SOCK;
   27.26  			return h;
   27.27  		}
   27.28  	}
   27.29  
   27.30  	saved_errno = errno;
   27.31  	close(sock);
   27.32 -	free(h);
   27.33 +	errno = saved_errno;
   27.34 +	return NULL;
   27.35 +}
   27.36 +
   27.37 +static struct xs_handle *get_dev(const char *connect_to)
   27.38 +{
   27.39 +	int fd, saved_errno;
   27.40 +	struct xs_handle *h = NULL;
   27.41 +
   27.42 +	fd = open(connect_to, O_RDONLY);
   27.43 +	if (fd < 0)
   27.44 +		return NULL;
   27.45 +
   27.46 +	h = malloc(sizeof(*h));
   27.47 +	if (h) {
   27.48 +		h->fd = fd;
   27.49 +		h->type = DEV;
   27.50 +		return h;
   27.51 +	}
   27.52 +
   27.53 +	saved_errno = errno;
   27.54 +	close(fd);
   27.55  	errno = saved_errno;
   27.56  	return NULL;
   27.57  }
   27.58 @@ -86,6 +111,11 @@ struct xs_handle *xs_daemon_open_readonl
   27.59  	return get_socket(xs_daemon_socket_ro());
   27.60  }
   27.61  
   27.62 +struct xs_handle *xs_domain_open(void)
   27.63 +{
   27.64 +	return get_dev(xs_domain_dev());
   27.65 +}
   27.66 +
   27.67  void xs_daemon_close(struct xs_handle *h)
   27.68  {
   27.69  	if (h->fd >= 0)
   27.70 @@ -160,9 +190,9 @@ static void *read_reply(int fd, enum xsd
   27.71  }
   27.72  
   27.73  /* Send message to xs, get malloc'ed reply.  NULL and set errno on error. */
   27.74 -static void *xs_talkv(struct xs_handle *h, enum xsd_sockmsg_type type,
   27.75 -		      const struct iovec *iovec, unsigned int num_vecs,
   27.76 -		      unsigned int *len)
   27.77 +static void *xs_talkv_sock(struct xs_handle *h, enum xsd_sockmsg_type type,
   27.78 +			   const struct iovec *iovec, unsigned int num_vecs,
   27.79 +			   unsigned int *len)
   27.80  {
   27.81  	struct xsd_sockmsg msg;
   27.82  	void *ret = NULL;
   27.83 @@ -223,6 +253,54 @@ close_fd:
   27.84  	return NULL;
   27.85  }
   27.86  
   27.87 +/* Send message to xs, get malloc'ed reply.  NULL and set errno on error. */
   27.88 +static void *xs_talkv_dev(struct xs_handle *h, enum xsd_sockmsg_type type,
   27.89 +			  const struct iovec *iovec, unsigned int num_vecs,
   27.90 +			  unsigned int *len)
   27.91 +{
   27.92 +	struct xenbus_dev_talkv dt;
   27.93 +	char *buf;
   27.94 +	int err, buflen = 1024;
   27.95 +
   27.96 + again:
   27.97 +	buf = malloc(buflen);
   27.98 +	if (buf == NULL) {
   27.99 +		errno = ENOMEM;
  27.100 +		return NULL;
  27.101 +	}
  27.102 +	dt.type = type;
  27.103 +	dt.iovec = (struct kvec *)iovec;
  27.104 +	dt.num_vecs = num_vecs;
  27.105 +	dt.buf = buf;
  27.106 +	dt.len = buflen;
  27.107 +	err = ioctl(h->fd, IOCTL_XENBUS_DEV_TALKV, &dt);
  27.108 +	if (err < 0) {
  27.109 +		free(buf);
  27.110 +		errno = err;
  27.111 +		return NULL;
  27.112 +	}
  27.113 +	if (err > buflen) {
  27.114 +		free(buf);
  27.115 +		buflen = err;
  27.116 +		goto again;
  27.117 +	}
  27.118 +	if (len)
  27.119 +		*len = err;
  27.120 +	return buf;
  27.121 +}
  27.122 +
  27.123 +/* Send message to xs, get malloc'ed reply.  NULL and set errno on error. */
  27.124 +static void *xs_talkv(struct xs_handle *h, enum xsd_sockmsg_type type,
  27.125 +		      const struct iovec *iovec, unsigned int num_vecs,
  27.126 +		      unsigned int *len)
  27.127 +{
  27.128 +	if (h->type == SOCK)
  27.129 +		return xs_talkv_sock(h, type, iovec, num_vecs, len);
  27.130 +	if (h->type == DEV)
  27.131 +		return xs_talkv_dev(h, type, iovec, num_vecs, len);
  27.132 +	return NULL;
  27.133 +}
  27.134 +
  27.135  /* free(), but don't change errno. */
  27.136  static void free_no_errno(void *p)
  27.137  {
    28.1 --- a/tools/xenstore/xs.h	Sat Sep 03 18:15:39 2005 +0000
    28.2 +++ b/tools/xenstore/xs.h	Sat Sep 03 18:24:46 2005 +0000
    28.3 @@ -30,6 +30,7 @@ struct xs_handle;
    28.4   * Returns a handle or NULL.
    28.5   */
    28.6  struct xs_handle *xs_daemon_open(void);
    28.7 +struct xs_handle *xs_domain_open(void);
    28.8  
    28.9  /* Connect to the xs daemon (readonly for non-root clients).
   28.10   * Returns a handle or NULL.
    29.1 --- a/tools/xenstore/xs_lib.c	Sat Sep 03 18:15:39 2005 +0000
    29.2 +++ b/tools/xenstore/xs_lib.c	Sat Sep 03 18:24:46 2005 +0000
    29.3 @@ -66,6 +66,12 @@ const char *xs_daemon_transactions(void)
    29.4  	return buf;
    29.5  }
    29.6  
    29.7 +const char *xs_domain_dev(void)
    29.8 +{
    29.9 +	char *s = getenv("XENSTORED_DOMAIN_DEV");
   29.10 +	return (s ? s : "/proc/xen/xenbus");
   29.11 +}
   29.12 +
   29.13  /* Simple routines for writing to sockets, etc. */
   29.14  bool xs_write_all(int fd, const void *data, unsigned int len)
   29.15  {
    30.1 --- a/tools/xenstore/xs_lib.h	Sat Sep 03 18:15:39 2005 +0000
    30.2 +++ b/tools/xenstore/xs_lib.h	Sat Sep 03 18:24:46 2005 +0000
    30.3 @@ -48,6 +48,7 @@ const char *xs_daemon_socket(void);
    30.4  const char *xs_daemon_socket_ro(void);
    30.5  const char *xs_daemon_store(void);
    30.6  const char *xs_daemon_transactions(void);
    30.7 +const char *xs_domain_dev(void);
    30.8  
    30.9  /* Simple write function: loops for you. */
   30.10  bool xs_write_all(int fd, const void *data, unsigned int len);