Skip to contentSkip to conversation

merge some xen bits into qemu

PATCH New Gerd Hoffmann 1 participant 8 messages Aug 4, 2008 Kbuild

lore
Share & tools
lore
#0 lore raw

cover merge some xen bits into qemu

Hi folks,

This is the second version of the xen support for qemu patch series, addressing review comments. Lots of little changes, the largest change probably is the switch-over to the esisting sys-queue.h list implementation instead of bringing in a copy of the linux kernel list.h header.

The console and framebuffer backend drivers are largely based on the xen code, the other bits are rewritten from scratch. Nevertheless the code should be functionally identical.

Overview (individual patches have longer descriptions):

#1 -- groundwork: build system, cmd line options, ... #2 -- xen backend driver infrastructrure
#3 -- xen console backend driver
#4 -- xen framebuffer backend driver
#5 -- xen block backend driver
#6 -- xen nic backend driver
#7 -- allow xen disks and nics being configured via qemu command
line options.

With the first four patches in place upstream qemu can replace xen's qemu-dm for paravirtual domains. The block and nic backend drivers are full userspace implementations using the grant table device (gntdev).

xen support is implemented using another machine type. xen's qemu-dm already uses the machine type to switch between paravirtualized and fully virtualized machines, so this was the natural choice. qemu has gets a new "xenpv" machine type additionally to the "pc" and "isapc" ones.

Comments?

cheers,
Gerd

#1 lore raw

PATCH 1/7 xen: groundwork for xen support

- configure script and build system changes.
- wind up new machine type.
- add -domid command line option.
- allow xenpv machines run without disk and kernel specified by adding a nodisk_ok field to QEMUMachine.
- detect xen being present.

---
 Makefile.target       |    8 +++
 configure             |   27 +++++++++
 hw/boards.h           |    4 +
 hw/xen-machine.c      |  146 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/xen.h              |   18 ++++++
 target-i386/machine.c |    3 +
 vl.c                  |   19 ++++++-
 7 files changed, 223 insertions(+), 2 deletions(-)
 create mode 100644 hw/xen-machine.c
 create mode 100644 hw/xen.h
Makefile.target +8 -0
index 42162c3..7edef6c 100644
@@ -515,6 +515,14 @@ CPPFLAGS += $(CONFIG_VNC_TLS_CFLAGS)
 LIBS += $(CONFIG_VNC_TLS_LIBS)
 endif
 
+# xen backend driver support
+XEN_OBJS := xen-machine.o
+ifeq ($(CONFIG_XEN), yes)
+  OBJS += $(XEN_OBJS)
+  LIBS += $(XEN_LIBS)
+  $(XEN_OBJS) : CFLAGS += -Wall -Wmissing-prototypes -Wstrict-prototypes
+endif
+
 # SCSI layer
 OBJS+= lsi53c895a.o esp.o
 
configure +27 -0
index 0a3b7c9..5111b73 100755
@@ -108,6 +108,7 @@ uname_release=""
 curses="yes"
 nptl="yes"
 mixemu="no"
+xen="no"
 
 # OS specific
 targetos=`uname -s`
@@ -202,6 +203,7 @@ linux="yes"
 linux_user="yes"
 if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then
     kqemu="yes"
+    xen="yes"
     audio_possible_drivers="$audio_possible_drivers fmod"
 fi
 ;;
@@ -285,6 +287,8 @@ for opt do
   ;;
   --disable-kqemu) kqemu="no"
   ;;
+  --disable-xen) xen="no"
+  ;;
   --disable-brlapi) brlapi="no"
   ;;
   --enable-profiler) profiler="yes"
@@ -421,6 +425,7 @@ echo "                           Available drivers: $audio_possible_drivers"
 echo "  --audio-card-list=LIST   set list of additional emulated audio cards"
 echo "                           Available cards: ac97 adlib cs4231a gus"
 echo "  --enable-mixemu          enable mixer emulation"
