[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 4/4] Implement RHEL-5.4 KVM support for SPICE graphics



This supports the -spice argument in RHEL-5's fork of KVM
which has SPICE support. There are many more options for
-spice than need to be added - at very least the x509
cert paths should be pulled out of /etc/libvirt/qemu.conf

* src/qemu_conf.c, src/qemu_conf.h: Add SPICE flag. Check for
  -spice availability. Format -spice arg for command line
* qemuhelptest.c: Add SPICE flag
* qemuxml2argvdata/qemuxml2argv-graphics-spice.args: Add <graphics>
  for spice
* qemuxml2argvdata/qemuxml2argv-graphics-spice.xml: Add -spice arg
* qemuxml2argvtest.c: Add SPICE flag
---
 src/qemu/qemu_conf.c                               |   38 ++++++++++++++++++++
 src/qemu/qemu_conf.h                               |    1 +
 tests/qemuhelptest.c                               |    3 +-
 .../qemuxml2argv-graphics-spice.args               |    2 +-
 .../qemuxml2argv-graphics-spice.xml                |    2 +
 tests/qemuxml2argvtest.c                           |    2 +-
 6 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 695ee7c..fea0747 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -865,6 +865,8 @@ static unsigned int qemudComputeCmdFlags(const char *help,
     }
     if (strstr(help, "-vga") && !strstr(help, "-std-vga"))
         flags |= QEMUD_CMD_FLAG_VGA;
+    if (strstr(help, "-spice"))
+        flags |= QEMUD_CMD_FLAG_SPICE;
     if (strstr(help, "-qxl"))
         flags |= QEMUD_CMD_FLAG_QXL;
     if (strstr(help, "boot=on"))
@@ -2163,6 +2165,42 @@ int qemudBuildCommandLine(virConnectPtr conn,
          */
         ADD_ENV_COPY("QEMU_AUDIO_DRV");
         ADD_ENV_COPY("SDL_AUDIODRIVER");
+    } else if ((def->ngraphics == 1) &&
+               def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
+        virBuffer opt = VIR_BUFFER_INITIALIZER;
+        char *optstr;
+
+        if (!(qemuCmdFlags & QEMUD_CMD_FLAG_SPICE)) {
+            qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
+                                 _("spice graphics are not supported with this QEMU"));
+            goto error;
+        }
+
+        virBufferVSprintf(&opt, "port=%u", def->graphics[0]->data.spice.port);
+
+        if (def->graphics[0]->data.spice.tlsPort)
+            virBufferVSprintf(&opt, ",sport=%u", def->graphics[0]->data.spice.tlsPort);
+
+        if (def->graphics[0]->data.spice.listenAddr)
+            virBufferVSprintf(&opt, ",host=%s", def->graphics[0]->data.spice.listenAddr);
+
+        if (virBufferError(&opt))
+            goto no_memory;
+
+        optstr = virBufferContentAndReset(&opt);
+
+        ADD_ARG_LIT("-spice");
+        ADD_ARG(optstr);
+        if (def->graphics[0]->data.spice.keymap) {
+            ADD_ARG_LIT("-k");
+            ADD_ARG_LIT(def->graphics[0]->data.spice.keymap);
+        }
+        /* SPICE includes native support for tunnelling audio, so we
+         * set the audio backend to none, to prevent it opening the
+         * host OS audio devices since that causes security issues
+         * and is non-sensical when using SPICE.
+         */
+        ADD_ENV_LIT("QEMU_AUDIO_DRV=none");
     } else if (def->ngraphics) {
         qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          "%s", _("unsupported graphics output requested"));
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index c8e3276..3866f0e 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -70,6 +70,7 @@ enum qemud_cmd_flags {
     QEMUD_CMD_FLAG_DRIVE_SERIAL  = (1 << 19), /* -driver serial=  available */
     QEMUD_CMD_FLAG_XEN_DOMID     = (1 << 20), /* -xen-domid (new style xen integration) */
     QEMUD_CMD_FLAG_QXL           = (1 << 21), /* Is -qxl avail (RHEL-5/6 custom) */
+    QEMUD_CMD_FLAG_SPICE         = (1 << 22), /* Is -spice avail (RHEL-5/6 custom) */
 };
 
 /* Main driver state */
diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c
index 7fd9e92..980d8bd 100644
--- a/tests/qemuhelptest.c
+++ b/tests/qemuhelptest.c
@@ -193,7 +193,8 @@ mymain(int argc, char **argv)
             QEMUD_CMD_FLAG_KVM |
             QEMUD_CMD_FLAG_DRIVE_FORMAT |
             QEMUD_CMD_FLAG_VGA |
-            QEMUD_CMD_FLAG_QXL,
+            QEMUD_CMD_FLAG_QXL |
+            QEMUD_CMD_FLAG_SPICE,
             9001, 1,  0);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice.args b/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice.args
index d401b85..43516da 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice.args
@@ -1 +1 @@
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb -qxl 3,ram=64
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb -spice port=5903,sport=5904,host=127.0.0.1 -qxl 3,ram=64
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice.xml
index 17f4b20..f985c89 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice.xml
@@ -18,6 +18,8 @@
       <source dev='/dev/HostVG/QEMUGuest1'/>
       <target dev='hda' bus='ide'/>
     </disk>
+    <input type='mouse' bus='ps2'/>
+    <graphics type='spice' port='5903' tlsPort='5904' listen='127.0.0.1'/>
     <video>
       <model type='qxl' vram='65536' heads='3'/>
     </video>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 142ee76..9650900 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -245,7 +245,7 @@ mymain(int argc, char **argv)
     DO_TEST("graphics-sdl", 0);
     DO_TEST("graphics-sdl-fullscreen", 0);
 
-    DO_TEST("graphics-spice", QEMUD_CMD_FLAG_QXL);
+    DO_TEST("graphics-spice", QEMUD_CMD_FLAG_QXL | QEMUD_CMD_FLAG_SPICE);
 
     DO_TEST("input-usbmouse", 0);
     DO_TEST("input-usbtablet", 0);
-- 
1.6.2.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]