Skip to contentSkip to conversation

PATCH: 0/10: Merge paravirt FB & console into qemu-dm

DISCUSSION Daniel P. Berrange 1 participant 11 messages Aug 22, 2007

lore
Share & tools
lore
#0 lore raw

The following series of 10 patches is a merge of the xenfb and xenconsoled functionality into the qemu-dm code. The general approach taken is to have qemu-dm provide two machine types - one for xen paravirt, the other for fullyvirt. For compatability the later is the default. The goals overall are to kill LibVNCServer, remove alot of code duplication and/or parallel impls of the same concepts, and increase the functionality for PV. In particular this will let paravirt guests take advantage of TLS encryption for the VNC server, and let us configure the text console in all the variety of ways QEMU supports (PTY, File, TCP, TCP_Telnet,UDP, etc).

One interesting possiblity that merging the text & graphics consoles into same daemon allows for, is to expose the pygrub screens over both a PTY and VNC server at the same time. If I can figure out how to actually code this idea it would solve a major headache when using bootloaders with PV guests remotely.

The patches should be applied in order - after each individual patch you should still have a fully operational system for both FV & PV. I have tested save/restore, save+checkpoint, and migration for fullyvirt, paravirt with SUSPEND_CANCEL, and paravirt without SUSPEND_CANCEL. With the latter I get sporadic failures - both with and without my changes - so I think that's a more general compat problem in xen-unstable.hg.

I've included diffstats inline with each patch, but since there's a fair bit of general re-factoring / moving code in intermediate patches here is a summary of the stats for the series as a whole. I recommend applying each patch individually though to preserve the history of changes.

 Config.mk                               |    1 
 a/tools/check/check_libvncserver        |   38 -
 a/tools/check/check_sdl                 |   27 
 a/tools/xenfb/Makefile                  |   32 
 a/tools/xenfb/sdlfb.c                   |  342 ----------
 a/tools/xenfb/vncfb.c                   |  522 ---------------
 a/tools/xenfb/xenfb.c                   |  785 -----------------------
 a/tools/xenfb/xenfb.h                   |   35 -
 b/tools/ioemu/hw/xen_console.c          |  424 ++++++++++++
 b/tools/ioemu/hw/xen_console.h          |   25 
 b/tools/ioemu/hw/xen_machine_fv.c       |  286 ++++++++
 b/tools/ioemu/hw/xen_machine_pv.c       |   74 ++
 b/tools/ioemu/hw/xenfb.c                | 1051 ++++++++++++++++++++++++++++++++
 b/tools/ioemu/hw/xenfb.h                |   13 
 tools/Makefile                          |    1 
 tools/check/Makefile                    |    4 
 tools/console/daemon/io.c               |    9 
 tools/ioemu/Makefile.target             |    4 
 tools/ioemu/target-i386-dm/helper2.c    |    5 
 tools/ioemu/vl.c                        |  249 -------
 tools/ioemu/vl.h                        |    4 
 tools/ioemu/xenstore.c                  |    2 
 tools/python/xen/xend/XendCheckpoint.py |    5 
 tools/python/xen/xend/XendConfig.py     |   35 -
 tools/python/xen/xend/XendDomainInfo.py |   41 -
 tools/python/xen/xend/image.py          |  379 ++++++-----
 tools/python/xen/xend/server/vfbif.py   |  110 ---
 27 files changed, 2165 insertions(+), 2338 deletions(-)

Dan.

Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
#1 lore raw

Re: PATCH: 1/10: Add a QEMU machine type for fullvirt guests

This patch does a (no functional change) re-arrangement of the code for starting up a fully virtualized guest. In particular it creates a new QEMU machine type for Xen fullyvirt guests which can be specified with '-M xenfv'. For compatability this is in fact made to be the default. The code for setting up memory maps is moved out of vl.c, and into hw/xen_machine_fv.c. This is basically to ensure that it can be easily skipped when we add a paravirt machine type in the next patch.

 b/tools/ioemu/hw/xen_machine_fv.c |  286 ++++++++++++++++++++++++++++++++++++++
 tools/ioemu/Makefile.target       |    1 
 tools/ioemu/vl.c                  |  244 --------------------------------
 tools/ioemu/vl.h                  |    3 
 4 files changed, 295 insertions(+), 239 deletions(-)

Dan.

tools/ioemu/Makefile.target +1 -0
diff -r 7953164cebb6 tools/ioemu/Makefile.target
@@ -400,6 +400,7 @@ VL_OBJS+= piix4acpi.o
 VL_OBJS+= piix4acpi.o
 VL_OBJS+= xenstore.o
 VL_OBJS+= xen_platform.o
+VL_OBJS+= xen_machine_fv.o
 VL_OBJS+= tpm_tis.o
 CPPFLAGS += -DHAS_AUDIO
 endif
tools/ioemu/hw/xen_machine_fv.c new file +286 -0

286 lines not on this page · raw message

tools/ioemu/vl.c +5 -239

288 lines not on this page · raw message

tools/ioemu/vl.h +3 -0
diff -r 7953164cebb6 tools/ioemu/vl.h
@@ -1118,6 +1118,9 @@ extern void pci_piix4_acpi_init(PCIBus *
 /* pc.c */
 extern QEMUMachine pc_machine;
 extern QEMUMachine isapc_machine;
+#ifdef CONFIG_DM
+extern QEMUMachine xenfv_machine;
+#endif
 extern int fd_bootchk;
 
 void ioport_set_a20(int enable);
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
#2 lore raw

Re: PATCH: 2/10: Add a QEMU machine type for paravirt guests

In reply to Daniel P. Berrange

This patch adds a paravirt machine type to QEMU. THis can be requested by passing the arg '-M xenpv' to qemu-dm. Aside from -d, and -domain-name, the only other args that are processed are the VNC / SDL graphics related args. Any others will be ignored. A tweak to helper2.c was made to stop it setting up a file handler watch when there are no CPUs registered.

The paravirt machine is in hw/xen_machine_pv.c and registers an instance of the xenfb class, integrating it with the QEMU event loop and key/mouse handlers. A couple of methods were adding to xenfb.h to allow direct access to the file handles for xenstore & the event channel.

The vfbif.py device controller is modified to launch qemu-dm instead of the old xen-vncfb / sdlfb daemons.

When receiving framebuffer updates from the guest, the update has to be copied into QEMU's copy of the framebuffer. This is because QEMU stores the framebuffer in the format that is native to the SDL display, or VNC client. This is not neccessarily the same as the guest framebuffer which is always 32bpp. If there is an exact depth match we use memcpy for speed, but in the non-matching case we have to fallback to slow code to covert pixel formats. It fully supports all features of the paravirt framebuffer including the choice between absolute & relative pointers.

To avoid both moving the xenfb.c and making changes to it in the same patch, this just uses a Makefile hack to link against the xenfb.o from the tools/xenfb/ directory. This will be removed in the following patch.

 b/tools/ioemu/hw/xen_machine_pv.c     |  231 ++++++++++++++++++++++++++++++++++
 tools/ioemu/Makefile.target           |    2 
 tools/ioemu/target-i386-dm/helper2.c  |    5 
 tools/ioemu/vl.c                      |    5 
 tools/ioemu/vl.h                      |    1 
 tools/python/xen/xend/server/vfbif.py |   26 +--
 tools/xenfb/xenfb.c                   |   80 ++++++++---
 tools/xenfb/xenfb.h                   |    4 
 8 files changed, 317 insertions(+), 37 deletions(-)

Dan.

tools/ioemu/Makefile.target +2 -0
diff -r 327024163186 tools/ioemu/Makefile.target
@@ -401,6 +401,8 @@ VL_OBJS+= xenstore.o
 VL_OBJS+= xenstore.o
 VL_OBJS+= xen_platform.o
 VL_OBJS+= xen_machine_fv.o
+VL_OBJS+= xen_machine_pv.o
+VL_OBJS+= ../../xenfb/xenfb.o
 VL_OBJS+= tpm_tis.o
 CPPFLAGS += -DHAS_AUDIO
 endif
tools/ioemu/hw/xen_machine_pv.c new file +231 -0

231 lines not on this page · raw message

tools/ioemu/target-i386-dm/helper2.c +3 -2
diff -r 327024163186 tools/ioemu/target-i386-dm/helper2.c
@@ -616,7 +616,7 @@ int main_loop(void)
     extern int shutdown_requested;
     extern int suspend_requested;
     CPUState *env = cpu_single_env;
-    int evtchn_fd = xc_evtchn_fd(xce_handle);
+    int evtchn_fd = xce_handle == -1 ? -1 : xc_evtchn_fd(xce_handle);
     char qemu_file[PATH_MAX];
     fd_set fds;
 
@@ -624,7 +624,8 @@ int main_loop(void)
 				       cpu_single_env);
     qemu_mod_timer(buffered_io_timer, qemu_get_clock(rt_clock));
 
-    qemu_set_fd_handler(evtchn_fd, cpu_handle_ioreq, NULL, env);
+    if (evtchn_fd != -1)
+        qemu_set_fd_handler(evtchn_fd, cpu_handle_ioreq, NULL, env);
 
     xenstore_record_dm_state("running");
     while (1) {
tools/ioemu/vl.c +3 -2
diff -r 327024163186 tools/ioemu/vl.c
@@ -182,7 +182,7 @@ extern int vcpus;
 
 int xc_handle;
 
-char domain_name[64] = "Xen-HVM-no-name";
+char domain_name[64] = "Xen-no-name";
 extern int domid;
 
 char vncpasswd[64];
@@ -6651,6 +6651,7 @@ void register_machines(void)
     qemu_register_machine(&isapc_machine);
 #else
     qemu_register_machine(&xenfv_machine);
+    qemu_register_machine(&xenpv_machine);
 #endif
 #elif defined(TARGET_PPC)
     qemu_register_machine(&heathrow_machine);
@@ -7370,7 +7371,7 @@ int main(int argc, char **argv)
                 break;
             case QEMU_OPTION_domainname:
                 snprintf(domain_name, sizeof(domain_name),
-                         "Xen-HVM-%s", optarg);
+                         "Xen-%s", optarg);
                 break;
             case QEMU_OPTION_d:
                 domid = atoi(optarg);