+echo "  --disable-xen            disable xen backend driver support"
 echo "  --disable-brlapi         disable BrlAPI"
 echo "  --disable-vnc-tls        disable TLS encryption for VNC server"
 echo "  --disable-curses         disable curses output"
@@ -681,6 +686,22 @@ else
 fi
 
 ##########################################
+# xen probe
+
+if test "$xen" = "yes" ; then
+cat > $TMPC <<EOF
+#include <xs.h>
+#include <xenctrl.h>
+int main(void) { xs_daemon_open; xc_interface_open; }
+EOF
+   if $cc $ARCH_CFLAGS -c -o $TMPO $TMPC -lxenstore -lxenctrl 2> /dev/null ; then
+      :
+   else
+      xen="no"
+   fi
+fi
+
+##########################################
 # SDL probe
 
 sdl_too_old=no
@@ -917,6 +938,7 @@ if test -n "$sparc_cpu"; then
     echo "Target Sparc Arch $sparc_cpu"
 fi
 echo "kqemu support     $kqemu"
+echo "xen support       $xen"
 echo "brlapi support    $brlapi"
 echo "Documentation     $build_docs"
 [ ! -z "$uname_release" ] && \
@@ -1168,6 +1190,11 @@ if test "$brlapi" = "yes" ; then
   echo "#define CONFIG_BRLAPI 1" >> $config_h
   echo "BRLAPI_LIBS=-lbrlapi" >> $config_mak
 fi
+if test "$xen" = "yes" ; then
+  echo "CONFIG_XEN=yes" >> $config_mak
+  echo "#define CONFIG_XEN 1" >> $config_h
+  echo "XEN_LIBS=-lxenstore -lxenctrl" >> $config_mak
+fi
 
 # XXX: suppress that
 if [ "$bsd" = "yes" ] ; then
hw/boards.h +4 -0
index 22ac332..9af9939 100644
@@ -16,6 +16,7 @@ typedef struct QEMUMachine {
     QEMUMachineInitFunc *init;
 #define RAMSIZE_FIXED	(1 << 0)
     ram_addr_t ram_require;
+    int nodisk_ok;
     struct QEMUMachine *next;
 } QEMUMachine;
 
@@ -29,6 +30,9 @@ extern QEMUMachine bareetraxfs_machine;
 extern QEMUMachine pc_machine;
 extern QEMUMachine isapc_machine;
 
+/* xen_machine.c */
+extern QEMUMachine xenpv_machine;
+
 /* ppc.c */
 extern QEMUMachine prep_machine;
 extern QEMUMachine core99_machine;
hw/xen-machine.c new file +146 -0

146 lines not on this page · raw message

hw/xen.h new file +18 -0
new file mode 100644
index 0000000..a772aad
@@ -0,0 +1,18 @@
+#ifndef QEMU_XEN_H
+#define QEMU_XEN_H 1
+/*
+ * public xen header
+ *   stuff needed outside xen-*.c, i.e. interfaces to qemu.
+ *   must not depend on any xen headers being present in
+ *   /usr/include/xen, so it can be included unconditionally.
+ */
+
+/* xen-machine.c */
+extern int xen_domid;
+extern int xen_present;
+extern int xen_emulate;
+extern int xen_domainbuild;
+
+int xen_detect(void);
+
+#endif /* QEMU_XEN_H */
target-i386/machine.c +3 -0
index 91dbd55..98ece17 100644
@@ -9,6 +9,9 @@ void register_machines(void)
 {
     qemu_register_machine(&pc_machine);
     qemu_register_machine(&isapc_machine);
+#ifdef CONFIG_XEN
+    qemu_register_machine(&xenpv_machine);
+#endif
 }
 
 static void cpu_put_seg(QEMUFile *f, SegmentCache *dt)
vl.c +17 -2
index e929370..c3f2185 100644
@@ -29,6 +29,7 @@
 #include "hw/audiodev.h"
 #include "hw/isa.h"
 #include "hw/baum.h"
