Index: ioemu/xenstore.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ ioemu/xenstore.c	2007-05-03 15:17:52.000000000 +0100
@@ -0,0 +1,139 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License.  See the file "COPYING" in the main directory of
+ * this archive for more details.
+ *
+ * Copyright (C) 2006 Christian Limpach
+ * Copyright (C) 2006 XenSource Ltd.
+ *
+ */
+
+#include "vl.h"
+
+static struct xs_handle *xsh = NULL;
+
+static int pasprintf(char **buf, const char *fmt, ...)
+{
+    va_list ap;
+    int ret = 0;
+
+    if (*buf)
+        free(*buf);
+    va_start(ap, fmt);
+    if (vasprintf(buf, fmt, ap) == -1) {
+        buf = NULL;
+        ret = -1;
+    }
+    va_end(ap);
+    return ret;
+}
+
+void xenstore_parse_domain_config(int domid)
+{
+    char *path;
+
+    xsh = xs_daemon_open();
+    if (xsh == NULL) {
+        fprintf(logfile, "Could not contact xenstore for domain config\n");
+        return;
+    }
+
+    path = xs_get_domain_path(xsh, domid);
+    if (path == NULL) {
+        fprintf(logfile, "xs_get_domain_path() error\n");
+        goto out;
+    }
+
+ out:
+    free(path);
+    return;
+}
+
+int xenstore_fd(void)
+{
+    if (xsh)
+        return xs_fileno(xsh);
+    return -1;
+}
+
+void xenstore_process_event(void *opaque)
+{
+    char **vec;
+    unsigned int num;
+
+    vec = xs_read_watch(xsh, &num);
+    if (!vec)
+        return;
+
+ out:
+    free(vec);
+}
+
+char *xenstore_vm_read(int domid, char *key, int *len)
+{
+    char *buf = NULL, *path = NULL, *value = NULL;
+
+    if (xsh == NULL)
+        goto out;
+
+    path = xs_get_domain_path(xsh, domid);
+    if (path == NULL) {
+        fprintf(logfile, "xs_get_domain_path(%d): error\n", domid);
+        goto out;
+    }
+
+    pasprintf(&buf, "%s/vm", path);
+    free(path);
+    path = xs_read(xsh, XBT_NULL, buf, NULL);
+    if (path == NULL) {
+        fprintf(logfile, "xs_read(%s): read error\n", buf);
+        goto out;
+    }
+
+    pasprintf(&buf, "%s/%s", path, key);
+    value = xs_read(xsh, XBT_NULL, buf, len);
+    if (value == NULL) {
+        fprintf(logfile, "xs_read(%s): read error\n", buf);
+        goto out;
+    }
+
+ out:
+    free(path);
+    free(buf);
+    return value;
+}
+
+int xenstore_vm_write(int domid, char *key, char *value)
+{
+    char *buf = NULL, *path = NULL;
+    int rc = -1;
+
+    if (xsh == NULL)
+        goto out;
+
+    path = xs_get_domain_path(xsh, domid);
+    if (path == NULL) {
+        fprintf(logfile, "xs_get_domain_path: error\n");
+        goto out;
+    }
+
+    pasprintf(&buf, "%s/vm", path);
+    free(path);
+    path = xs_read(xsh, XBT_NULL, buf, NULL);
+    if (path == NULL) {
+        fprintf(logfile, "xs_read(%s): read error\n", buf);
+        goto out;
+    }
+
+    pasprintf(&buf, "%s/%s", path, key);
+    rc = xs_write(xsh, XBT_NULL, buf, value, strlen(value));
+    if (rc) {
+        fprintf(logfile, "xs_write(%s, %s): write error\n", buf, key);
+        goto out;
+    }
+
+ out:
+    free(path);
+    free(buf);
+    return rc;
+}
Index: ioemu/vl.h
===================================================================
--- ioemu.orig/vl.h	2007-05-03 15:15:40.000000000 +0100
+++ ioemu/vl.h	2007-05-03 15:18:00.000000000 +0100
@@ -1204,6 +1204,12 @@
 void readline_start(const char *prompt, int is_password,
                     ReadLineFunc *readline_func, void *opaque);
 
+/* xenstore.c */
+void xenstore_parse_domain_config(int domid);
+
+int xenstore_vm_write(int domid, char *key, char *val);
+char *xenstore_vm_read(int domid, char *key, int *len);
+
 void kqemu_record_dump(void);
 
 extern char domain_name[];
Index: ioemu/Makefile.target
===================================================================
--- ioemu.orig/Makefile.target	2007-05-03 15:15:39.000000000 +0100
+++ ioemu/Makefile.target	2007-05-03 15:16:41.000000000 +0100
@@ -359,6 +359,7 @@
 VL_OBJS+= cirrus_vga.o mixeng.o parallel.o acpi.o piix_pci.o
 VL_OBJS+= usb-uhci.o
 VL_OBJS+= piix4acpi.o
+VL_OBJS+= xenstore.o
 DEFINES += -DHAS_AUDIO
 endif
 ifeq ($(TARGET_BASE_ARCH), ppc)
Index: ioemu/vl.c
===================================================================
--- ioemu.orig/vl.c	2007-05-03 15:15:40.000000000 +0100
+++ ioemu/vl.c	2007-05-03 15:17:52.000000000 +0100
@@ -6371,6 +6371,10 @@
         }
     }
 
+#ifdef CONFIG_DM
+    xenstore_parse_domain_config(domid);
+#endif /* CONFIG_DM */
+
 #ifdef USE_KQEMU
     if (smp_cpus > 1)
         kqemu_allowed = 0;
@@ -6624,6 +6628,8 @@
         }
     }
 
+    qemu_set_fd_handler(xenstore_fd(), xenstore_process_event, NULL, NULL);
+
     machine->init(ram_size, vga_ram_size, boot_device,
                   ds, fd_filename, snapshot,
                   kernel_filename, kernel_cmdline, initrd_filename);