tools/ioemu/vl.h +1 -0
diff -r 327024163186 tools/ioemu/vl.h
@@ -1120,6 +1120,7 @@ extern QEMUMachine isapc_machine;
 extern QEMUMachine isapc_machine;
 #ifdef CONFIG_DM
 extern QEMUMachine xenfv_machine;
+extern QEMUMachine xenpv_machine;
 #endif
 extern int fd_bootchk;
 
tools/python/xen/xend/server/vfbif.py +13 -13
diff -r 327024163186 tools/python/xen/xend/server/vfbif.py
@@ -50,8 +50,10 @@ class VfbifController(DevController):
             # is HVM, so qemu-dm will handle the vfb.
             return
         
-        std_args = [ "--domid", "%d" % self.vm.getDomid(),
-                     "--title", self.vm.getName() ]
+        args = [ xen.util.auxbin.pathTo("qemu-dm"),
+                 "-M", "xenpv",
+                 "-d", "%d" % self.vm.getDomid(),
+                 "-domain-name", self.vm.getName() ]
         t = config.get("type", None)
         if t == "vnc":
             passwd = None
@@ -65,15 +67,14 @@ class VfbifController(DevController):
             else:
                 log.debug("No VNC passwd configured for vfb access")
 
-            # Try to start the vnc backend
-            args = [xen.util.auxbin.pathTo("xen-vncfb")]
-            if config.has_key("vncunused"):
-                args += ["--unused"]
-            elif config.has_key("vncdisplay"):
-                args += ["--vncport", "%d" % (5900 + int(config["vncdisplay"]))]
-            vnclisten = config.get("vnclisten",
+            vnclisten = config.get('vnclisten',
                                    xen.xend.XendOptions.instance().get_vnclisten_address())
-            args += [ "--listen", vnclisten ]
+            vncdisplay = config.get('vncdisplay', 0)
+            args += ['-vnc', "%s:%d" % (vnclisten, vncdisplay)]
+
+            if config.get('vncunused', 0):
+                args += ['-vncunused']
+
             if config.has_key("keymap"):
                 args += ["-k", "%s" % config["keymap"]]
             else:
@@ -81,15 +82,14 @@ class VfbifController(DevController):
                 if xoptions.get_keymap():
                     args += ["-k", "%s" % xoptions.get_keymap()]
 
-            spawn_detached(args[0], args + std_args, os.environ)
+            spawn_detached(args[0], args, os.environ)
         elif t == "sdl":
-            args = [xen.util.auxbin.pathTo("xen-sdlfb")]
             env = dict(os.environ)
             if config.has_key("display"):
                 env['DISPLAY'] = config["display"]
             if config.has_key("xauthority"):
                 env['XAUTHORITY'] = config["xauthority"]
-            spawn_detached(args[0], args + std_args, env)
+            spawn_detached(args[0], args, env)
         else:
             raise VmError('Unknown vfb type %s (%s)' % (t, repr(config)))
 
tools/xenfb/xenfb.c +60 -20

106 lines not on this page · raw message

tools/xenfb/xenfb.h +4 -0
diff -r 327024163186 tools/xenfb/xenfb.h
@@ -25,8 +25,12 @@ void xenfb_teardown(struct xenfb *xenfb)
 
 int xenfb_attach_dom(struct xenfb *xenfb, int domid);
 
+int xenfb_dispatch_store(struct xenfb *xenfb_pub);
+int xenfb_dispatch_channel(struct xenfb *xenfb_pub);
 int xenfb_select_fds(struct xenfb *xenfb, fd_set *readfds);
 int xenfb_poll(struct xenfb *xenfb, fd_set *readfds);
+int xenfb_get_store_fd(struct xenfb *xenfb_pub);
+int xenfb_get_channel_fd(struct xenfb *xenfb_pub);
 
 int xenfb_send_key(struct xenfb *xenfb, bool down, int keycode);
 int xenfb_send_motion(struct xenfb *xenfb, int rel_x, int rel_y);
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
#3 lore raw

Re: PATCH: 3/10: Remove standalone xenfb code

In reply to Daniel P. Berrange

This patch removes all trace of the standalone paravirt framebuffer daemon. With this there is no longer any requirement for LibVNCServer. Everything is handled by the QEMU device model. The xenfb.c and xenfb.h files are now moved (without code change) into tools/ioemu/hw/ & the temporary Makefile hack from the previous patch is removed.

 Config.mk                        |    1 
 a/tools/check/check_libvncserver |   38 -
 a/tools/check/check_sdl          |   27 -
 a/tools/xenfb/Makefile           |   32 -
 a/tools/xenfb/sdlfb.c            |  342 ----------------
 a/tools/xenfb/vncfb.c            |  522 ------------------------
 a/tools/xenfb/xenfb.c            |  825 ---------------------------------------
 a/tools/xenfb/xenfb.h            |   39 -
 b/tools/ioemu/hw/xenfb.c         |  825 +++++++++++++++++++++++++++++++++++++++
 b/tools/ioemu/hw/xenfb.h         |   39 +
 tools/Makefile                   |    1 
 tools/check/Makefile             |    4 
 tools/ioemu/Makefile.target      |    2 
 tools/ioemu/hw/xen_machine_pv.c  |    2 
 14 files changed, 868 insertions(+), 1831 deletions(-)

Dan.

Config.mk +0 -1
diff -r 450e0143acaf Config.mk
@@ -85,7 +85,6 @@ XENSTAT_XENTOP     ?= y
 XENSTAT_XENTOP     ?= y
 VTPM_TOOLS         ?= n
 LIBXENAPI_BINDINGS ?= n
-XENFB_TOOLS        ?= n
 PYTHON_TOOLS       ?= y
 
 -include $(XEN_ROOT)/.config
tools/Makefile +0 -1
diff -r 450e0143acaf tools/Makefile
@@ -19,7 +19,6 @@ SUBDIRS-y += libaio
 SUBDIRS-y += libaio
 SUBDIRS-y += blktap
 SUBDIRS-y += libfsimage
-SUBDIRS-$(XENFB_TOOLS) += xenfb
 SUBDIRS-$(LIBXENAPI_BINDINGS) += libxen
 
 # These don't cross-compile
tools/check/Makefile +2 -2
diff -r 450e0143acaf tools/check/Makefile
@@ -7,7 +7,7 @@ all: build
 # Check this machine is OK for building on.
 .PHONY: build
 build:
-	XENFB_TOOLS=$(XENFB_TOOLS) LIBXENAPI_BINDINGS=$(LIBXENAPI_BINDINGS) ./chk build
+	LIBXENAPI_BINDINGS=$(LIBXENAPI_BINDINGS) ./chk build
 
 # Check this machine is OK for installing on.
 # DO NOT use this check from 'make install' in the parent
@@ -15,7 +15,7 @@ build:
 # copy rather than actually installing.
 .PHONY: install
 install:
-	XENFB_TOOLS=$(XENFB_TOOLS) LIBXENAPI_BINDINGS=$(LIBXENAPI_BINDINGS) ./chk install
+	LIBXENAPI_BINDINGS=$(LIBXENAPI_BINDINGS) ./chk install
 
 .PHONY: clean
 clean:
tools/check/check_libvncserver deleted +0 -38
diff -r 450e0143acaf tools/check/check_libvncserver
@@ -1,38 +0,0 @@
-#!/bin/sh
-# CHECK-BUILD CHECK-INSTALL
-
-if [ ! "$XENFB_TOOLS" = "y" ]
-then
-    echo -n "unused, "
-    exit 0
-fi
-
-RC=0
-
-LIBVNCSERVER_CONFIG="$(which libvncserver-config)"
-tmpfile=$(mktemp)
-
-if test -z ${LIBVNCSERVER_CONFIG}; then 
-    RC=1
-else
-    ${LIBVNCSERVER_CONFIG} --libs 2>&1 > /dev/null
-    RC=$?
-fi
-
-if test $RC -ne 0; then
-    echo "FAILED"
-	echo " *** libvncserver-config is missing. "
-    echo " *** Please install libvncserver."
-elif ! ld $($LIBVNCSERVER_CONFIG --libs) -o $tmpfile >/dev/null 2>&1; then
-    echo "FAILED"
-    echo " *** dependency libraries for libvncserver are missing: "
-    RC=1
-    for i in $(ld $($LIBVNCSERVER_CONFIG --libs) -o $tmpfile 2>&1 >/dev/null); do
-        case $i in
-        -l*) echo lib${i#-l}
-        esac
-    done
-fi
-rm -f $tmpfile
-
-exit $RC
tools/check/check_sdl deleted +0 -27
diff -r 450e0143acaf tools/check/check_sdl
@@ -1,27 +0,0 @@
-#!/bin/sh
-# CHECK-BUILD CHECK-INSTALL
-
-if [ ! "$XENFB_TOOLS" = "y" ]
-then
-    echo -n "unused, "
-    exit 0
-fi
-
-RC=0
-
-SDL_CONFIG="$(which sdl-config)"
-
-if test -z ${SDL_CONFIG}; then 
-    RC=1
-else
-    ${SDL_CONFIG} --libs 2>&1 > /dev/null
-    RC=$?
-fi
-
-if test $RC -ne 0; then
-    echo "FAILED"
-	echo " *** sdl-config is missing. "
-    echo " *** Please install libsdl-dev or sdl."
-fi
-
-exit $RC
tools/ioemu/Makefile.target +1 -1
diff -r 450e0143acaf tools/ioemu/Makefile.target
@@ -402,7 +402,7 @@ VL_OBJS+= xen_platform.o
 VL_OBJS+= xen_platform.o
 VL_OBJS+= xen_machine_fv.o
 VL_OBJS+= xen_machine_pv.o
-VL_OBJS+= ../../xenfb/xenfb.o
+VL_OBJS+= xenfb.o
 VL_OBJS+= tpm_tis.o
 CPPFLAGS += -DHAS_AUDIO
 endif
tools/ioemu/hw/xen_machine_pv.c +1 -1
diff -r 450e0143acaf tools/ioemu/hw/xen_machine_pv.c
@@ -23,7 +23,7 @@
  */
 
 #include "vl.h"
-#include "../../xenfb/xenfb.h"
+#include "xenfb.h"
 #include <linux/input.h>
 
 /* A convenient function for munging pixels between different depths */
tools/ioemu/hw/xenfb.c new file +825 -0

825 lines not on this page · raw message

tools/ioemu/hw/xenfb.h new file +39 -0
diff -r 450e0143acaf tools/ioemu/hw/xenfb.h
@@ -0,0 +1,39 @@
+#ifndef _XENFB_H_
+#define _XENFB_H_
+
+#include <stdbool.h>
+#include <sys/types.h>
+
+struct xenfb
+{
+	void *pixels;
+
+	int row_stride;
+	int depth;
+	int width;
+	int height;
+	int abs_pointer_wanted;
+
+	void *user_data;
+
+	void (*update)(struct xenfb *xenfb, int x, int y, int width, int height);
+};
+
+struct xenfb *xenfb_new(void);
+void xenfb_delete(struct xenfb *xenfb);
+void xenfb_teardown(struct xenfb *xenfb);
+
+int xenfb_attach_dom(struct xenfb *xenfb, int domid);
+
+int xenfb_dispatch_store(struct xenfb *xenfb_pub);
+int xenfb_dispatch_channel(struct xenfb *xenfb_pub);
+int xenfb_select_fds(struct xenfb *xenfb, fd_set *readfds);
+int xenfb_poll(struct xenfb *xenfb, fd_set *readfds);
+int xenfb_get_store_fd(struct xenfb *xenfb_pub);
+int xenfb_get_channel_fd(struct xenfb *xenfb_pub);
+
+int xenfb_send_key(struct xenfb *xenfb, bool down, int keycode);
+int xenfb_send_motion(struct xenfb *xenfb, int rel_x, int rel_y);
+int xenfb_send_position(struct xenfb *xenfb, int abs_x, int abs_y);
+
+#endif
tools/xenfb/Makefile deleted +0 -32
diff -r 450e0143acaf tools/xenfb/Makefile
@@ -1,32 +0,0 @@
-XEN_ROOT=../..
-include $(XEN_ROOT)/tools/Rules.mk
-
-CFLAGS  += -I$(XEN_LIBXC) -I$(XEN_XENSTORE)
-CFLAGS  += -I$(XEN_ROOT)/tools/ioemu
-LDFLAGS += -L$(XEN_LIBXC) -L$(XEN_XENSTORE)
-
-.PHONY: all
-all: build
-
-.PHONY: build
-build:
-	$(MAKE) vncfb sdlfb
-
-install: all
-	$(INSTALL_DIR) $(DESTDIR)/usr/$(LIBDIR)/xen/bin
-	$(INSTALL_PROG) vncfb $(DESTDIR)/usr/$(LIBDIR)/xen/bin/xen-vncfb
-	$(INSTALL_PROG) sdlfb $(DESTDIR)/usr/$(LIBDIR)/xen/bin/xen-sdlfb
-
-sdlfb: sdlfb.o xenfb.o
-
-sdlfb.o: CFLAGS += $(shell sdl-config --cflags)
-sdlfb: LDLIBS += $(shell sdl-config --libs) -lxenctrl -lxenstore
-
-clean:
-	$(RM) *.o *~ vncfb sdlfb
-
-vncfb: vncfb.o xenfb.o
-vncfb.o: CFLAGS += $(shell libvncserver-config --cflags)
-vncfb: LDLIBS += $(shell libvncserver-config --libs) -lxenctrl -lxenstore
-
-sdlfb.o xenfb.o vncfb.o: xenfb.h
tools/xenfb/sdlfb.c deleted +0 -342

342 lines not on this page · raw message

tools/xenfb/vncfb.c deleted +0 -522

522 lines not on this page · raw message

tools/xenfb/xenfb.c deleted +0 -825

825 lines not on this page · raw message

tools/xenfb/xenfb.h deleted +0 -39
diff -r 450e0143acaf tools/xenfb/xenfb.h
@@ -1,39 +0,0 @@
-#ifndef _XENFB_H_
-#define _XENFB_H_
-
-#include <stdbool.h>
-#include <sys/types.h>
-
-struct xenfb
-{
-	void *pixels;
-
-	int row_stride;
-	int depth;
-	int width;
-	int height;
-	int abs_pointer_wanted;
-
-	void *user_data;
-
-	void (*update)(struct xenfb *xenfb, int x, int y, int width, int height);
-};
-
-struct xenfb *xenfb_new(void);
-void xenfb_delete(struct xenfb *xenfb);
-void xenfb_teardown(struct xenfb *xenfb);
-
-int xenfb_attach_dom(struct xenfb *xenfb, int domid);
-
-int xenfb_dispatch_store(struct xenfb *xenfb_pub);
-int xenfb_dispatch_channel(struct xenfb *xenfb_pub);
-int xenfb_select_fds(struct xenfb *xenfb, fd_set *readfds);
-int xenfb_poll(struct xenfb *xenfb, fd_set *readfds);
-int xenfb_get_store_fd(struct xenfb *xenfb_pub);
-int xenfb_get_channel_fd(struct xenfb *xenfb_pub);
-
-int xenfb_send_key(struct xenfb *xenfb, bool down, int keycode);
-int xenfb_send_motion(struct xenfb *xenfb, int rel_x, int rel_y);
-int xenfb_send_position(struct xenfb *xenfb, int abs_x, int abs_y);
-
-#endif
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
#4 lore raw

Re: PATCH: 4/10: Refactor xenfb event handlers

In reply to Daniel P. Berrange

This patch is a simple code re-factoring to move the event loop integration directly into the xenfb.c file. It is to facilitate the patches which follow.

 xen_machine_pv.c |   29 ------
 xenfb.c          |  249 +++++++++++++++++++++++--------------------------------
 xenfb.h          |    7 -
 3 files changed, 106 insertions(+), 179 deletions(-)

Dan.

tools/ioemu/hw/xen_machine_pv.c +0 -29
diff -r bd1bddd42929 tools/ioemu/hw/xen_machine_pv.c
@@ -136,21 +136,6 @@ void xen_pvfb_invalidate(void *opaque)
 /* Screen dump is not used in Xen, so no need to impl this ? */
 void xen_pvfb_screen_dump(void *opaque, const char *name) { }
 
-void xen_pvfb_dispatch_store(void *opaque) {
-    int ret;
-    if ((ret = xenfb_dispatch_store((struct xenfb *)opaque)) < 0) {
-        fprintf(stderr, "Failure while dispatching store: %d\n", ret);
-        exit(1);
-    }
-}
-
-void xen_pvfb_dispatch_channel(void *opaque) {
-    int ret;
-    if ((ret = xenfb_dispatch_channel((struct xenfb *)opaque)) < 0) {
-        fprintf(stderr, "Failure while dispatching store: %d\n", ret);
-        exit(1);
-    }
-}
 
 /* The Xen PV machine currently provides
  *   - a virtual framebuffer
@@ -165,7 +150,6 @@ static void xen_init_pv(uint64_t ram_siz
 {
     struct xenfb *xenfb;
     extern int domid;
-    int fd;
 
     /* Prepare PVFB state */
     xenfb = xenfb_new();
@@ -197,19 +181,6 @@ static void xen_init_pv(uint64_t ram_siz
                                  xenfb->abs_pointer_wanted,
                                  "Xen PVFB Mouse");
 
-    /* Listen for events from xenstore */
-    fd = xenfb_get_store_fd(xenfb);
-    if (qemu_set_fd_handler2(fd, NULL, xen_pvfb_dispatch_store, NULL, xenfb) < 0) {
-        fprintf(stderr, "Could not register event handler (%s)\n",
-                strerror(errno));
-    }
-
-    /* Listen for events from the event channel */
-    fd = xenfb_get_channel_fd(xenfb);
-    if (qemu_set_fd_handler2(fd, NULL, xen_pvfb_dispatch_channel, NULL, xenfb) < 0) {
-        fprintf(stderr, "Could not register event handler (%s)\n",
-                strerror(errno));
-    }
 
     /* Setup QEMU display */
     dpy_resize(ds, xenfb->width, xenfb->height);
tools/ioemu/hw/xenfb.c +106 -143

292 lines not on this page · raw message

tools/ioemu/hw/xenfb.h +0 -7
diff -r bd1bddd42929 tools/ioemu/hw/xenfb.h
@@ -25,13 +25,6 @@ void xenfb_teardown(struct xenfb *xenfb)
 
 int xenfb_attach_dom(struct xenfb *xenfb, int domid);
 
-int xenfb_dispatch_store(struct xenfb *xenfb_pub);
-int xenfb_dispatch_channel(struct xenfb *xenfb_pub);
-int xenfb_select_fds(struct xenfb *xenfb, fd_set *readfds);
-int xenfb_poll(struct xenfb *xenfb, fd_set *readfds);
-int xenfb_get_store_fd(struct xenfb *xenfb_pub);
-int xenfb_get_channel_fd(struct xenfb *xenfb_pub);
-
 int xenfb_send_key(struct xenfb *xenfb, bool down, int keycode);
 int xenfb_send_motion(struct xenfb *xenfb, int rel_x, int rel_y);
 int xenfb_send_position(struct xenfb *xenfb, int abs_x, int abs_y);
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
#5 lore raw

Re: PATCH: 5/10: Refactor QEMU console integration

In reply to Daniel P. Berrange

This patch moves a bunch of code out of the xen_machine_pv.c file and into the xenfb.c file. This is simply a re-factoring to facilitate the two patches which follow.

 xen_machine_pv.c |  132 ----------------------------
 xenfb.c          |  254 +++++++++++++++++++++++++++++++++++++++++--------------
 xenfb.h          |    8 -
 3 files changed, 195 insertions(+), 199 deletions(-)

Dan.

tools/ioemu/hw/xen_machine_pv.c +1 -131
diff -r c2aa6c7965a3 tools/ioemu/hw/xen_machine_pv.c
@@ -24,117 +24,6 @@
 
 #include "vl.h"
 #include "xenfb.h"
-#include <linux/input.h>
-
-/* A convenient function for munging pixels between different depths */
-#define BLT(SRC_T,DST_T,RLS,GLS,BLS,RRS,GRS,BRS,RM,GM,BM)               \
-    for (line = y ; line < h ; line++) {                                \
-        SRC_T *src = (SRC_T *)(xenfb->pixels + (line*xenfb->row_stride) + (x*xenfb->depth/8)); \
-        DST_T *dst = (DST_T *)(ds->data + (line*ds->linesize) + (x*ds->depth/8)); \
-        int col;                                                        \
-        for (col = x ; col < w ; col++) {                               \
-            *dst = (((*src >> RRS)&RM) << RLS) |                        \
-                (((*src >> GRS)&GM) << GLS) |                           \
-                (((*src >> GRS)&BM) << BLS);                            \
-            src++;                                                      \
-            dst++;                                                      \
-        }                                                               \
-    }
-
-
-/* This copies data from the guest framebuffer region, into QEMU's copy
- * NB. QEMU's copy is stored in the pixel format of a) the local X server (SDL case)
- * or b) the current VNC client pixel format.
- */
-static void xen_pvfb_guest_copy(struct xenfb *xenfb, int x, int y, int w, int h)
-{
-    DisplayState *ds = (DisplayState *)xenfb->user_data;
-    int line;
-
-    if (xenfb->depth == ds->depth) { /* Perfect match can use fast path */
-        for (line = y ; line < (y+h) ; line++) {
-            memcpy(ds->data + (line * ds->linesize) + (x*ds->depth/8),
-                   xenfb->pixels + (line*xenfb->row_stride) + (x*xenfb->depth/8),
-                   w * xenfb->depth/8);
-        }
-    } else { /* Mismatch requires slow pixel munging */
-        if (xenfb->depth == 8) {
-            /* 8 bit source == r:3 g:3 b:2 */
-            if (ds->depth == 16) {
-                BLT(uint8_t, uint16_t,   5, 2, 0,   11, 5, 0,   7, 7, 3);
-            } else if (ds->depth == 32) {
-                BLT(uint8_t, uint32_t,   5, 2, 0,   16, 8, 0,   7, 7, 3);
-            }
-        } else if (xenfb->depth == 16) {
-            /* 16 bit source == r:5 g:6 b:5 */
-            if (ds->depth == 8) {
-                BLT(uint16_t, uint8_t,    11, 5, 0,   5, 2, 0,    31, 63, 31);
-            } else if (ds->depth == 32) {
-                BLT(uint16_t, uint32_t,   11, 5, 0,   16, 8, 0,   31, 63, 31);
-            }
-        } else if (xenfb->depth == 32) {
-            /* 32 bit source == r:8 g:8 b:8 (padding:8) */
-            if (ds->depth == 8) {
-                BLT(uint32_t, uint8_t,    16, 8, 0,   5, 2, 0,    255, 255, 255);
-            } else if (ds->depth == 16) {
-                BLT(uint32_t, uint16_t,   16, 8, 0,   11, 5, 0,   255, 255, 255);
-            }
-        }
-    }
-    dpy_update(ds, x, y, w, h);
-}
-
-
-/* Send a keypress from the client to the guest OS */
-static void xen_pvfb_put_keycode(void *opaque, int keycode)
-{
-    struct xenfb *xenfb = (struct xenfb*)opaque;
-    xenfb_send_key(xenfb, keycode & 0x80 ? 0 : 1, keycode & 0x7f);
-}
-
-/* Send a mouse event from the client to the guest OS */
-static void xen_pvfb_mouse_event(void *opaque,
-                                 int dx, int dy, int dz, int button_state)
-{
-    static int old_state = 0;
-    int i;
-    struct xenfb *xenfb = (struct xenfb*)opaque;
-    DisplayState *ds = (DisplayState *)xenfb->user_data;
-    if (xenfb->abs_pointer_wanted)
-        xenfb_send_position(xenfb,
-                            dx*ds->width/0x7fff,
-                            dy*ds->height/0x7fff);
-    else
-        xenfb_send_motion(xenfb, dx, dy);
-
-	for (i = 0 ; i < 8 ; i++) {
-		int lastDown = old_state & (1 << i);
-		int down = button_state & (1 << i);
-		if (down == lastDown)
-			continue;
-
-		if (xenfb_send_key(xenfb, down, BTN_LEFT+i) < 0)
-			return;
-	}
-    old_state = button_state;
-}
-
-/* QEMU display state changed, so refresh the framebuffer copy */
-void xen_pvfb_update(void *opaque)
-{
-    struct xenfb *xenfb = (struct xenfb *)opaque;
-    xen_pvfb_guest_copy(xenfb, 0, 0, xenfb->width, xenfb->height);
-}
-
-/* QEMU display state changed, so refresh the framebuffer copy */
-void xen_pvfb_invalidate(void *opaque)
-{
-    struct xenfb *xenfb = (struct xenfb *)opaque;
-    xen_pvfb_guest_copy(xenfb, 0, 0, xenfb->width, xenfb->height);
-}
-
-/* Screen dump is not used in Xen, so no need to impl this ? */
-void xen_pvfb_screen_dump(void *opaque, const char *name) { }
 
 
 /* The Xen PV machine currently provides
@@ -160,30 +49,11 @@ static void xen_init_pv(uint64_t ram_siz
     }
 
     /* Talk to the guest */
-    if (xenfb_attach_dom(xenfb, domid) < 0) {
+    if (xenfb_attach_dom(xenfb, domid, ds) < 0) {
         fprintf(stderr, "Could not connect to domain (%s)\n",
                 strerror(errno));
         exit(1);
     }
-    xenfb->update = xen_pvfb_guest_copy;
-    xenfb->user_data = ds;
-
-    /* Tell QEMU to allocate a graphical console */
-    graphic_console_init(ds,
-                         xen_pvfb_update,
-                         xen_pvfb_invalidate,
-                         xen_pvfb_screen_dump,
-                         xenfb);
-
-    /* Register our keyboard & mouse handlers */
-    qemu_add_kbd_event_handler(xen_pvfb_put_keycode, xenfb);
-    qemu_add_mouse_event_handler(xen_pvfb_mouse_event, xenfb,
-                                 xenfb->abs_pointer_wanted,
-                                 "Xen PVFB Mouse");
-
-
-    /* Setup QEMU display */
-    dpy_resize(ds, xenfb->width, xenfb->height);
 }
 
 QEMUMachine xenpv_machine = {
tools/ioemu/hw/xenfb.c +191 -63

284 lines not on this page · raw message

tools/ioemu/hw/xenfb.h +3 -5
diff -r c2aa6c7965a3 tools/ioemu/hw/xenfb.h
@@ -1,6 +1,7 @@
 #ifndef _XENFB_H_
 #define _XENFB_H_
 
+#include "vl.h"
 #include <stdbool.h>
 #include <sys/types.h>
 
@@ -13,6 +14,7 @@ struct xenfb
 	int width;
 	int height;
 	int abs_pointer_wanted;
+	int button_state;
 
 	void *user_data;
 
@@ -23,10 +25,6 @@ void xenfb_delete(struct xenfb *xenfb);
 void xenfb_delete(struct xenfb *xenfb);
 void xenfb_teardown(struct xenfb *xenfb);
 
-int xenfb_attach_dom(struct xenfb *xenfb, int domid);
-
-int xenfb_send_key(struct xenfb *xenfb, bool down, int keycode);
-int xenfb_send_motion(struct xenfb *xenfb, int rel_x, int rel_y);
-int xenfb_send_position(struct xenfb *xenfb, int abs_x, int abs_y);
+int xenfb_attach_dom(struct xenfb *xenfb, int domid, DisplayState *ds);
 
 #endif
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
#6 lore raw

Re: PATCH: 6/10: Merge private & public xenfb structs

In reply to Daniel P. Berrange

This patch merges the public & private structs from the paravirt FB into a single struct. Since QEMU is the only consumer of this code there is no need for the artifical pub/priv split. Merging the two will make it possible to more tightly integrate with QEMU's event loop and do asynchronous non-blocking negoiation with the frontend devices (see next patch).

 xenfb.c |  273 ++++++++++++++++++++++++++++++++--------------------------------
 xenfb.h |   16 ---
 2 files changed, 139 insertions(+), 150 deletions(-)

Dan.

tools/ioemu/hw/xenfb.c +138 -135
diff -r 231a22d0b7dd tools/ioemu/hw/xenfb.c
@@ -22,6 +22,8 @@
 
 // FIXME defend against malicious frontend?
 
+struct xenfb;
+
 struct xenfb_device {
 	const char *devicetype;
 	char nodename[64];	/* backend xenstore dir */
@@ -30,20 +32,33 @@ struct xenfb_device {
 	enum xenbus_state state; /* backend state */
 	void *page;		/* shared page */
 	evtchn_port_t port;
-	struct xenfb_private *xenfb;
+	struct xenfb *xenfb;
 };
 
-struct xenfb_private {
-	struct xenfb pub;
+struct xenfb_data
+{
+	void *pixels;
+	size_t len;
+
+	int row_stride;
+	int depth;
+	int width;
+	int height;
+	int abs_pointer_wanted;
+};
+
+struct xenfb {
+	DisplayState *ds;
 	int evt_xch;		/* event channel driver handle */
 	int xc;			/* hypervisor interface handle */
 	struct xs_handle *xsh;	/* xs daemon handle */
 	struct xenfb_device fb, kbd;
-	size_t fb_len;		/* size of framebuffer */
+	struct xenfb_data data;
 	char protocol[64];	/* frontend protocol */
+	int button_state;
 };
 
-static void xenfb_detach_dom(struct xenfb_private *);
+static void xenfb_detach_dom(struct xenfb *);
 
 static char *xenfb_path_in_dom(struct xs_handle *xsh,
 			       char *buf, size_t size,
@@ -124,7 +139,7 @@ static int xenfb_xs_printf(struct xs_han
 
 static void xenfb_device_init(struct xenfb_device *dev,
 			      const char *type,
-			      struct xenfb_private *xenfb)
+			      struct xenfb *xenfb)
 {
 	dev->devicetype = type;
 	dev->otherend_id = -1;
@@ -132,19 +147,17 @@ static void xenfb_device_init(struct xen
 	dev->xenfb = xenfb;
 }
 
-int xenfb_device_set_domain(struct xenfb_device *dev, int domid)
-{
-	struct xenfb_private *xenfb = dev->xenfb;
-
+static int xenfb_device_set_domain(struct xenfb_device *dev, int domid)
+{
 	dev->otherend_id = domid;
 
-	if (!xenfb_path_in_dom(xenfb->xsh,
+	if (!xenfb_path_in_dom(dev->xenfb->xsh,
 			       dev->otherend, sizeof(dev->otherend),
 			       domid, "device/%s/0", dev->devicetype)) {
 		errno = ENOENT;
 		return -1;
 	}
-	if (!xenfb_path_in_dom(xenfb->xsh,
+	if (!xenfb_path_in_dom(dev->xenfb->xsh,
 			       dev->nodename, sizeof(dev->nodename),
 			       0, "backend/%s/%d/0", dev->devicetype, domid)) {
 		errno = ENOENT;
@@ -156,8 +169,8 @@ int xenfb_device_set_domain(struct xenfb
 
 struct xenfb *xenfb_new(void)
 {
-	struct xenfb_private *xenfb = malloc(sizeof(*xenfb));
 	int serrno;
+	struct xenfb *xenfb = qemu_malloc(sizeof(struct xenfb));
 
 	if (xenfb == NULL)
 		return NULL;
@@ -179,30 +192,26 @@ struct xenfb *xenfb_new(void)
 	if (!xenfb->xsh)
 		goto fail;
 
-	return &xenfb->pub;
+	return xenfb;
 
  fail:
 	serrno = errno;
-	xenfb_delete(&xenfb->pub);
+	xenfb_delete(xenfb);
 	errno = serrno;
 	return NULL;
 }
 
 /* Remove the backend area in xenbus since the framebuffer really is
    going away. */
-void xenfb_teardown(struct xenfb *xenfb_pub)
-{
-       struct xenfb_private *xenfb = (struct xenfb_private *)xenfb_pub;
-
+void xenfb_teardown(struct xenfb *xenfb)
+{
        xs_rm(xenfb->xsh, XBT_NULL, xenfb->fb.nodename);
        xs_rm(xenfb->xsh, XBT_NULL, xenfb->kbd.nodename);
 }
 
 
-void xenfb_delete(struct xenfb *xenfb_pub)
-{
-	struct xenfb_private *xenfb = (struct xenfb_private *)xenfb_pub;
-
+void xenfb_delete(struct xenfb *xenfb)
+{
 	xenfb_detach_dom(xenfb);
 	if (xenfb->xc >= 0)
 		xc_interface_close(xenfb->xc);
@@ -334,7 +343,7 @@ static void xenfb_copy_mfns(int mode, in
 		dst[i] = (mode == 32) ? src32[i] : src64[i];
 }
 
-static int xenfb_map_fb(struct xenfb_private *xenfb, int domid)
+static int xenfb_map_fb(struct xenfb *xenfb, int domid)
 {
 	struct xenfb_page *page = xenfb->fb.page;
 	int n_fbmfns;
@@ -389,7 +398,7 @@ static int xenfb_map_fb(struct xenfb_pri
 #endif
 	}
 
-	n_fbmfns = (xenfb->fb_len + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;
+	n_fbmfns = (xenfb->data.len + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;
 	n_fbdirs = n_fbmfns * mode / 8;
 	n_fbdirs = (n_fbdirs + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;
 
@@ -412,9 +421,9 @@ static int xenfb_map_fb(struct xenfb_pri
 	xenfb_copy_mfns(mode, n_fbmfns, fbmfns, map);
 	munmap(map, n_fbdirs * XC_PAGE_SIZE);
 
-	xenfb->pub.pixels = xc_map_foreign_batch(xenfb->xc, domid,
+	xenfb->data.pixels = xc_map_foreign_batch(xenfb->xc, domid,
 				PROT_READ | PROT_WRITE, fbmfns, n_fbmfns);
-	if (xenfb->pub.pixels == NULL)
+	if (xenfb->data.pixels == NULL)
 		goto out;
 
 	ret = 0; /* all is fine */
@@ -429,7 +438,7 @@ static int xenfb_map_fb(struct xenfb_pri
 
 static int xenfb_bind(struct xenfb_device *dev)
 {
-	struct xenfb_private *xenfb = dev->xenfb;
+	struct xenfb *xenfb = dev->xenfb;
 	unsigned long mfn;
 	evtchn_port_t evtchn;
 
@@ -512,17 +521,74 @@ static void xenfb_dev_fatal(struct xenfb
 }
 
 
-static void xenfb_detach_dom(struct xenfb_private *xenfb)
+static void xenfb_detach_dom(struct xenfb *xenfb)
 {
 	xenfb_unbind(&xenfb->fb);
 	xenfb_unbind(&xenfb->kbd);
-	if (xenfb->pub.pixels) {
-		munmap(xenfb->pub.pixels, xenfb->fb_len);
-		xenfb->pub.pixels = NULL;
-	}
-}
-
-static void xenfb_on_fb_event(struct xenfb_private *xenfb)
+	if (xenfb->data.pixels) {
+		munmap(xenfb->data.pixels, xenfb->data.len);
+		xenfb->data.pixels = NULL;
+	}
+}
+
+/* A convenient function for munging pixels between different depths */
+#define BLT(SRC_T,DST_T,RLS,GLS,BLS,RRS,GRS,BRS,RM,GM,BM)               \
+	for (line = y ; line < h ; line++) {				\
+		SRC_T *src = (SRC_T *)(xenfb->data.pixels + (line*xenfb->data.row_stride) + (x*xenfb->data.depth/8)); \
+		DST_T *dst = (DST_T *)(xenfb->ds->data + (line*xenfb->ds->linesize) + (x*xenfb->ds->depth/8)); \
+		int col;						\
+		for (col = x ; col < w ; col++) {			\
+			*dst = (((*src >> RRS)&RM) << RLS) |		\
+				(((*src >> GRS)&GM) << GLS) |		\
+				(((*src >> GRS)&BM) << BLS);		\
+			src++;						\
+			dst++;						\
+		}							\
+	}
+
+
+/* This copies data from the guest framebuffer region, into QEMU's copy
+ * NB. QEMU's copy is stored in the pixel format of a) the local X server (SDL case)
+ * or b) the current VNC client pixel format.
+ */
+static void xenfb_guest_copy(struct xenfb *xenfb, int x, int y, int w, int h)
+{
+	int line;
+
+	if (xenfb->data.depth == xenfb->ds->depth) { /* Perfect match can use fast path */
+		for (line = y ; line < (y+h) ; line++) {
+			memcpy(xenfb->ds->data + (line * xenfb->ds->linesize) + (x*xenfb->ds->depth/8),
+			       xenfb->data.pixels + (line*xenfb->data.row_stride) + (x*xenfb->data.depth/8),
+			       w * xenfb->data.depth/8);
+		}
+	} else { /* Mismatch requires slow pixel munging */
+		if (xenfb->data.depth == 8) {
+			/* 8 bit source == r:3 g:3 b:2 */
+			if (xenfb->ds->depth == 16) {
+				BLT(uint8_t, uint16_t,   5, 2, 0,   11, 5, 0,   7, 7, 3);
+			} else if (xenfb->ds->depth == 32) {
+				BLT(uint8_t, uint32_t,   5, 2, 0,   16, 8, 0,   7, 7, 3);
+			}
+		} else if (xenfb->data.depth == 16) {
+			/* 16 bit source == r:5 g:6 b:5 */
+			if (xenfb->ds->depth == 8) {
+				BLT(uint16_t, uint8_t,    11, 5, 0,   5, 2, 0,    31, 63, 31);
+			} else if (xenfb->ds->depth == 32) {
+				BLT(uint16_t, uint32_t,   11, 5, 0,   16, 8, 0,   31, 63, 31);
+			}
+		} else if (xenfb->data.depth == 32) {
+			/* 32 bit source == r:8 g:8 b:8 (padding:8) */
+			if (xenfb->ds->depth == 8) {
+				BLT(uint32_t, uint8_t,    16, 8, 0,   5, 2, 0,    255, 255, 255);
+			} else if (xenfb->ds->depth == 16) {
+				BLT(uint32_t, uint16_t,   16, 8, 0,   11, 5, 0,   255, 255, 255);
+			}
+		}
+	}
+	dpy_update(xenfb->ds, x, y, w, h);
+}
+
+static void xenfb_on_fb_event(struct xenfb *xenfb)
 {
 	uint32_t prod, cons;
 	struct xenfb_page *page = xenfb->fb.page;
@@ -536,11 +602,10 @@ static void xenfb_on_fb_event(struct xen
 
 		switch (event->type) {
 		case XENFB_TYPE_UPDATE:
-                    if (xenfb->pub.update)
-			xenfb->pub.update(&xenfb->pub,
-					  event->update.x, event->update.y,
-					  event->update.width, event->update.height);
-                    break;
+			xenfb_guest_copy(xenfb,
+					 event->update.x, event->update.y,
+					 event->update.width, event->update.height);
+			break;
 		}
 	}
 	mb();			/* ensure we're done with ring contents */
@@ -548,7 +613,7 @@ static void xenfb_on_fb_event(struct xen
 	xc_evtchn_notify(xenfb->evt_xch, xenfb->fb.port);
 }
 
-static void xenfb_on_kbd_event(struct xenfb_private *xenfb)
+static void xenfb_on_kbd_event(struct xenfb *xenfb)
 {
 	struct xenkbd_page *page = xenfb->kbd.page;
 
@@ -586,7 +651,7 @@ static int xenfb_on_state_change(struct 
 	return 0;
 }
 
-static int xenfb_kbd_event(struct xenfb_private *xenfb,
+static int xenfb_kbd_event(struct xenfb *xenfb,
 			   union xenkbd_in_event *event)
 {
 	uint32_t prod;
@@ -608,9 +673,8 @@ static int xenfb_kbd_event(struct xenfb_
 	return xc_evtchn_notify(xenfb->evt_xch, xenfb->kbd.port);
 }
 
-static int xenfb_send_key(struct xenfb *xenfb_pub, bool down, int keycode)
-{
-	struct xenfb_private *xenfb = (struct xenfb_private *)xenfb_pub;
+static int xenfb_send_key(struct xenfb *xenfb, bool down, int keycode)
+{
 	union xenkbd_in_event event;
 
 	memset(&event, 0, XENKBD_IN_EVENT_SIZE);
@@ -621,9 +685,8 @@ static int xenfb_send_key(struct xenfb *
 	return xenfb_kbd_event(xenfb, &event);
 }
 
-static int xenfb_send_motion(struct xenfb *xenfb_pub, int rel_x, int rel_y)
-{
-	struct xenfb_private *xenfb = (struct xenfb_private *)xenfb_pub;
+static int xenfb_send_motion(struct xenfb *xenfb, int rel_x, int rel_y)
+{
 	union xenkbd_in_event event;
 
 	memset(&event, 0, XENKBD_IN_EVENT_SIZE);
@@ -634,9 +697,8 @@ static int xenfb_send_motion(struct xenf
 	return xenfb_kbd_event(xenfb, &event);
 }
 
-static int xenfb_send_position(struct xenfb *xenfb_pub, int abs_x, int abs_y)
-{
-	struct xenfb_private *xenfb = (struct xenfb_private *)xenfb_pub;
+static int xenfb_send_position(struct xenfb *xenfb, int abs_x, int abs_y)
+{
 	union xenkbd_in_event event;
 
 	memset(&event, 0, XENKBD_IN_EVENT_SIZE);
@@ -660,11 +722,11 @@ static void xenfb_mouse_event(void *opaq
 {
 	int i;
 	struct xenfb *xenfb = (struct xenfb*)opaque;
-	DisplayState *ds = (DisplayState *)xenfb->user_data;
-	if (xenfb->abs_pointer_wanted)
+
+	if (xenfb->data.abs_pointer_wanted)
 		xenfb_send_position(xenfb,
-				    dx*ds->width/0x7fff,
-				    dy*ds->height/0x7fff);
+				    dx*xenfb->ds->width/0x7fff,
+				    dy*xenfb->ds->height/0x7fff);
 	else
 		xenfb_send_motion(xenfb, dx, dy);
 
@@ -680,76 +742,19 @@ static void xenfb_mouse_event(void *opaq
 	xenfb->button_state = button_state;
 }
 
-/* A convenient function for munging pixels between different depths */
-#define BLT(SRC_T,DST_T,RLS,GLS,BLS,RRS,GRS,BRS,RM,GM,BM)               \
-	for (line = y ; line < h ; line++) {				\
-		SRC_T *src = (SRC_T *)(xenfb->pixels + (line*xenfb->row_stride) + (x*xenfb->depth/8)); \
-		DST_T *dst = (DST_T *)(ds->data + (line*ds->linesize) + (x*ds->depth/8)); \
-		int col;						\
-		for (col = x ; col < w ; col++) {			\
-			*dst = (((*src >> RRS)&RM) << RLS) |		\
-				(((*src >> GRS)&GM) << GLS) |		\
-				(((*src >> GRS)&BM) << BLS);		\
-			src++;						\
-			dst++;						\
-		}							\
-	}
-
-
-/* This copies data from the guest framebuffer region, into QEMU's copy
- * NB. QEMU's copy is stored in the pixel format of a) the local X server (SDL case)
- * or b) the current VNC client pixel format.
- */
-static void xenfb_guest_copy(struct xenfb *xenfb, int x, int y, int w, int h)
-{
-	DisplayState *ds = (DisplayState *)xenfb->user_data;
-	int line;
-
-	if (xenfb->depth == ds->depth) { /* Perfect match can use fast path */
-		for (line = y ; line < (y+h) ; line++) {
-			memcpy(ds->data + (line * ds->linesize) + (x*ds->depth/8),
-			       xenfb->pixels + (line*xenfb->row_stride) + (x*xenfb->depth/8),
-			       w * xenfb->depth/8);
-		}
-	} else { /* Mismatch requires slow pixel munging */
-		if (xenfb->depth == 8) {
-			/* 8 bit source == r:3 g:3 b:2 */
-			if (ds->depth == 16) {
-				BLT(uint8_t, uint16_t,   5, 2, 0,   11, 5, 0,   7, 7, 3);
-			} else if (ds->depth == 32) {
-				BLT(uint8_t, uint32_t,   5, 2, 0,   16, 8, 0,   7, 7, 3);
-			}
-		} else if (xenfb->depth == 16) {
-			/* 16 bit source == r:5 g:6 b:5 */
-			if (ds->depth == 8) {
-				BLT(uint16_t, uint8_t,    11, 5, 0,   5, 2, 0,    31, 63, 31);
-			} else if (ds->depth == 32) {
-				BLT(uint16_t, uint32_t,   11, 5, 0,   16, 8, 0,   31, 63, 31);
-			}
-		} else if (xenfb->depth == 32) {
-			/* 32 bit source == r:8 g:8 b:8 (padding:8) */
-			if (ds->depth == 8) {
-				BLT(uint32_t, uint8_t,    16, 8, 0,   5, 2, 0,    255, 255, 255);
-			} else if (ds->depth == 16) {
-				BLT(uint32_t, uint16_t,   16, 8, 0,   11, 5, 0,   255, 255, 255);
-			}
-		}
-	}
-	dpy_update(ds, x, y, w, h);
-}
 
 /* QEMU display state changed, so refresh the framebuffer copy */
 static void xenfb_update(void *opaque)
 {
 	struct xenfb *xenfb = (struct xenfb *)opaque;
-	xenfb_guest_copy(xenfb, 0, 0, xenfb->width, xenfb->height);
+	xenfb_guest_copy(xenfb, 0, 0, xenfb->data.width, xenfb->data.height);
 }
 
 /* QEMU display state changed, so refresh the framebuffer copy */
 static void xenfb_invalidate(void *opaque)
 {
 	struct xenfb *xenfb = (struct xenfb *)opaque;
-	xenfb_guest_copy(xenfb, 0, 0, xenfb->width, xenfb->height);
+	xenfb_guest_copy(xenfb, 0, 0, xenfb->data.width, xenfb->data.height);
 }
 
 /* Screen dump is not used in Xen, so no need to impl this ? */
@@ -757,9 +762,9 @@ static void xenfb_screen_dump(void *opaq
 
 
 
-static void xenfb_dispatch_channel(void *xenfb_pub)
-{
-	struct xenfb_private *xenfb = (struct xenfb_private *)xenfb_pub;
+static void xenfb_dispatch_channel(void *opaque)
+{
+	struct xenfb *xenfb = (struct xenfb *)opaque;
 	evtchn_port_t port;
 	port = xc_evtchn_pending(xenfb->evt_xch);
 	if (port == -1)
@@ -774,9 +779,9 @@ static void xenfb_dispatch_channel(void 
 		exit(1);
 }
 
-static void xenfb_dispatch_store(void *xenfb_pub)
-{
-	struct xenfb_private *xenfb = (struct xenfb_private *)xenfb_pub;
+static void xenfb_dispatch_store(void *opaque)
+{
+	struct xenfb *xenfb = (struct xenfb *)opaque;
 	unsigned dummy;
 	char **vec;
 	int r;
@@ -791,9 +796,8 @@ static void xenfb_dispatch_store(void *x
 }
 
 
-int xenfb_attach_dom(struct xenfb *xenfb_pub, int domid, DisplayState *ds)
-{
-	struct xenfb_private *xenfb = (struct xenfb_private *)xenfb_pub;
+int xenfb_attach_dom(struct xenfb *xenfb, int domid, DisplayState *ds)
+{
 	struct xs_handle *xsh = xenfb->xsh;
 	int val, serrno;
 	struct xenfb_page *fb_page;
@@ -849,12 +853,12 @@ int xenfb_attach_dom(struct xenfb *xenfb
 
 	/* TODO check for permitted ranges */
 	fb_page = xenfb->fb.page;
-	xenfb->pub.depth = fb_page->depth;
-	xenfb->pub.width = fb_page->width;
-	xenfb->pub.height = fb_page->height;
+	xenfb->data.depth = fb_page->depth;
+	xenfb->data.width = fb_page->width;
+	xenfb->data.height = fb_page->height;
 	/* TODO check for consistency with the above */
-	xenfb->fb_len = fb_page->mem_length;
-	xenfb->pub.row_stride = fb_page->line_length;
+	xenfb->data.len = fb_page->mem_length;
+	xenfb->data.row_stride = fb_page->line_length;
 
 	if (xenfb_map_fb(xenfb, domid) < 0)
 		goto error;
@@ -869,7 +873,7 @@ int xenfb_attach_dom(struct xenfb *xenfb
 	if (xenfb_xs_scanf1(xsh, xenfb->kbd.otherend, "request-abs-pointer",
 			    "%d", &val) < 0)
 		val = 0;
-	xenfb->pub.abs_pointer_wanted = val;
+	xenfb->data.abs_pointer_wanted = val;
 
 	/* Listen for events from xenstore */
 	if (qemu_set_fd_handler2(xs_fileno(xenfb->xsh), NULL, xenfb_dispatch_store, NULL, xenfb) < 0)
@@ -882,19 +886,18 @@ int xenfb_attach_dom(struct xenfb *xenfb
 	/* Register our keyboard & mouse handlers */
 	qemu_add_kbd_event_handler(xenfb_put_keycode, xenfb);
 	qemu_add_mouse_event_handler(xenfb_mouse_event, xenfb,
-				     xenfb_pub->abs_pointer_wanted,
+				     xenfb->data.abs_pointer_wanted,
 				     "Xen PVFB Mouse");
 
-	xenfb_pub->update = xenfb_guest_copy;
-	xenfb_pub->user_data = ds;
+	xenfb->ds = ds;
 
 	/* Tell QEMU to allocate a graphical console */
 	graphic_console_init(ds,
 			     xenfb_update,
 			     xenfb_invalidate,
 			     xenfb_screen_dump,
-			     xenfb_pub);
-	dpy_resize(ds, xenfb_pub->width, xenfb_pub->height);
+			     xenfb);
+	dpy_resize(ds, xenfb->data.width, xenfb->data.height);
 
 	return 0;
 
tools/ioemu/hw/xenfb.h +1 -15
diff -r 231a22d0b7dd tools/ioemu/hw/xenfb.h
@@ -5,21 +5,7 @@
 #include <stdbool.h>
 #include <sys/types.h>
 
-struct xenfb
-{
-	void *pixels;
-
-	int row_stride;
-	int depth;
-	int width;
-	int height;
-	int abs_pointer_wanted;
-	int button_state;
-
-	void *user_data;
-
-	void (*update)(struct xenfb *xenfb, int x, int y, int width, int height);
-};
+struct xenfb;
 
 struct xenfb *xenfb_new(void);
 void xenfb_delete(struct xenfb *xenfb);
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
#7 lore raw

Re: PATCH: 7/10: Async negotiation with xenfb frontend

In reply to Daniel P. Berrange

This patch re-factors the paravirt console xenfb_attach_dom method. The original method blocks the caller until the front & backends have both switched to the connected state. This isn't an immediate problem, but patches which follow will extend qemu to also handle the text console so blocking on graphics console startup will block the text console processing.

The new code is basically a state machine. It starts off with a watch waiting for the KBD backend to switch to 'initialized' mode, then does the same for the FB backend. Now it waits for KBD & FB frontend devices to initialize, reading & mapping the framebuffer & its config at the appropriate step. When the KBD frontend finally reaches the connected state it registers a graphical console with QEMU and sets up the various framebuffer, mouse & keyboard event handlers. If a client connects to the VNC server before this is completed, then they will merely see a text console (or perhaps the monitor if configured that way).

 xen_machine_pv.c |    9 
 xenfb.c          |  752 ++++++++++++++++++++++++++++++++-----------------------
 xenfb.h          |    7 
 3 files changed, 445 insertions(+), 323 deletions(-)

Dan.

tools/ioemu/hw/xen_machine_pv.c +1 -8
diff -r 829464d36542 tools/ioemu/hw/xen_machine_pv.c
@@ -41,16 +41,9 @@ static void xen_init_pv(uint64_t ram_siz
     extern int domid;
 
     /* Prepare PVFB state */
-    xenfb = xenfb_new();
+    xenfb = xenfb_new(domid, ds);
     if (xenfb == NULL) {
         fprintf(stderr, "Could not create framebuffer (%s)\n",
-                strerror(errno));
-        exit(1);
-    }
-
-    /* Talk to the guest */
-    if (xenfb_attach_dom(xenfb, domid, ds) < 0) {
-        fprintf(stderr, "Could not connect to domain (%s)\n",
                 strerror(errno));
         exit(1);
     }
tools/ioemu/hw/xenfb.c +442 -310

846 lines not on this page · raw message

tools/ioemu/hw/xenfb.h +2 -5
diff -r 829464d36542 tools/ioemu/hw/xenfb.h
@@ -7,10 +7,7 @@
 
 struct xenfb;
 
-struct xenfb *xenfb_new(void);
-void xenfb_delete(struct xenfb *xenfb);
-void xenfb_teardown(struct xenfb *xenfb);
-
-int xenfb_attach_dom(struct xenfb *xenfb, int domid, DisplayState *ds);
+struct xenfb *xenfb_new(int domid, DisplayState *ds);
+void xenfb_shutdown(struct xenfb *xenfb);
 
 #endif
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
#8 lore raw

Re: PATCH: 8/10: Add pv console to QEMU paravirt machine

In reply to Daniel P. Berrange

This patch adds a paravirt console driver to qemu-dm. This is used when the QEMU machine type is 'xenpv', connecting to the ring buffer provided by the guest kernel. The '-serial' command line flag controls how the guest console is exposed.

For parity with xenconsoled the '-serial pty' arg can be used. For guests which are running a qemu-dm device model, the xenconsoled daemon is no longer needed for guest consoles. The code for the xen_console.c is based on the original code in tools/console/daemon/io.c, but simplified; since its only dealing with a single guest there's no state tracking to worry about.

 b/tools/ioemu/hw/xen_console.c  |  424 ++++++++++++++++++++++++++++++++++++++++
 b/tools/ioemu/hw/xen_console.h  |   25 ++
 tools/ioemu/Makefile.target     |    1 
 tools/ioemu/hw/xen_machine_pv.c |    9 
 tools/ioemu/xenstore.c          |    2 
 5 files changed, 460 insertions(+), 1 deletion(-)

Dan.

tools/ioemu/Makefile.target +1 -0
diff -r fb720737dddb tools/ioemu/Makefile.target
@@ -403,6 +403,7 @@ VL_OBJS+= xen_machine_fv.o
 VL_OBJS+= xen_machine_fv.o
 VL_OBJS+= xen_machine_pv.o
 VL_OBJS+= xenfb.o
+VL_OBJS+= xen_console.o
 VL_OBJS+= tpm_tis.o
 CPPFLAGS += -DHAS_AUDIO
 endif
tools/ioemu/hw/xen_console.c new file +424 -0

424 lines not on this page · raw message

tools/ioemu/hw/xen_console.h new file +25 -0
diff -r fb720737dddb tools/ioemu/hw/xen_console.h
@@ -0,0 +1,25 @@
+/*
+ *  Copyright (C) International Business Machines  Corp., 2005
+ *  Author(s): Anthony Liguori <[email protected]>
+ *
+ *  Copyright (C) Red Hat 2007
+ *
+ *  Xen Console
+ *
+ *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "vl.h"
+
+extern int xencons_init(int domid, CharDriverState *chr);
tools/ioemu/hw/xen_machine_pv.c +9 -0
diff -r fb720737dddb tools/ioemu/hw/xen_machine_pv.c
@@ -23,6 +23,7 @@
  */
 
 #include "vl.h"
+#include "xen_console.h"
 #include "xenfb.h"
 
 
@@ -39,6 +40,14 @@ static void xen_init_pv(uint64_t ram_siz
 {
     struct xenfb *xenfb;
     extern int domid;
+
+    /* Connect to text console */
+    if (serial_hds[0]) {
+        if (xencons_init(domid, serial_hds[0]) < 0) {
+            fprintf(stderr, "Could not connect to domain console\n");
+            exit(1);
+        }
+    }
 
     /* Prepare PVFB state */
     xenfb = xenfb_new(domid, ds);
tools/ioemu/xenstore.c +1 -1
diff -r fb720737dddb tools/ioemu/xenstore.c
@@ -17,7 +17,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
-static struct xs_handle *xsh = NULL;
+struct xs_handle *xsh = NULL;
 static char *media_filename[MAX_DISKS + MAX_SCSI_DISKS];
 static QEMUTimer *insert_timer = NULL;
 
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
#9 lore raw

Re: PATCH: 9/10: XenD device model re-factoring

In reply to Daniel P. Berrange

This patches adapts XenD so that it is capable of starting a qemu-dm device model for both paravirt and fullyvirt guests. A paravirt guest will only be given a device model if it has a VFB configured, or the user explicitly include the device_model option in the config config. This avoids unneccessary overhead for those wanting a minimal paravirt guest.

The bulk of this patch involves moving code from the HVMImageHandler into the base ImageHandler class. The HVMImageHandler and LinuxImageHandler subclasses now merely containing a couple of overrides to set some specific command line flags. The most important is -M xenpv, vs -M xenfv.

The XenConfig class has a minor refactoring to add a has_rfb() method to avoid duplicating code in a couple of places. Instead of hardcoding DEFAULT_DM it now uses the xen.util.auxbin APIs to locate it - this works on platforms where qemu-dm is in /usr/lib64 instead of /usr/lib. As before paravirt only gets a default qemu-dm if using a VFB

The vfbif.py class is trimmed out since it no longer needs to spawn a daemon. A few other misc fixes deal with qemu-dm interactions when saving/restoring, and in particular recovering from save failures (or checkpointing).

 XendCheckpoint.py |    5 
 XendConfig.py     |   35 ++--
 XendDomainInfo.py |   34 ++--
 image.py          |  379 ++++++++++++++++++++++++++++--------------------------
 server/vfbif.py   |  110 ++-------------
 5 files changed, 254 insertions(+), 309 deletions(-)

Dan.

tools/python/xen/xend/XendCheckpoint.py +4 -1
diff -r 912986c9283d tools/python/xen/xend/XendCheckpoint.py
@@ -6,6 +6,7 @@
 # this archive for more details.
 
 import os
+import os.path
 import re
 import string
 import threading
@@ -105,7 +106,7 @@ def save(fd, dominfo, network, live, dst
         forkHelper(cmd, fd, saveInputHandler, False)
 
         # put qemu device model state
-        if hvm:
+        if os.path.exists("/var/lib/xen/qemu-save.%d" % dominfo.getDomid()):
             write_exact(fd, QEMU_SIGNATURE, "could not write qemu signature")
             qemu_fd = os.open("/var/lib/xen/qemu-save.%d" % dominfo.getDomid(),
                               os.O_RDONLY)
@@ -231,6 +232,8 @@ def restore(xd, fd, dominfo = None, paus
             raise XendError('Could not read console MFN')        
 
         # get qemu state and create a tmp file for dm restore
+        # Even PV guests may have QEMU stat, but its not currently
+        # used so only bother with HVM currently.
         if is_hvm:
             qemu_signature = read_exact(fd, len(QEMU_SIGNATURE),
                                         "invalid device model signature read")
tools/python/xen/xend/XendConfig.py +17 -18
diff -r 912986c9283d tools/python/xen/xend/XendConfig.py
@@ -32,6 +32,7 @@ from xen.util.blkif import blkdev_name_t
 from xen.util.blkif import blkdev_name_to_number
 from xen.xend.XendXSPolicyAdmin import XSPolicyAdminInstance
 from xen.util import xsconstants
+import xen.util.auxbin
 
 log = logging.getLogger("xend.XendConfig")
 log.setLevel(logging.WARN)
@@ -236,8 +237,6 @@ LEGACY_XENSTORE_VM_PARAMS = [
     'on_xend_start',
     'on_xend_stop',
 ]
-
-DEFAULT_DM = '/usr/lib/xen/bin/qemu-dm'
 
 ##
 ## Config Choices
@@ -398,13 +397,14 @@ class XendConfig(dict):
             self['name_label'] = 'Domain-' + self['uuid']
 
     def _platform_sanity_check(self):
+        if 'keymap' not in self['platform'] and XendOptions.instance().get_keymap():
+            self['platform']['keymap'] = XendOptions.instance().get_keymap()
+
+        if self.is_hvm() or self.has_rfb():
+            if 'device_model' not in self['platform']:
+                self['platform']['device_model'] = xen.util.auxbin.pathTo("qemu-dm")
+
         if self.is_hvm():
-            if 'keymap' not in self['platform'] and XendOptions.instance().get_keymap():
-                self['platform']['keymap'] = XendOptions.instance().get_keymap()
-
-            if 'device_model' not in self['platform']:
-                self['platform']['device_model'] = DEFAULT_DM
-
             # Compatibility hack, can go away soon.
             if 'soundhw' not in self['platform'] and \
                self['platform'].get('enable_audio'):
@@ -740,16 +740,7 @@ class XendConfig(dict):
         # coalesce hvm vnc frame buffer with vfb config
         if self.is_hvm() and int(self['platform'].get('vnc', 0)) != 0:
             # add vfb device if it isn't there already
-            has_rfb = False
-            for console_uuid in self['console_refs']:
-                if self['devices'][console_uuid][1].get('protocol') == 'rfb':
-                    has_rfb = True
-                    break
-                if self['devices'][console_uuid][0] == 'vfb':
-                    has_rfb = True
-                    break
-
-            if not has_rfb:
+            if not self.has_rfb():
                 dev_config = ['vfb']
                 # copy VNC related params from platform config to vfb dev conf
                 for key in ['vncpasswd', 'vncunused', 'vncdisplay',
@@ -759,6 +750,14 @@ class XendConfig(dict):
 
                 self.device_add('vfb', cfg_sxp = dev_config)
 
+
+    def has_rfb(self):
+        for console_uuid in self['console_refs']:
+            if self['devices'][console_uuid][1].get('protocol') == 'rfb':
+                return True
+            if self['devices'][console_uuid][0] == 'vfb':
+                return True
+        return False
 
     def _sxp_to_xapi_unsupported(self, sxp_cfg):
         """Read in an SXP configuration object and populate
tools/python/xen/xend/XendDomainInfo.py +17 -17
diff -r 912986c9283d tools/python/xen/xend/XendDomainInfo.py
@@ -1347,10 +1347,16 @@ class XendDomainInfo:
 
     def _releaseDevices(self, suspend = False):
         """Release all domain's devices.  Nothrow guarantee."""
-        if suspend and self.image:
-            self.image.destroy(suspend)
-            return
-
+        if self.image:
+            try:
+                log.debug("Destroying device model")
+                self.image.destroyDeviceModel()
+            except Exception, e:
+                log.exception("Device model destroy failed %s" % str(e))
+        else:
+            log.debug("No device model")
+
+        log.debug("Releasing devices")
         t = xstransact("%s/device" % self.dompath)
         for devclass in XendDevices.valid_devices():
             for dev in t.list(devclass):
@@ -1360,8 +1366,8 @@ class XendDomainInfo:
                 except:
                     # Log and swallow any exceptions in removal --
                     # there's nothing more we can do.
-                        log.exception("Device release failed: %s; %s; %s",
-                                      self.info['name_label'], devclass, dev)
+                    log.exception("Device release failed: %s; %s; %s",
+                                  self.info['name_label'], devclass, dev)
 
             
 
@@ -1586,11 +1592,6 @@ class XendDomainInfo:
             bootloader_tidy(self)
 
             if self.image:
-                try:
-                    self.image.destroy()
-                except:
-                    log.exception(
-                        "XendDomainInfo.cleanup: image.destroy() failed.")
                 self.image = None
 
             try:
@@ -1638,10 +1639,9 @@ class XendDomainInfo:
         self.console_mfn = console_mfn
 
         self._introduceDomain()
-        if self.info.is_hvm():
-            self.image = image.create(self, self.info)
-            if self.image:
-                self.image.createDeviceModel(True)
+        self.image = image.create(self, self.info)
+        if self.image:
+            self.image.createDeviceModel(True)
         self._storeDomDetails()
         self._registerWatches()
         self.refreshShutdown()
@@ -1758,8 +1758,8 @@ class XendDomainInfo:
             ResumeDomain(self.domid)
         except:
             log.exception("XendDomainInfo.resume: xc.domain_resume failed on domain %s." % (str(self.domid)))
-        if self.is_hvm():
-            self.image.resumeDeviceModel()
+        self.image.resumeDeviceModel()
+        log.debug("XendDomainInfo.resumeDomain: completed")
 
 
     #
tools/python/xen/xend/image.py +199 -180

450 lines not on this page · raw message

tools/python/xen/xend/server/vfbif.py +17 -93

138 lines not on this page · raw message

Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
#10 lore raw

Re: PATCH: 10/10: Make xenconsoled ignore doms with qemu-dm

In reply to Daniel P. Berrange

This patch writes a field /local/vm/DOMID/console/type taking the value 'ioemu' or 'xenconsoled'. If xenconsoled sees a type that is not its own, then it skips handling of that guest. The qemu-dm process doesn't need to read this field since it will only attach to the console if given the -serial pty arg which XenD already ensures matches this xenstore field.

The overall behaviour is that if a paravirt guest has a qemu-dm process running then that handles the console, otherwise the xenconsoled handles it. The former is more functional, with the exception of not currently supporting persistent logging to a file at the same time as exposing a PTY.

 console/daemon/io.c               |    9 +++++++++
 python/xen/xend/XendDomainInfo.py |    7 +++++++
 2 files changed, 16 insertions(+)

Dan.

tools/console/daemon/io.c +9 -0
diff -r 4559faae3790 tools/console/daemon/io.c
@@ -327,6 +327,7 @@ static int domain_create_ring(struct dom
 static int domain_create_ring(struct domain *dom)
 {
 	int err, remote_port, ring_ref, rc;
+	char *type, path[PATH_MAX];
 
 	err = xs_gather(xs, dom->serialpath,
 			"ring-ref", "%u", &ring_ref,
@@ -343,6 +344,14 @@ static int domain_create_ring(struct dom
 	} else
 		dom->use_consolepath = 0;
 
+	sprintf(path, "%s/type", dom->use_consolepath ? dom->conspath: dom->serialpath);
+	type = xs_read(xs, XBT_NULL, path, NULL);
+	if (type && strcmp(type, "xenconsoled") != 0) {
+		free(type);
+		return 0;
+	}
+	free(type);
+
 	if ((ring_ref == dom->ring_ref) && (remote_port == dom->remote_port))
 		goto out;
 
tools/python/xen/xend/XendDomainInfo.py +7 -0
diff -r 4559faae3790 tools/python/xen/xend/XendDomainInfo.py
@@ -883,8 +883,15 @@ class XendDomainInfo:
                 else:
                     to_store[n] = str(v)
 
+        # Figure out if we need to tell xenconsoled to ignore this guest's
+        # console - device model will handle console if it is running
+        constype = "ioemu"
+        if 'device_model' not in self.info['platform']:
+            constype = "xenconsoled"
+
         f('console/port',     self.console_port)
         f('console/ring-ref', self.console_mfn)
+        f('console/type',     constype)
         f('store/port',       self.store_port)
         f('store/ring-ref',   self.store_mfn)
 
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=|