+#include "hw/xen.h"
 #include "net.h"
 #include "console.h"
 #include "sysemu.h"
@@ -7744,6 +7745,9 @@ static void help(int exitcode)
            "-startdate      select initial date of the clock\n"
            "-icount [N|auto]\n"
            "                Enable virtual instruction counter with 2^N clock ticks per instruction\n"
+#ifdef CONFIG_XEN
+           "-domid          specify xen guest domain id\n"
+#endif
            "\n"
            "During emulation, the following keys are useful:\n"
            "ctrl-alt-f      toggle full screen\n"
@@ -7849,6 +7853,9 @@ enum {
     QEMU_OPTION_startdate,
     QEMU_OPTION_tb_size,
     QEMU_OPTION_icount,
+#ifdef CONFIG_XEN
+    QEMU_OPTION_domid,
+#endif
 };
 
 typedef struct QEMUOption {
@@ -7937,6 +7944,9 @@ const QEMUOption qemu_options[] = {
 #ifdef CONFIG_CURSES
     { "curses", 0, QEMU_OPTION_curses },
 #endif
+#ifdef CONFIG_XEN
+    { "domid", HAS_ARG, QEMU_OPTION_domid },
+#endif
 
     /* temporary options */
     { "usb", 0, QEMU_OPTION_usb },
@@ -8784,6 +8794,11 @@ int main(int argc, char **argv)
                     icount_time_shift = strtol(optarg, NULL, 0);
                 }
                 break;
+#ifdef CONFIG_XEN
+            case QEMU_OPTION_domid:
+                xen_domid = atoi(optarg);
+                break;
+#endif
             }
         }
     }
@@ -8858,9 +8873,9 @@ int main(int argc, char **argv)
     linux_boot = (kernel_filename != NULL);
     net_boot = (boot_devices_bitmap >> ('n' - 'a')) & 0xF;
 
-    /* XXX: this should not be: some embedded targets just have flash */
+    /* need a disk for this machine to boot ? */
     if (!linux_boot && net_boot == 0 &&
-        nb_drives_opt == 0)
+        !machine->nodisk_ok && nb_drives_opt == 0)
         help(1);
 
     if (!linux_boot && *kernel_cmdline != '\0') {
Signature · 1 line
1.5.5.1
#2 lore raw

PATCH 2/7 xen: backend driver core

In reply to Gerd Hoffmann

This patch adds infrastructure for xen backend drivers living in qemu, so drivers don't need to implement common stuff on their own. It's mostly xenbus management stuff: some functions to access xentore, setting up xenstore watches, callbacks on device discovery and state changes, handle event channel, ...

---
 Makefile.target  |    2 +-
 hw/xen-backend.c |  665 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/xen-backend.h |   87 +++++++
 hw/xen-common.h  |   38 +++
 hw/xen-machine.c |    7 +-
 5 files changed, 797 insertions(+), 2 deletions(-)
 create mode 100644 hw/xen-backend.c
 create mode 100644 hw/xen-backend.h
 create mode 100644 hw/xen-common.h
Makefile.target +1 -1
index 7edef6c..65f4910 100644
@@ -516,7 +516,7 @@ LIBS += $(CONFIG_VNC_TLS_LIBS)
 endif
 
 # xen backend driver support
-XEN_OBJS := xen-machine.o
+XEN_OBJS := xen-machine.o xen-backend.o
 ifeq ($(CONFIG_XEN), yes)
   OBJS += $(XEN_OBJS)
   LIBS += $(XEN_LIBS)
hw/xen-backend.c new file +665 -0

665 lines not on this page · raw message

hw/xen-backend.h new file +87 -0

87 lines not on this page · raw message

hw/xen-common.h new file +38 -0
new file mode 100644
index 0000000..866049a
@@ -0,0 +1,38 @@
+#ifndef QEMU_XEN_COMMON_H
+#define QEMU_XEN_COMMON_H 1
+
+#include <stddef.h>
+#include <inttypes.h>
+
+#include <xenctrl.h>
+#include <xs.h>
+#include <xen/io/xenbus.h>
+
+#include "hw.h"
+#include "xen.h"
+#include "sys-queue.h"   /* BSD list implementation */
+
+/*
+ * tweaks needed to build with different xen versions
+ *  0x00030205 -> 3.1.0
+ *  0x00030207 -> 3.2.0
+ *  0x00030208 -> unstable
+ */
+#include <xen/xen-compat.h>
+#if __XEN_LATEST_INTERFACE_VERSION__ < 0x00030207
+# define xc_map_foreign_pages xc_map_foreign_batch
+#endif
+#if __XEN_LATEST_INTERFACE_VERSION__ < 0x00030208
+# define xen_mb()  mb()
+# define xen_rmb() rmb()
+# define xen_wmb() wmb()
+#endif
+
+/* ------------------------------------------------------------- */
+/* useful defines                                                */
+
+#define container_of(ptr, type, member) ({                      \
+        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
+        (type *)( (char *)__mptr - offsetof(type,member) );})
+
+#endif /* QEMU_XEN_COMMON_H */
hw/xen-machine.c +6 -1
index 7757bde..f0ebd60 100644
@@ -25,7 +25,7 @@
 #include "hw.h"
 #include "boards.h"
 
