xen: pv domain support.
cover xen: pv domain support.
Hi,
Next round, addressing review comments. Bulk of the changes are just coding style, i.e. swap ordering of the funny "if (-1 == foo()) bar()" compare style. Also the FSF address is fixed everythere. And the qemu disk backend uses vectorized aio now.
Short overview (individual patches have longer descriptions):
#1 - groundwork for xen support (makefiles, configure, ...). #2 - backend driver core (common code used by all backends). #3 - add console backend driver. #4 - add framebuffer backend driver.
With these four patches in place upstream qemu is functional aequivalent to qemu-xen for paravirtual guests. The patches are merged into qemu-xen already, with the exception of a few framebuffer bits which got hold back due to displaystate work and the most recent updates due to review comments.
#5 - add block device backend driver.
#6 - add net backend driver.
These two patches add backend drivers for disk and network to qemu.
#7 - blk & nic configuration via cmd line. #8 - pv domain builder. #9 - simplify vga selection
#10 - add -vga xenfb option, configure xenfb
These patches add support to qemu for creating xen pv guests. That way one can run xen guests without xend. Patch #8 is the domain builder code itself. The other patches add support for configuring devices (fb, disk, nic) via command line.
The patches are also available via git:
git: git://git.et.redhat.com/qemu-kraxel.git
gitweb: http://git.et.redhat.com/?p=qemu-kraxel.git
branches:
xenbits.v5 - this patch series. qx.misc.v4 - xenfb update + review changes for qemu-xen.
Ian, is just pulling from git fine with you? Or do you want the qemu-xen patches mailed to xen-devel?
cheers,
Gerd
PATCH 1/10 xen: groundwork for xen support
- configure script and build system changes.
- wind up new machine type.
- add -xen-* command line options.
--- Makefile.target | 7 +++++ configure | 34 +++++++++++++++++++++++++++ hw/boards.h | 3 ++ hw/xen.h | 20 ++++++++++++++++ hw/xen_machine_pv.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 11 +++++++++ target-i386/machine.c | 3 ++ vl.c | 12 +++++++++ 8 files changed, 151 insertions(+), 0 deletions(-) create mode 100644 hw/xen.h create mode 100644 hw/xen_machine_pv.c
Makefile.target +7 -0
@@ -557,6 +557,13 @@ ifdef CONFIG_BLUEZ LIBS += $(CONFIG_BLUEZ_LIBS) endif +# xen backend driver support +XEN_OBJS := xen_machine_pv.o +ifeq ($(CONFIG_XEN), yes) + OBJS += $(XEN_OBJS) + LIBS += $(XEN_LIBS) +endif + # SCSI layer OBJS+= lsi53c895a.o esp.o
configure +34 -0
@@ -190,6 +190,7 @@ aix="no" blobs="yes" fdt="yes" sdl_x11="no" +xen="yes" # OS specific if check_define __linux__ ; then
@@ -409,6 +410,8 @@ for opt do ;; --disable-kqemu) kqemu="no" ;; + --disable-xen) xen="no" + ;; --disable-brlapi) brlapi="no" ;; --disable-bluez) bluez="no"
@@ -568,6 +571,7 @@ echo " Available drivers: $audio_possible_drivers" echo " --audio-card-list=LIST set list of emulated audio cards [$audio_card_list]" echo " Available cards: $audio_possible_cards" 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-vnc-sasl disable SASL encryption for VNC server"
@@ -781,6 +785,22 @@ else fi ########################################## +# xen probe + +if test "$xen" = "yes" ; then +cat > $TMPC <<EOF +#include <xenctrl.h> +#include <xs.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
@@ -1211,6 +1231,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" ] && \
@@ -1512,6 +1533,9 @@ if test "$bluez" = "yes" ; then echo "CONFIG_BLUEZ_LIBS=$bluez_libs" >> $config_mak echo "#define CONFIG_BLUEZ 1" >> $config_h fi +if test "$xen" = "yes" ; then + echo "XEN_LIBS=-lxenstore -lxenctrl" >> $config_mak +fi if test "$aio" = "yes" ; then echo "#define CONFIG_AIO 1" >> $config_h echo "CONFIG_AIO=yes" >> $config_mak
@@ -1673,6 +1697,11 @@ case "$target_cpu" in echo "KVM_CFLAGS=$kvm_cflags" >> $config_mak echo "#define CONFIG_KVM 1" >> $config_h fi + if test "$xen" = "yes" -a "$target_softmmu" = "yes"; + then + echo "CONFIG_XEN=yes" >> $config_mak + echo "#define CONFIG_XEN 1" >> $config_h + fi ;; x86_64) echo "TARGET_ARCH=x86_64" >> $config_mak
@@ -1688,6 +1717,11 @@ case "$target_cpu" in echo "KVM_CFLAGS=$kvm_cflags" >> $config_mak echo "#define CONFIG_KVM 1" >> $config_h fi + if test "$xen" = "yes" -a "$target_softmmu" = "yes" + then + echo "CONFIG_XEN=yes" >> $config_mak + echo "#define CONFIG_XEN 1" >> $config_h + fi ;; alpha) echo "TARGET_ARCH=alpha" >> $config_mak
hw/boards.h +3 -0
@@ -34,6 +34,9 @@ extern QEMUMachine axisdev88_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.h new file +20 -0
@@ -0,0 +1,20 @@ +#ifndef QEMU_HW_XEN_H +#define QEMU_HW_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 */ +enum xen_mode { +XEN_EMULATE =0 ,// xen emulation, using xenner (default) +XEN_CREATE ,// create xen domain +XEN_ATTACH // attach to xen domain created by xend +}; + +extern uint32_t xen_domid; +extern enum xen_mode xen_mode; + +#endif /* QEMU_HW_XEN_H */
hw/xen_machine_pv.c new file +61 -0
61 lines not on this page · raw message
qemu-options.hx +11 -0
@@ -1305,6 +1305,17 @@ Enable KVM full virtualization support. This option is only available if KVM support is enabled when compiling. ETEXI +#ifdef CONFIG_XEN +DEF("xen-domid", HAS_ARG, QEMU_OPTION_xen_domid, + "-xen-domid id specify xen guest domain id\n") +DEF("xen-create", 0, QEMU_OPTION_xen_create, + "-xen-create create domain using xen hypercalls, bypassing xend\n" + " warning: should not be used when xend is in use\n") +DEF("xen-attach", 0, QEMU_OPTION_xen_attach, + "-xen-attach attach to existing xen domain\n" + " xend will use this when starting qemu\n") +#endif + DEF("no-reboot", 0, QEMU_OPTION_no_reboot, \ "-no-reboot exit instead of rebooting\n") STEXI
target-i386/machine.c +3 -0
@@ -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 +12 -0
@@ -138,6 +138,7 @@ int main(int argc, char **argv)#include "hw/isa.h" #include "hw/baum.h" #include "hw/bt.h" +#include "hw/xen.h" #include "bt-host.h" #include "net.h" #include "monitor.h"
@@ -4949,6 +4950,17 @@ int main(int argc, char **argv, char **envp) run_as = optarg;break ;#endif +#ifdef CONFIG_XEN +case QEMU_OPTION_xen_domid: + xen_domid =atoi (optarg); +break ; +case QEMU_OPTION_xen_create: + xen_mode =XEN_CREATE ; +break ; +case QEMU_OPTION_xen_attach: + xen_mode =XEN_ATTACH ; +break ; +#endif } } }
Signature · 1 line
1.6.2.2
PATCH 2/10 xen: backend driver core
In reply to Gerd HoffmannThis 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 | 691 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/xen_backend.h | 86 +++++++ hw/xen_common.h | 34 +++ hw/xen_machine_pv.c | 8 +- 5 files changed, 819 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
@@ -558,7 +558,7 @@ LIBS += $(CONFIG_BLUEZ_LIBS) endif # xen backend driver support -XEN_OBJS := xen_machine_pv.o +XEN_OBJS := xen_machine_pv.o xen_backend.o ifeq ($(CONFIG_XEN), yes) OBJS += $(XEN_OBJS) LIBS += $(XEN_LIBS)
hw/xen_backend.c new file +691 -0
691 lines not on this page · raw message
hw/xen_backend.h new file +86 -0
86 lines not on this page · raw message
hw/xen_common.h new file +34 -0
@@ -0,0 +1,34 @@ +#ifndef QEMU_HW_XEN_COMMON_H +#define QEMU_HW_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__ <0x00030205 +# define evtchn_port_or_error_t int +#endif +#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 + +#endif /* QEMU_HW_XEN_COMMON_H */
hw/xen_machine_pv.c +7 -1
@@ -26,7 +26,7 @@#include "pc.h" #include "sysemu.h" #include "boards.h" -#include "xen.h" +#include "xen_backend.h" uint32_t xen_domid;enum xen_mode xen_mode =XEN_EMULATE ;
@@ -50,6 +50,12 @@ static void xen_init_pv(ram_addr_t ram_size, int vga_ram_size, } env =cpu_init (cpu_model); env->halted =1 ; + +/* Initialize backend core & drivers */ +if (-1 ==xen_be_init ()) { +fprintf (stderr,"%s: xen backend core setup failed\n" , __FUNCTION__); +exit (1 ); + } }QEMUMachine xenpv_machine = {
Signature · 1 line
1.6.2.2
PATCH 3/10 xen: add console backend driver.
In reply to Gerd HoffmannThis 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 | 276 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/xen_machine_pv.c | 1 + 4 files changed, 281 insertions(+), 0 deletions(-) create mode 100644 hw/xen_console.c
Makefile.target +1 -0
@@ -559,6 +559,7 @@ endif # xen backend driver support XEN_OBJS := xen_machine_pv.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
@@ -83,4 +83,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 */ +extern struct XenDevOps xen_console_ops;/* xen_console.c */ +#endif /* QEMU_HW_XEN_BACKEND_H */
hw/xen_console.c new file +276 -0
276 lines not on this page · raw message
hw/xen_machine_pv.c +1 -0
@@ -56,6 +56,7 @@ static void xen_init_pv(ram_addr_t ram_size, int vga_ram_size,fprintf (stderr,"%s: xen backend core setup failed\n" , __FUNCTION__);exit (1 ); } +xen_be_register ("console" , &xen_console_ops); }QEMUMachine xenpv_machine = {
Signature · 1 line
1.6.2.2
PATCH 4/10 xen: add framebuffer backend driver
In reply to Gerd HoffmannThis 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 release 3.3
--- Makefile.target | 2 +- hw/xen_backend.h | 4 + hw/xen_machine_pv.c | 5 + hw/xenfb.c | 1017 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1027 insertions(+), 1 deletions(-) create mode 100644 hw/xenfb.c
Makefile.target +1 -1
@@ -559,7 +559,7 @@ endif # xen backend driver support XEN_OBJS := xen_machine_pv.o xen_backend.o -XEN_OBJS += xen_console.o +XEN_OBJS += xen_console.o xenfb.o ifeq ($(CONFIG_XEN), yes) OBJS += $(XEN_OBJS) LIBS += $(XEN_LIBS)
hw/xen_backend.h +4 -0
@@ -85,5 +85,9 @@ void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, .../* actual backend drivers */ extern struct XenDevOps xen_console_ops;/* xen_console.c */ +extern struct XenDevOps xen_kbdmouse_ops;/* xen_framebuffer.c */ +extern struct XenDevOps xen_framebuffer_ops;/* xen_framebuffer.c */ + +void xen_init_display (int domid);#endif /* QEMU_HW_XEN_BACKEND_H */
hw/xen_machine_pv.c +5 -0
@@ -57,6 +57,11 @@ static void xen_init_pv(ram_addr_t ram_size, int vga_ram_size,exit (1 ); }xen_be_register ("console" , &xen_console_ops); +xen_be_register ("vkbd" , &xen_kbdmouse_ops); +xen_be_register ("vfb" , &xen_framebuffer_ops); + +/* setup framebuffer */ +xen_init_display (xen_domid); }QEMUMachine xenpv_machine = {
hw/xenfb.c new file +1017 -0
1,017 lines not on this page · raw message
Signature · 1 line
1.6.2.2
PATCH 5/10 xen: add block device backend driver.
In reply to Gerd HoffmannThis 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 | 777 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/xen_machine_pv.c | 1 + sysemu.h | 2 +- vl.c | 6 +- 7 files changed, 890 insertions(+), 3 deletions(-) create mode 100644 hw/xen_blkif.h create mode 100644 hw/xen_disk.c
Makefile.target +1 -1
@@ -559,7 +559,7 @@ endif # xen backend driver support XEN_OBJS := xen_machine_pv.o xen_backend.o -XEN_OBJS += xen_console.o xenfb.o +XEN_OBJS += xen_console.o xenfb.o xen_disk.o ifeq ($(CONFIG_XEN), yes) OBJS += $(XEN_OBJS) LIBS += $(XEN_LIBS)
hw/xen_backend.h +2 -0
@@ -2,6 +2,7 @@#define QEMU_HW_XEN_BACKEND_H 1#include "xen_common.h" +#include "sysemu.h" /* ------------------------------------------------------------- */
@@ -87,6 +88,7 @@ void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ...extern struct XenDevOps xen_console_ops;/* xen_console.c */ extern struct XenDevOps xen_kbdmouse_ops;/* xen_framebuffer.c */ extern struct XenDevOps xen_framebuffer_ops;/* xen_framebuffer.c */ +extern struct XenDevOps xen_blkdev_ops;/* xen_disk.c */ void xen_init_display (int domid);
hw/xen_blkif.h new file +103 -0
103 lines not on this page · raw message
hw/xen_disk.c new file +777 -0
777 lines not on this page · raw message
hw/xen_machine_pv.c +1 -0
@@ -59,6 +59,7 @@ static void xen_init_pv(ram_addr_t ram_size, int vga_ram_size,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_init_display (xen_domid);
sysemu.h +1 -1
@@ -127,7 +127,7 @@ extern unsigned int nb_prom_envs;#endif typedef enum { -IF_IDE ,IF_SCSI ,IF_FLOPPY ,IF_PFLASH ,IF_MTD ,IF_SD ,IF_VIRTIO +IF_IDE ,IF_SCSI ,IF_FLOPPY ,IF_PFLASH ,IF_MTD ,IF_SD ,IF_VIRTIO ,IF_XEN }BlockInterfaceType ; typedef enum {
vl.c +5 -1
@@ -2368,7 +2368,10 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) }else if (!strcmp (buf,"virtio" )) { type =IF_VIRTIO ; max_devs =0 ; - }else { + }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 ; }
@@ -2582,6 +2585,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)switch (type) {case IF_IDE :case IF_SCSI : +case IF_XEN :switch (media) {case MEDIA_DISK :if (cyls !=0 ) {
Signature · 1 line
1.6.2.2
PATCH 6/10 xen: add net backend driver.
In reply to Gerd HoffmannThis 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_pv.c | 1 + hw/xen_nic.c | 396 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 399 insertions(+), 1 deletions(-) create mode 100644 hw/xen_nic.c
Makefile.target +1 -1
@@ -559,7 +559,7 @@ endif # xen backend driver support XEN_OBJS := xen_machine_pv.o xen_backend.o -XEN_OBJS += xen_console.o xenfb.o xen_disk.o +XEN_OBJS += xen_console.o xenfb.o xen_disk.o xen_nic.o ifeq ($(CONFIG_XEN), yes) OBJS += $(XEN_OBJS) LIBS += $(XEN_LIBS)
hw/xen_backend.h +1 -0
@@ -89,6 +89,7 @@ extern struct XenDevOps xen_console_ops; /* xen_console.c */extern struct XenDevOps xen_kbdmouse_ops;/* xen_framebuffer.c */ extern struct XenDevOps xen_framebuffer_ops;/* xen_framebuffer.c */ extern struct XenDevOps xen_blkdev_ops;/* xen_disk.c */ +extern struct XenDevOps xen_netdev_ops;/* xen_nic.c */ void xen_init_display (int domid);
hw/xen_machine_pv.c +1 -0
@@ -60,6 +60,7 @@ static void xen_init_pv(ram_addr_t ram_size, int vga_ram_size,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_init_display (xen_domid);
hw/xen_nic.c new file +396 -0
396 lines not on this page · raw message
Signature · 1 line
1.6.2.2
PATCH 7/10 xen: blk & nic configuration via cmd line.
In reply to Gerd HoffmannThis 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.c | 1 + hw/xen_backend.h | 8 +++ hw/xen_devconfig.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/xen_machine_pv.c | 19 +++++++ 5 files changed, 174 insertions(+), 1 deletions(-) create mode 100644 hw/xen_devconfig.c
Makefile.target +1 -1
@@ -558,7 +558,7 @@ LIBS += $(CONFIG_BLUEZ_LIBS) endif # xen backend driver support -XEN_OBJS := xen_machine_pv.o xen_backend.o +XEN_OBJS := xen_machine_pv.o xen_backend.o xen_devconfig.o XEN_OBJS += xen_console.o xenfb.o xen_disk.o xen_nic.o ifeq ($(CONFIG_XEN), yes) OBJS += $(XEN_OBJS)
hw/xen_backend.c +1 -0
@@ -45,6 +45,7 @@/* public */ int xen_xc;struct xs_handle *xenstore =NULL ; +const char *xen_protocol;/* private */ static TAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = TAILQ_HEAD_INITIALIZER(xendevs);
hw/xen_backend.h +8 -0
@@ -3,6 +3,8 @@#include "xen_common.h" #include "sysemu.h" +#include "net.h" +#include "block_int.h" /* ------------------------------------------------------------- */
@@ -56,6 +58,7 @@ struct XenDevice {/* variables */ extern int xen_xc;extern struct xs_handle *xenstore; +extern const char *xen_protocol;/* xenstore helper functions */ int xenstore_write_str (const char *base,const char *node,const char *val);
@@ -93,4 +96,9 @@ extern struct XenDevOps xen_netdev_ops; /* xen_nic.c */void xen_init_display (int domid); +/* 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_HW_XEN_BACKEND_H */
hw/xen_devconfig.c new file +145 -0
145 lines not on this page · raw message
hw/xen_machine_pv.c +19 -0
@@ -39,6 +39,7 @@ static void xen_init_pv(ram_addr_t ram_size, int vga_ram_size, const char *cpu_model) {CPUState *env; +int i, index;/* Initialize a dummy CPU */ if (cpu_model ==NULL ) {
@@ -62,6 +63,24 @@ static void xen_init_pv(ram_addr_t ram_size, int vga_ram_size,xen_be_register ("qdisk" , &xen_blkdev_ops);xen_be_register ("qnic" , &xen_netdev_ops); +/* 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); +/* setup framebuffer */ xen_init_display (xen_domid); }
Signature · 1 line
1.6.2.2
PATCH 8/10 xen: pv domain builder.
In reply to Gerd HoffmannThis adds domain building support for paravirtual domains to qemu. This allows booting xen guests directly with qemu, without Xend and the management stack.
--- Makefile.target | 2 +- configure | 2 +- hw/xen_backend.h | 3 + hw/xen_devconfig.c | 29 +++++ hw/xen_domainbuild.c | 294 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/xen_domainbuild.h | 13 +++ hw/xen_machine_pv.c | 19 ++++ 7 files changed, 360 insertions(+), 2 deletions(-) create mode 100644 hw/xen_domainbuild.c create mode 100644 hw/xen_domainbuild.h
Makefile.target +1 -1
@@ -558,7 +558,7 @@ LIBS += $(CONFIG_BLUEZ_LIBS) endif # xen backend driver support -XEN_OBJS := xen_machine_pv.o xen_backend.o xen_devconfig.o +XEN_OBJS := xen_machine_pv.o xen_backend.o xen_devconfig.o xen_domainbuild.o XEN_OBJS += xen_console.o xenfb.o xen_disk.o xen_nic.o ifeq ($(CONFIG_XEN), yes) OBJS += $(XEN_OBJS)
configure +1 -1
@@ -1534,7 +1534,7 @@ if test "$bluez" = "yes" ; then echo "#define CONFIG_BLUEZ 1" >> $config_h fi if test "$xen" = "yes" ; then - echo "XEN_LIBS=-lxenstore -lxenctrl" >> $config_mak + echo "XEN_LIBS=-lxenstore -lxenctrl -lxenguest" >> $config_mak fi if test "$aio" = "yes" ; then echo "#define CONFIG_AIO 1" >> $config_h
hw/xen_backend.h +3 -0
@@ -100,5 +100,8 @@ void xen_init_display(int domid);void xen_config_cleanup (void );int xen_config_dev_blk (DriveInfo *disk);int xen_config_dev_nic (NICInfo *nic); +int xen_config_dev_vfb (int vdev,const char *type); +int xen_config_dev_vkbd (int vdev); +int xen_config_dev_console (int vdev);#endif /* QEMU_HW_XEN_BACKEND_H */
hw/xen_devconfig.c +29 -0
@@ -143,3 +143,32 @@ int xen_config_dev_nic(NICInfo *nic)/* common stuff */ return xen_config_dev_all (fe, be); } + +int xen_config_dev_vfb (int vdev,const char *type) +{ +char fe[256 ], be[256 ]; + +xen_config_dev_dirs ("vfb" ,"vfb" , vdev, fe, be,sizeof (fe)); + +/* backend */ +xenstore_write_str (be,"type" , type); + +/* common stuff */ +return xen_config_dev_all (fe, be); +} + +int xen_config_dev_vkbd (int vdev) +{ +char fe[256 ], be[256 ]; + +xen_config_dev_dirs ("vkbd" ,"vkbd" , vdev, fe, be,sizeof (fe)); +return xen_config_dev_all (fe, be); +} + +int xen_config_dev_console (int vdev) +{ +char fe[256 ], be[256 ]; + +xen_config_dev_dirs ("console" ,"console" , vdev, fe, be,sizeof (fe)); +return xen_config_dev_all (fe, be); +}
hw/xen_domainbuild.c new file +294 -0
294 lines not on this page · raw message
hw/xen_domainbuild.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef QEMU_HW_XEN_DOMAINBUILD_H +#define QEMU_HW_XEN_DOMAINBUILD_H 1 + +#include "xen_common.h" + +int xenstore_domain_init1 (const char *kernel,const char *ramdisk, +const char *cmdline); +int xenstore_domain_init2 (int xenstore_port,int xenstore_mfn, +int console_port,int console_mfn); +int xen_domain_build_pv (const char *kernel,const char *ramdisk, +const char *cmdline); + +#endif /* QEMU_HW_XEN_DOMAINBUILD_H */
hw/xen_machine_pv.c +19 -0
@@ -27,6 +27,7 @@#include "sysemu.h" #include "boards.h" #include "xen_backend.h" +#include "xen_domainbuild.h" uint32_t xen_domid;enum xen_mode xen_mode =XEN_EMULATE ;
@@ -57,6 +58,24 @@ static void xen_init_pv(ram_addr_t ram_size, int vga_ram_size,fprintf (stderr,"%s: xen backend core setup failed\n" , __FUNCTION__);exit (1 ); } + +switch (xen_mode) { +case XEN_ATTACH : +/* nothing to do, xend handles everything */ +break ; +case XEN_CREATE : +if (xen_domain_build_pv (kernel_filename, initrd_filename, + kernel_cmdline) <0 ) { +fprintf (stderr,"xen pv domain creation failed\n" ); +exit (1 ); + } +break ; +case XEN_EMULATE : +fprintf (stderr,"xen emulation not implemented (yet)\n" ); +exit (1 ); +break ; + } +xen_be_register ("console" , &xen_console_ops);xen_be_register ("vkbd" , &xen_kbdmouse_ops);xen_be_register ("vfb" , &xen_framebuffer_ops);
Signature · 1 line
1.6.2.2
PATCH 9/10 simplify vga selection
In reply to Gerd Hoffmann--- vl.c | 15 ++++----------- 1 files changed, 4 insertions(+), 11 deletions(-)
vl.c +4 -11
@@ -4153,23 +4153,16 @@ static void select_vgahw (const char *p) {const char *opts; + cirrus_vga_enabled =0 ; + std_vga_enabled =0 ; + vmsvga_enabled =0 ;if (strstart (p,"std" , &opts)) { std_vga_enabled =1 ; - cirrus_vga_enabled =0 ; - vmsvga_enabled =0 ; }else if (strstart (p,"cirrus" , &opts)) { cirrus_vga_enabled =1 ; - std_vga_enabled =0 ; - vmsvga_enabled =0 ; }else if (strstart (p,"vmware" , &opts)) { - cirrus_vga_enabled =0 ; - std_vga_enabled =0 ; vmsvga_enabled =1 ; - }else if (strstart (p,"none" , &opts)) { - cirrus_vga_enabled =0 ; - std_vga_enabled =0 ; - vmsvga_enabled =0 ; - }else { + }else if (!strstart (p,"none" , &opts)) { invalid_vga:fprintf (stderr,"Unknown vga type: %s\n" , p);exit (1 );
Signature · 1 line
1.6.2.2
PATCH 10/10 xen: add -vga xenfb option, configure xenfb
In reply to Gerd Hoffmann--- hw/xen_machine_pv.c | 6 ++++++ qemu-options.hx | 2 +- sysemu.h | 1 + vl.c | 4 ++++ 4 files changed, 12 insertions(+), 1 deletions(-)
hw/xen_machine_pv.c +6 -0
@@ -82,6 +82,12 @@ static void xen_init_pv(ram_addr_t ram_size, int vga_ram_size,xen_be_register ("qdisk" , &xen_blkdev_ops);xen_be_register ("qnic" , &xen_netdev_ops); +/* configure framebuffer */ +if (xenfb_enabled) { +xen_config_dev_vfb (0 ,"vnc" ); +xen_config_dev_vkbd (0 ); + } +/* configure disks */ for (i =0 ; i <16 ; i++) { index =drive_get_index (IF_XEN ,0 , i);
qemu-options.hx +1 -1
@@ -450,7 +450,7 @@ Rotate graphical output 90 deg left (only PXA LCD). ETEXI DEF("vga", HAS_ARG, QEMU_OPTION_vga, - "-vga [std|cirrus|vmware|none]\n" + "-vga [std|cirrus|vmware|xenfb|none]\n" " select video card type\n") STEXI @item -vga @var{type}
sysemu.h +1 -0
@@ -87,6 +87,7 @@ extern int bios_size;extern int cirrus_vga_enabled;extern int std_vga_enabled;extern int vmsvga_enabled; +extern int xenfb_enabled;extern int graphic_width;extern int graphic_height;extern int graphic_depth;
vl.c +4 -0
@@ -215,6 +215,7 @@ static int rtc_date_offset = -1; /* -1 means no change */int cirrus_vga_enabled =1 ;int std_vga_enabled =0 ;int vmsvga_enabled =0 ; +int xenfb_enabled =0 ;#ifdef TARGET_SPARC int graphic_width =1024 ;int graphic_height =768 ;
@@ -4156,12 +4157,15 @@ static void select_vgahw (const char *p) cirrus_vga_enabled =0 ; std_vga_enabled =0 ; vmsvga_enabled =0 ; + xenfb_enabled =0 ;if (strstart (p,"std" , &opts)) { std_vga_enabled =1 ; }else if (strstart (p,"cirrus" , &opts)) { cirrus_vga_enabled =1 ; }else if (strstart (p,"vmware" , &opts)) { vmsvga_enabled =1 ; + }else if (strstart (p,"xenfb" , &opts)) { + xenfb_enabled =1 ; }else if (!strstart (p,"none" , &opts)) { invalid_vga:fprintf (stderr,"Unknown vga type: %s\n" , p);
Signature · 1 line
1.6.2.2
Quoted 5 lines · Gerd Hoffmann
Hi,
Next round, addressing review comments. Bulk of the changes are just coding style, i.e. swap ordering of the funny "if (-1 ==
foo())bar()" compare style. Also the FSF address is fixed everythere. And the
There are still a lot of those funny comparisons.
Re: [Qemu-devel] [PATCH 02/10] xen: backend driver core
In reply to Gerd HoffmannQuoted 79 lines · 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, ...
Signed-off-by Gerd Hoffmann <[email protected]>--- Makefile.target | 2 +- hw/xen_backend.c | 691 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/xen_backend.h | 86 +++++++ hw/xen_common.h | 34 +++ hw/xen_machine_pv.c | 8 +- 5 files changed, 819 insertions(+), 2 deletions(-) create mode 100644 hw/xen_backend.c create mode 100644 hw/xen_backend.h create mode 100644 hw/xen_common.hMakefile.target +1
-1@@ -558,7 +558,7 @@ LIBS += $(CONFIG_BLUEZ_LIBS) endif # xen backend driver support -XEN_OBJS := xen_machine_pv.o +XEN_OBJS := xen_machine_pv.o xen_backend.o ifeq ($(CONFIG_XEN), yes) OBJS += $(XEN_OBJS) LIBS += $(XEN_LIBS)hw/xen_backend.c new file +41
-0@@ -0,0 +1,691 @@ +/* +* xen backend driver infrastructure +* (c) 2008 Gerd Hoffmann <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; under version 2 of the License. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +/* +* TODO: add some xenbus / xenstore concepts overview here. +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <inttypes.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <sys/signal.h> + +#include <xs.h> +#include <xenctrl.h> +#include <xen/grant_table.h> + +#include "hw.h" +#include "qemu-char.h" +#include "xen_backend.h"
hw/xen_backend.c line 51
Quoted 10 lines
hw/xen_backend.c new file +10
-0+ +/* ------------------------------------------------------------- */ + +/* public */ +int xen_xc; +struct xs_handle *xenstore =NULL ; + +/* private */ +static TAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = TAILQ_HEAD_INITIALIZER(xendevs); +static int debug =0 ;
Would be better to have all of this in a structure that had a single static instance. Would be even better if you could avoid requiring the static instance.
Quoted 10 lines
hw/xen_backend.c new file +9
-0+/* ------------------------------------------------------------- */ + +int xenstore_write_str (const char *base,const char *node,const char *val) +{ +char abspath[XEN_BUFSIZE ]; + +snprintf (abspath,sizeof (abspath),"%s/%s" , base, node); +if (!xs_write (xenstore,0 , abspath, val,strlen (val))) +return -1 ;
hw/xen_backend.c line 71
Quoted 10 lines
hw/xen_backend.c new file +10
-0+return 0 ; +} + +char *xenstore_read_str (const char *base,const char *node) +{ +char abspath[XEN_BUFSIZE ]; +unsigned int len; + +snprintf (abspath,sizeof (abspath),"%s/%s" , base, node); +return xs_read (xenstore,0 , abspath, &len);
xs_read() is a xenstore API, it's returning malloc()'d memory.
Quoted 10 lines
hw/xen_backend.c new file +9
-0+} + +int xenstore_write_int (const char *base,const char *node,int ival) +{ +char val[32 ]; + +snprintf (val,sizeof (val),"%d" , ival); +return xenstore_write_str (base, node, val); +}
hw/xen_backend.c line 90
Quoted 10 lines
hw/xen_backend.c new file +10
-0+ +int xenstore_read_int (const char *base,const char *node,int *ival) +{ +char *val; +int rc =-1 ; + + val =xenstore_read_str (base, node); +if (val &&1 ==sscanf (val,"%d" , ival)) + rc =0 ; +qemu_free (val);
And here you're free()'ing with qemu_free.
Quoted 8 lines
hw/xen_backend.c new file +7
-0+/* +* get xen backend device, allocate a new one if it doesn't exist. +*/ +static struct XenDevice *xen_be_get_xendev (const char *type,int dom,int dev, +struct XenDevOps *ops) +{ +struct XenDevice *xendev;
hw/xen_backend.c line 187
Quoted 10 lines
hw/xen_backend.c new file +10
-0+char *dom0; + + xendev =xen_be_find_xendev (type, dom, dev); +if (xendev) +return xendev; + +/* init new xendev */ + xendev =qemu_mallocz (ops->size); +if (!xendev) +return NULL ;
No need to check malloc failures.
hw/xen_backend.c line 521
Quoted 13 lines
hw/xen_backend.c new file +12
-0+ +/* look for backends */ + dev =xs_directory (xenstore,0 , path, &cdev); +if (!dev) +return 0 ; +for (j =0 ; j < cdev; j++) { + xendev =xen_be_get_xendev (type, dom,atoi (dev[j]), ops); +if (xendev ==NULL ) +continue ; +xen_be_check_state (xendev); + } +qemu_free (dev);
Mixing qemu_free() with malloc'd memory.
Quoted 8 lines
hw/xen_backend.c new file +7
-0+static void xenstore_update_be (char *watch,char *type,int dom, +struct XenDevOps *ops) +{ +struct XenDevice *xendev; +char path[XEN_BUFSIZE ], *dom0; +unsigned int len, dev; +
hw/xen_backend.c line 541
Quoted 10 lines
hw/xen_backend.c new file +10
-0+ dom0 =xs_get_domain_path (xenstore,0 ); + len =snprintf (path,sizeof (path),"%s/backend/%s/%d" , dom0, type, dom); +free (dom0); +if (0 !=strncmp (path, watch, len)) +return ; +if (2 !=sscanf (watch+len,"/%u/%255s" , &dev, path)) { +strcpy (path,"" ); +if (1 !=sscanf (watch+len,"/%u" , &dev)) + dev =-1 ; + }
Overly defensive ifs. You also have open coded calls to fprintf(stderr) whereas you've introduced a higher level function.
Regards,
Anthony Liguori
Re: [Qemu-devel] [PATCH 02/10] xen: backend driver core
Quoted 8 lines · Anthony Liguori
Quoted 4 lines
(quoted diff) +2
-0+/* private */ +static TAILQ_HEAD(XenDeviceHead, XenDevice) xendevs =
TAILQ_HEAD_INITIALIZER(xendevs);
+static int debug = 0;Would be better to have all of this in a structure that had a single static instance. Would be even better if you could avoid requiring the static instance.
Huh? Point being? This is just a list head, i.e. a pointer (or two?).
Quoted 10 lines
hw/xen_backend.c line 71
Quoted 7 lines
hw/xen_backend.c new file +7
-0+char *xenstore_read_str (const char *base,const char *node) +{ +char abspath[XEN_BUFSIZE ]; +unsigned int len; + +snprintf (abspath,sizeof (abspath),"%s/%s" , base, node); +return xs_read (xenstore,0 , abspath, &len);
xs_read()is a xenstore API, it's returning malloc()'d memory.
Quoted 11 lines
hw/xen_backend.c line 90
Quoted 9 lines
hw/xen_backend.c new file +9
-0+int xenstore_read_int (const char *base,const char *node,int *ival) +{ +char *val; +int rc =-1 ; + + val =xenstore_read_str (base, node); +if (val &&1 ==sscanf (val,"%d" , ival)) + rc =0 ; +qemu_free (val);And here you're free()'ing with
qemu_free.
Oops. Good catch.
Quoted 5 lines
Quoted 3 lines
+ xendev =
qemu_mallocz(ops->size);
+ if (!xendev)
+ return NULL;No need to check malloc failures.
Will fix.
Quoted 4 lines
Quoted 2 lines
+ dev =
xs_directory(xenstore, 0, path, &cdev);
+qemu_free(dev);Mixing
qemu_free()with malloc'd memory.
This too.
Quoted 2 lines
You also have open coded calls to fprintf(stderr) whereas you've introduced a higher level function.
The high-level function wants a device instance and thus doesn't work everythere. Nevertheless the code probably should use the new qemu_log() function instead. I'll look into this.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 02/10] xen: backend driver core
Quoted 2 lines · Gerd Hoffmann
Nevertheless the code probably should use the new
qemu_log()function instead.
Well, for debug/info only. Errors should still go to stderr I think.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 02/10] xen: backend driver core
In reply to Gerd HoffmannQuoted 11 lines · Gerd Hoffmann
Quoted 8 lines · Anthony Liguori
Quoted 4 lines
(quoted diff) +2
-0+/* private */ +static TAILQ_HEAD(XenDeviceHead, XenDevice) xendevs =
TAILQ_HEAD_INITIALIZER(xendevs);
+static int debug = 0;Would be better to have all of this in a structure that had a single static instance. Would be even better if you could avoid requiring the static instance.
Huh? Point being? This is just a list head, i.e. a pointer (or two?).
I meant the public stuff too. I don't like having extern variables all over the place.
It would be better to have this in a structure that was passed to all of the backend drivers that they then passed as a context. This will become more useful down the road too when we start introducing a common device model and finer grain locking.
Regards,
Anthony Liguori
Quoted 8 lines · Blue Swirl
Quoted 5 lines · Gerd Hoffmann
Hi,Next round, addressing review comments. Bulk of the changes are just coding style, i.e. swap ordering of the funny "if (-1 ==
foo())bar()" compare style. Also the FSF address is fixed everythere. And theThere are still a lot of those funny comparisons.
Oops. My grep missed the != comparisons. And a single one here and there.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 02/10] xen: backend driver core
In reply to Anthony LiguoriQuoted 7 lines · Anthony Liguori
I meant the public stuff too. I don't like having extern variables all over the place.
It would be better to have this in a structure that was passed to all of the backend drivers that they then passed as a context. This will become more useful down the road too when we start introducing a common device model and finer grain locking.
The variables are more global xen state, not device / xenbus state. The usage is not limited to the backend drivers, the domain builder code will use them as well. There will never ever be more than one instance of these. I don't see the point of placing them into a struct and passing around a pointer.
cheers,
Gerd