-#include <xenctrl.h>
+#include "xen-backend.h"
 
 /* -------------------------------------------------------------------- */
 /* variables                                                            */
@@ -81,6 +81,11 @@ static int xen_init(void)
         xen_emulate = 1;
     }
 
+    if (-1 == xen_be_init()) {
+        fprintf(stderr, "%s: xen backend core setup failed\n", __FUNCTION__);
+        return -1;
+    }
+
     return 0;
 }
 
Signature · 1 line
1.5.5.1
#3 lore raw

PATCH 3/7 xen: add console backend driver.

In reply to Gerd Hoffmann

This patch adds a xenconsole backend driver. It it based on current xen-unstable code. It has been changed to make use of the common backend driver code.

---
 Makefile.target  |    1 +
 hw/xen-backend.h |    3 +
 hw/xen-console.c |  270 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/xen-machine.c |    3 +
 4 files changed, 277 insertions(+), 0 deletions(-)
 create mode 100644 hw/xen-console.c
Makefile.target +1 -0
index 65f4910..f61458c 100644
@@ -517,6 +517,7 @@ endif
 
 # xen backend driver support
 XEN_OBJS := xen-machine.o xen-backend.o
+XEN_OBJS += xen-console.o
 ifeq ($(CONFIG_XEN), yes)
   OBJS += $(XEN_OBJS)
   LIBS += $(XEN_LIBS)
hw/xen-backend.h +3 -0
index 13b3190..61c37ac 100644
@@ -84,4 +84,7 @@ int xen_be_send_notify(struct XenDevice *xendev);
 void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ...)
     __attribute__ ((format(printf, 3, 4)));
 
+/* actual backend drivers */
+struct XenDevOps xen_console_ops;      /* xen_console.c     */
+
 #endif /* QEMU_XEN_BACKEND_H */
hw/xen-console.c new file +270 -0

270 lines not on this page · raw message

hw/xen-machine.c +3 -0
index f0ebd60..de22cdb 100644
@@ -97,6 +97,9 @@ static int xen_init_pv(DisplayState *ds)
     if (rc < 0)
         return rc;
 
+    /* xenbus backend drivers */
+    xen_be_register("console", &xen_console_ops);
+
     return 0;
 }
 
Signature · 1 line
1.5.5.1
#4 lore raw

PATCH 4/7 xen: add framebuffer backend driver

In reply to Gerd Hoffmann

This patch adds a frsamebuffer (and kbd+mouse) backend driver. It it based on current xen-unstable code. It has been changed to make use of the common backend driver code. It also has been changed to compile with xen headers older than unstable (aka son-to-be 3.3).

---
 Makefile.target      |    2 +-
 hw/xen-backend.h     |    4 +
 hw/xen-framebuffer.c |  933 ++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/xen-machine.c     |    5 +
 4 files changed, 943 insertions(+), 1 deletions(-)
 create mode 100644 hw/xen-framebuffer.c
Makefile.target +1 -1
index f61458c..39db580 100644
@@ -517,7 +517,7 @@ endif
 
 # xen backend driver support
 XEN_OBJS := xen-machine.o xen-backend.o
-XEN_OBJS += xen-console.o
+XEN_OBJS += xen-console.o xen-framebuffer.o
 ifeq ($(CONFIG_XEN), yes)
   OBJS += $(XEN_OBJS)
   LIBS += $(XEN_LIBS)
hw/xen-backend.h +4 -0
index 61c37ac..f7dd0c8 100644
@@ -86,5 +86,9 @@ void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ...
 
 /* actual backend drivers */
 struct XenDevOps xen_console_ops;      /* xen_console.c     */
+struct XenDevOps xen_kbdmouse_ops;     /* xen_framebuffer.c */
+struct XenDevOps xen_framebuffer_ops;  /* xen_framebuffer.c */
+
+void xen_set_display(int domid, DisplayState *ds);
 
 #endif /* QEMU_XEN_BACKEND_H */
hw/xen-framebuffer.c new file +933 -0

933 lines not on this page · raw message

hw/xen-machine.c +5 -0
index de22cdb..8d7140a 100644
@@ -99,6 +99,11 @@ static int xen_init_pv(DisplayState *ds)
 
     /* xenbus backend drivers */
     xen_be_register("console", &xen_console_ops);
+    xen_be_register("vkbd", &xen_kbdmouse_ops);
+    xen_be_register("vfb", &xen_framebuffer_ops);
+
+    /* setup framebuffer */
+    xen_set_display(xen_domid, ds);
 
     return 0;
 }
Signature · 1 line
1.5.5.1
#5 lore raw

PATCH 5/7 xen: add block device backend driver.

In reply to Gerd Hoffmann

This patch adds a block device backend driver to qemu. It is a pure userspace implemention using the gntdev interface. It uses "qdisk" as backend name in xenstore so it doesn't interfere with the other existing backends (blkback aka "vbd" and tapdisk aka "tap").

---
 Makefile.target  |    2 +-
 hw/xen-backend.h |    2 +
 hw/xen-blkif.h   |  103 ++++++++
 hw/xen-disk.c    |  677 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/xen-machine.c |    1 +
 sysemu.h         |    2 +-
 vl.c             |    4 +
 7 files changed, 789 insertions(+), 2 deletions(-)
 create mode 100644 hw/xen-blkif.h
 create mode 100644 hw/xen-disk.c
Makefile.target +1 -1
index 39db580..e668bd2 100644
@@ -517,7 +517,7 @@ endif
 
 # xen backend driver support
 XEN_OBJS := xen-machine.o xen-backend.o
-XEN_OBJS += xen-console.o xen-framebuffer.o
+XEN_OBJS += xen-console.o xen-framebuffer.o xen-disk.o
 ifeq ($(CONFIG_XEN), yes)
   OBJS += $(XEN_OBJS)
   LIBS += $(XEN_LIBS)
hw/xen-backend.h +2 -0
index f7dd0c8..7489cbe 100644
@@ -2,6 +2,7 @@
 #define QEMU_XEN_BACKEND_H 1
 
 #include "xen-common.h"
+#include "sysemu.h"
 
 /* ------------------------------------------------------------- */
 
@@ -88,6 +89,7 @@ void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ...
 struct XenDevOps xen_console_ops;      /* xen_console.c     */
 struct XenDevOps xen_kbdmouse_ops;     /* xen_framebuffer.c */
 struct XenDevOps xen_framebuffer_ops;  /* xen_framebuffer.c */
+struct XenDevOps xen_blkdev_ops;       /* xen_disk.c        */
 
 void xen_set_display(int domid, DisplayState *ds);
 
hw/xen-blkif.h new file +103 -0

103 lines not on this page · raw message

hw/xen-disk.c new file +677 -0

677 lines not on this page · raw message

hw/xen-machine.c +1 -0
index 8d7140a..a1289c1 100644
@@ -101,6 +101,7 @@ static int xen_init_pv(DisplayState *ds)
     xen_be_register("console", &xen_console_ops);
     xen_be_register("vkbd", &xen_kbdmouse_ops);
     xen_be_register("vfb", &xen_framebuffer_ops);
+    xen_be_register("qdisk", &xen_blkdev_ops);
 
     /* setup framebuffer */
     xen_set_display(xen_domid, ds);
sysemu.h +1 -1
index b12fae0..49e75b1 100644
@@ -113,7 +113,7 @@ extern unsigned int nb_prom_envs;
 #endif
 
 typedef enum {
-    IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD
+    IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_XEN
 } BlockInterfaceType;
 
 typedef struct DriveInfo {
vl.c +4 -0
index c3f2185..a80a46e 100644
@@ -5484,6 +5484,9 @@ static int drive_init(struct drive_opt *arg, int snapshot,
 	} else if (!strcmp(buf, "sd")) {
 	    type = IF_SD;
             max_devs = 0;
+	} else if (!strcmp(buf, "xen")) {
+	    type = IF_XEN;
+            max_devs = 0;
 	} else {
             fprintf(stderr, "qemu: '%s' unsupported bus type '%s'\n", str, buf);
             return -1;
@@ -5669,6 +5672,7 @@ static int drive_init(struct drive_opt *arg, int snapshot,
     switch(type) {
     case IF_IDE:
     case IF_SCSI:
+    case IF_XEN:
         switch(media) {
 	case MEDIA_DISK:
             if (cyls != 0) {
Signature · 1 line
1.5.5.1
#6 lore raw

PATCH 6/7 xen: add net backend driver.

In reply to Gerd Hoffmann

This patch adds a network interface backend driver to qemu. It is a pure userspace implemention using the gntdev interface. It uses "qnet" as backend name in xenstore so it doesn't interfere with the netback backend (aka "vnif").

The network backend is hooked into the corrosponding qemu vlan, i.e. vif 0 is hooked into vlan 0. To make the packages actually arrive somewhere you additionally have to link the vlan to the outside world using the usual qemu command line options such as "-net tap,...".

---
 Makefile.target  |    2 +-
 hw/xen-backend.h |    1 +
 hw/xen-machine.c |    1 +
 hw/xen-nic.c     |  380 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 383 insertions(+), 1 deletions(-)
 create mode 100644 hw/xen-nic.c
Makefile.target +1 -1
index e668bd2..85f938c 100644
@@ -517,7 +517,7 @@ endif
 
 # xen backend driver support
 XEN_OBJS := xen-machine.o xen-backend.o
-XEN_OBJS += xen-console.o xen-framebuffer.o xen-disk.o
+XEN_OBJS += xen-console.o xen-framebuffer.o xen-disk.o xen-nic.o
 ifeq ($(CONFIG_XEN), yes)
   OBJS += $(XEN_OBJS)
   LIBS += $(XEN_LIBS)
hw/xen-backend.h +1 -0
index 7489cbe..b484752 100644
@@ -90,6 +90,7 @@ struct XenDevOps xen_console_ops;      /* xen_console.c     */
 struct XenDevOps xen_kbdmouse_ops;     /* xen_framebuffer.c */
 struct XenDevOps xen_framebuffer_ops;  /* xen_framebuffer.c */
 struct XenDevOps xen_blkdev_ops;       /* xen_disk.c        */
+struct XenDevOps xen_netdev_ops;       /* xen_nic.c         */
 
 void xen_set_display(int domid, DisplayState *ds);
 
hw/xen-machine.c +1 -0
index a1289c1..c8fb256 100644
@@ -102,6 +102,7 @@ static int xen_init_pv(DisplayState *ds)
     xen_be_register("vkbd", &xen_kbdmouse_ops);
     xen_be_register("vfb", &xen_framebuffer_ops);
     xen_be_register("qdisk", &xen_blkdev_ops);
+    xen_be_register("qnic", &xen_netdev_ops);
 
     /* setup framebuffer */
     xen_set_display(xen_domid, ds);
hw/xen-nic.c new file +380 -0

380 lines not on this page · raw message

Signature · 1 line
1.5.5.1
#7 lore raw

PATCH 7/7 xen: blk & nic configuration via cmd line.

In reply to Gerd Hoffmann

This patch makes qemu create backend and frontend device entries in xenstore for devices configured on the command line. It will use qdisk and qnic backend names, so the qemu internal backends will be used.

Disks can be created using -drive if=xen,file=...
Nics can be created using -net nic,macaddr=...

---
 Makefile.target  |    2 +-
 hw/xen-backend.h |    7 +++
 hw/xen-config.c  |  139 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/xen-machine.c |   19 +++++++-
 4 files changed, 165 insertions(+), 2 deletions(-)
 create mode 100644 hw/xen-config.c
Makefile.target +1 -1
index 85f938c..a3f8d24 100644
@@ -516,7 +516,7 @@ LIBS += $(CONFIG_VNC_TLS_LIBS)
 endif
 
 # xen backend driver support
-XEN_OBJS := xen-machine.o xen-backend.o
+XEN_OBJS := xen-machine.o xen-backend.o xen-config.o
 XEN_OBJS += xen-console.o xen-framebuffer.o xen-disk.o xen-nic.o
 ifeq ($(CONFIG_XEN), yes)
   OBJS += $(XEN_OBJS)
hw/xen-backend.h +7 -0
index b484752..c1da2ca 100644
@@ -3,6 +3,8 @@
 
 #include "xen-common.h"
 #include "sysemu.h"
+#include "net.h"
+#include "block_int.h"
 
 /* ------------------------------------------------------------- */
 
@@ -94,4 +96,9 @@ struct XenDevOps xen_netdev_ops;       /* xen_nic.c         */
 
 void xen_set_display(int domid, DisplayState *ds);
 
+/* configuration (aka xenbus setup) */
+void xen_config_cleanup(void);
+int xen_config_dev_blk(DriveInfo *disk);
+int xen_config_dev_nic(NICInfo *nic);
+
 #endif /* QEMU_XEN_BACKEND_H */
hw/xen-config.c new file +139 -0

139 lines not on this page · raw message

hw/xen-machine.c +18 -1
index c8fb256..4e4d893 100644
@@ -121,7 +121,7 @@ static void xenpv_init(ram_addr_t ram_size, int vga_ram_size,
 		       const char *cpu_model)
 {
     CPUState *env;
-    int rc;
+    int index,i,rc;
 
     rc = xen_init_pv(ds);
     if (-1 == rc)
@@ -147,6 +147,23 @@ static void xenpv_init(ram_addr_t ram_size, int vga_ram_size,
     env = cpu_init(cpu_model);
     env->halted = 1;
 
+    /* configure disks */
+    for (i = 0; i < 16; i++) {
+        index = drive_get_index(IF_XEN, 0, i);
+	if (index == -1)
+	    continue;
+	xen_config_dev_blk(drives_table + index);
+    }
+
+    /* configure nics */
+    for (i = 0; i < nb_nics; i++) {
+	if (nd_table[i].model && 0 != strcmp(nd_table[i].model, "xen"))
+	    continue;
+        xen_config_dev_nic(nd_table + i);
+    }
+
+    /* config cleanup hook */
+    atexit(xen_config_cleanup);
     return;
 
 err:
Signature · 1 line
1.5.5.1