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

[libvirt] PATCH 2/2: Support <video> element in QEMU driver



This patch extends the QEMU driver to support the <video> element
for configuring the type of video adapter exposed to the guest.

It implements the XML -> ARGV and ARGV -> XML conversions, so both
import & export work. Some of the existing tests are updated to
use the <video> element to get test coverage. The QEMU help parsing
test is changed to use symbolic constants instead of black magic
hex constants. This supports both old -std-vga and new -vga style
QEMU args.

Daniel

From: Daniel P. Berrange <berrange redhat com>
Date: Mon, 6 Jul 2009 14:59:19 +0100
Subject: [PATCH 2/3] Support <video> element for QEMU guests

	* src/qemu_conf.c, src/qemu_conf.h: Use -vga or -std-vga
	when starting guests if video card is present
	* tests/qemuhelptest.c: Change to use constants instead
	of hardcoded hex numbers, and add VGA support
	* tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl-fullscreen.xml,
	tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl.args,
	tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl.xml,
	tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-sasl.args,
	tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-sasl.xml,
	tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-tls.xml,
	tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc.xml,
	tests/qemuxml2argvdata/qemuxml2argv-input-xen.xml: Add <video>
	element for testing graphics adapter
	* tests/qemuxml2argvtest.c: Add QEMUD_CMD_FLAG_VGA flag
	* tests/qemuxml2xmltest.c: Add missing graphics-vnc-sasl/tls tests
---
 src/qemu_conf.c                                    |   89 ++++++++++++++++++++
 src/qemu_conf.h                                    |    1 +
 tests/qemuhelptest.c                               |   66 +++++++++++++-
 .../qemuxml2argv-graphics-sdl-fullscreen.xml       |    3 +
 .../qemuxml2argv-graphics-sdl.args                 |    2 +-
 .../qemuxml2argvdata/qemuxml2argv-graphics-sdl.xml |    3 +
 .../qemuxml2argv-graphics-vnc-sasl.args            |    2 +-
 .../qemuxml2argv-graphics-vnc-sasl.xml             |    3 +
 .../qemuxml2argv-graphics-vnc-tls.xml              |    3 +
 .../qemuxml2argvdata/qemuxml2argv-graphics-vnc.xml |    3 +
 tests/qemuxml2argvdata/qemuxml2argv-input-xen.xml  |    3 +
 tests/qemuxml2argvtest.c                           |    2 +-
 tests/qemuxml2xmltest.c                            |    2 +
 13 files changed, 174 insertions(+), 8 deletions(-)

diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index 9ca60b9..6337045 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -78,6 +78,15 @@ VIR_ENUM_IMPL(qemuDiskCacheV2, VIR_DOMAIN_DISK_CACHE_LAST,
               "writethrough",
               "writeback");
 
+VIR_ENUM_DECL(qemuVideo)
+
+VIR_ENUM_IMPL(qemuVideo, VIR_DOMAIN_VIDEO_TYPE_LAST,
+              "std",
+              "cirrus",
+              "vmware",
+              NULL, /* no arg needed for xen */
+              NULL /* don't support vbox */);
+
 
 int qemudLoadDriverConfig(struct qemud_driver *driver,
                           const char *filename) {
@@ -455,6 +464,8 @@ static unsigned int qemudComputeCmdFlags(const char *help,
         if (strstr(help, "format="))
             flags |= QEMUD_CMD_FLAG_DRIVE_FORMAT;
     }
+    if (strstr(help, "-vga") && !strstr(help, "-std-vga"))
+        flags |= QEMUD_CMD_FLAG_VGA;
     if (strstr(help, "boot=on"))
         flags |= QEMUD_CMD_FLAG_DRIVE_BOOT;
     if (version >= 9000)
@@ -1533,6 +1544,53 @@ int qemudBuildCommandLine(virConnectPtr conn,
             ADD_ARG_LIT("-full-screen");
     }
 
+    if (def->nvideos) {
+        if (def->nvideos > 1) {
+            qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                             "%s", _("only one video card is currentely supported"));
+            goto error;
+        }
+
+        if (qemuCmdFlags & QEMUD_CMD_FLAG_VGA) {
+            if (def->videos[0]->type == VIR_DOMAIN_VIDEO_TYPE_XEN) {
+                /* nothing - vga has no effect on Xen pvfb */
+            } else {
+                const char *vgastr = qemuVideoTypeToString(def->videos[0]->type);
+                if (!vgastr) {
+                    qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                                     _("video type %s is not supported with QEMU"),
+                                     virDomainVideoTypeToString(def->videos[0]->type));
+                    goto error;
+                }
+
+                ADD_ARG_LIT("-vga");
+                ADD_ARG_LIT(vgastr);
+            }
+        } else {
+
+            switch (def->videos[0]->type) {
+            case VIR_DOMAIN_VIDEO_TYPE_VGA:
+                ADD_ARG_LIT("-std-vga");
+                break;
+
+            case VIR_DOMAIN_VIDEO_TYPE_VMVGA:
+                ADD_ARG_LIT("-vmwarevga");
+                break;
+
+            case VIR_DOMAIN_VIDEO_TYPE_XEN:
+            case VIR_DOMAIN_VIDEO_TYPE_CIRRUS:
+                /* No special args - this is the default */
+                break;
+
+            default:
+                qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                                 _("video type %s is not supported with QEMU"),
+                                 virDomainVideoTypeToString(def->videos[0]->type));
+                goto error;
+            }
+        }
+    }
+
     /* Add sound hardware */
     if (def->nsounds) {
         int size = 100;
@@ -2428,6 +2486,7 @@ virDomainDefPtr qemuParseCommandLine(virConnectPtr conn,
     char *path;
     int nnics = 0;
     const char **nics = NULL;
+    int video = VIR_DOMAIN_VIDEO_TYPE_CIRRUS;
 
     if (!progargv[0]) {
         qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
@@ -2805,6 +2864,18 @@ virDomainDefPtr qemuParseCommandLine(virConnectPtr conn,
             def->os.bootloader = strdup(val);
             if (!def->os.bootloader)
                 goto no_memory;
+        } else if (STREQ(arg, "-vmwarevga")) {
+            video = VIR_DOMAIN_VIDEO_TYPE_VMVGA;
+        } else if (STREQ(arg, "-std-vga")) {
+            video = VIR_DOMAIN_VIDEO_TYPE_VGA;
+        } else if (STREQ(arg, "-vga")) {
+            WANT_VALUE();
+            video = qemuVideoTypeFromString(val);
+            if (video < 0) {
+                qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                                 _("unknown video adapter type '%s'"), val);
+                goto error;
+            }
         } else if (STREQ(arg, "-domid")) {
             WANT_VALUE();
             /* ignore, generted on the fly */
@@ -2859,6 +2930,24 @@ virDomainDefPtr qemuParseCommandLine(virConnectPtr conn,
         def->graphics[def->ngraphics++] = sdl;
     }
 
+    if (def->ngraphics) {
+        virDomainVideoDefPtr vid;
+        if (VIR_ALLOC(vid) < 0)
+            goto no_memory;
+        if (def->virtType == VIR_DOMAIN_VIRT_XEN)
+            vid->type = VIR_DOMAIN_VIDEO_TYPE_XEN;
+        else
+            vid->type = video;
+        vid->vram = virDomainVideoDefaultRAM(def, vid->type);
+        vid->heads = 1;
+
+        if (VIR_REALLOC_N(def->videos, def->nvideos+1) < 0) {
+            virDomainVideoDefFree(vid);
+            goto no_memory;
+        }
+        def->videos[def->nvideos++] = vid;
+    }
+
     VIR_FREE(nics);
 
     if (!def->name) {
diff --git a/src/qemu_conf.h b/src/qemu_conf.h
index c0ed46d..9065821 100644
--- a/src/qemu_conf.h
+++ b/src/qemu_conf.h
@@ -57,6 +57,7 @@ enum qemud_cmd_flags {
     QEMUD_CMD_FLAG_DRIVE_CACHE_V2    = (1 << 12), /* Is the cache= flag wanting new v2 values */
     QEMUD_CMD_FLAG_KVM               = (1 << 13), /* Whether KVM is compiled in */
     QEMUD_CMD_FLAG_DRIVE_FORMAT      = (1 << 14), /* Is -drive format= avail */
+    QEMUD_CMD_FLAG_VGA               = (1 << 15), /* Is -vga avail */
 };
 
 /* Main driver state */
diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c
index bf8a293..73eae54 100644
--- a/tests/qemuhelptest.c
+++ b/tests/qemuhelptest.c
@@ -89,11 +89,67 @@ mymain(int argc, char **argv)
             ret = -1;                                                               \
     } while (0)
 
-    DO_TEST("qemu-0.9.1",      0x002f, 9001,  0,  0);
-    DO_TEST("kvm-74",          0x633e, 9001,  1, 74);
-    DO_TEST("qemu-0.10.5",     0x5c6f, 10005, 0,  0);
-    DO_TEST("qemu-kvm-0.10.5", 0x7d7e, 10005, 1,  0);
-    DO_TEST("kvm-86",          0x7d7e, 10050, 1,  0);
+    DO_TEST("qemu-0.9.1",
+            QEMUD_CMD_FLAG_KQEMU |
+            QEMUD_CMD_FLAG_VNC_COLON |
+            QEMUD_CMD_FLAG_NO_REBOOT |
+            QEMUD_CMD_FLAG_DRIVE |
+            QEMUD_CMD_FLAG_NAME,
+            9001,  0,  0);
+    DO_TEST("kvm-74",
+            QEMUD_CMD_FLAG_VNC_COLON |
+            QEMUD_CMD_FLAG_NO_REBOOT |
+            QEMUD_CMD_FLAG_DRIVE |
+            QEMUD_CMD_FLAG_DRIVE_BOOT |
+            QEMUD_CMD_FLAG_NAME |
+            QEMUD_CMD_FLAG_VNET_HDR |
+            QEMUD_CMD_FLAG_MIGRATE_KVM_STDIO |
+            QEMUD_CMD_FLAG_KVM |
+            QEMUD_CMD_FLAG_DRIVE_FORMAT,
+            9001,  1, 74);
+    DO_TEST("qemu-0.10.5",
+            QEMUD_CMD_FLAG_KQEMU |
+            QEMUD_CMD_FLAG_VNC_COLON |
+            QEMUD_CMD_FLAG_NO_REBOOT |
+            QEMUD_CMD_FLAG_DRIVE |
+            QEMUD_CMD_FLAG_NAME |
+            QEMUD_CMD_FLAG_UUID |
+            QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP |
+            QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC |
+            QEMUD_CMD_FLAG_DRIVE_CACHE_V2 |
+            QEMUD_CMD_FLAG_DRIVE_FORMAT |
+            QEMUD_CMD_FLAG_VGA,
+            10005, 0,  0);
+    DO_TEST("qemu-kvm-0.10.5",
+            QEMUD_CMD_FLAG_VNC_COLON |
+            QEMUD_CMD_FLAG_NO_REBOOT |
+            QEMUD_CMD_FLAG_DRIVE |
+            QEMUD_CMD_FLAG_DRIVE_BOOT |
+            QEMUD_CMD_FLAG_NAME |
+            QEMUD_CMD_FLAG_UUID |
+            QEMUD_CMD_FLAG_VNET_HDR |
+            QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP |
+            QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC |
+            QEMUD_CMD_FLAG_DRIVE_CACHE_V2 |
+            QEMUD_CMD_FLAG_KVM |
+            QEMUD_CMD_FLAG_DRIVE_FORMAT |
+            QEMUD_CMD_FLAG_VGA,
+            10005, 1,  0);
+    DO_TEST("kvm-86",
+            QEMUD_CMD_FLAG_VNC_COLON |
+            QEMUD_CMD_FLAG_NO_REBOOT |
+            QEMUD_CMD_FLAG_DRIVE |
+            QEMUD_CMD_FLAG_DRIVE_BOOT |
+            QEMUD_CMD_FLAG_NAME |
+            QEMUD_CMD_FLAG_UUID |
+            QEMUD_CMD_FLAG_VNET_HDR |
+            QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP |
+            QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC |
+            QEMUD_CMD_FLAG_DRIVE_CACHE_V2 |
+            QEMUD_CMD_FLAG_KVM |
+            QEMUD_CMD_FLAG_DRIVE_FORMAT |
+            QEMUD_CMD_FLAG_VGA,
+            10050, 1,  0);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl-fullscreen.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl-fullscreen.xml
index fe1fe1a..f3fc588 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl-fullscreen.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl-fullscreen.xml
@@ -20,5 +20,8 @@
     </disk>
     <input type='mouse' bus='ps2'/>
     <graphics type='sdl' display=':0.1' xauth='/root/.Xauthority' fullscreen='yes'/>
+    <video>
+      <model type='cirrus' vram='9216' heads='1'/>
+    </video>
   </devices>
 </domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl.args b/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl.args
index 3b2b049..f908252 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl.args
@@ -1 +1 @@
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test XAUTHORITY=/root/.Xauthority DISPLAY=:0.1 /usr/bin/qemu -S -M pc -m 214 -smp 1 -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test XAUTHORITY=/root/.Xauthority DISPLAY=:0.1 /usr/bin/qemu -S -M pc -m 214 -smp 1 -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb -std-vga
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl.xml
index 1e04f12..431c3c9 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl.xml
@@ -20,5 +20,8 @@
     </disk>
     <input type='mouse' bus='ps2'/>
     <graphics type='sdl' display=':0.1' xauth='/root/.Xauthority'/>
+    <video>
+      <model type='vga' vram='9216' heads='1'/>
+    </video>
   </devices>
 </domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-sasl.args b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-sasl.args
index a41a57c..bd63540 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-sasl.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-sasl.args
@@ -1 +1 @@
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test SASL_CONF_DIR=/root/.sasl2 /usr/bin/qemu -S -M pc -m 214 -smp 1 -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb -vnc 127.0.0.1:3,sasl
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test SASL_CONF_DIR=/root/.sasl2 /usr/bin/qemu -S -M pc -m 214 -smp 1 -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb -vnc 127.0.0.1:3,sasl -vga cirrus
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-sasl.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-sasl.xml
index cbaa1da..b6f99d3 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-sasl.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-sasl.xml
@@ -20,5 +20,8 @@
     </disk>
     <input type='mouse' bus='ps2'/>
     <graphics type='vnc' port='5903' autoport='no' listen='127.0.0.1'/>
+    <video>
+      <model type='cirrus' vram='9216' heads='1'/>
+    </video>
   </devices>
 </domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-tls.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-tls.xml
index cbaa1da..b6f99d3 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-tls.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-tls.xml
@@ -20,5 +20,8 @@
     </disk>
     <input type='mouse' bus='ps2'/>
     <graphics type='vnc' port='5903' autoport='no' listen='127.0.0.1'/>
+    <video>
+      <model type='cirrus' vram='9216' heads='1'/>
+    </video>
   </devices>
 </domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc.xml
index cbaa1da..b6f99d3 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc.xml
@@ -20,5 +20,8 @@
     </disk>
     <input type='mouse' bus='ps2'/>
     <graphics type='vnc' port='5903' autoport='no' listen='127.0.0.1'/>
+    <video>
+      <model type='cirrus' vram='9216' heads='1'/>
+    </video>
   </devices>
 </domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-input-xen.xml b/tests/qemuxml2argvdata/qemuxml2argv-input-xen.xml
index 1e80317..fea7f8e 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-input-xen.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-input-xen.xml
@@ -20,5 +20,8 @@
     </disk>
     <input type='mouse' bus='xen'/>
     <graphics type='vnc' port='5903' autoport='no' listen='127.0.0.1'/>
+    <video>
+      <model type='xen' vram='4096' heads='1'/>
+    </video>
   </devices>
 </domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 28609eb..2a93018 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -216,7 +216,7 @@ mymain(int argc, char **argv)
 
     driver.vncSASL = 1;
     driver.vncSASLdir = strdup("/root/.sasl2");
-    DO_TEST("graphics-vnc-sasl", 0);
+    DO_TEST("graphics-vnc-sasl", QEMUD_CMD_FLAG_VGA);
     driver.vncTLS = 1;
     driver.vncTLSx509verify = 1;
     driver.vncTLSx509certdir = strdup("/etc/pki/tls/qemu");
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index ab9943d..7db7611 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -102,6 +102,8 @@ mymain(int argc, char **argv)
     DO_TEST("disk-drive-cache-v1-wb");
     DO_TEST("disk-drive-cache-v1-none");
     DO_TEST("graphics-vnc");
+    DO_TEST("graphics-vnc-sasl");
+    DO_TEST("graphics-vnc-tls");
     DO_TEST("graphics-sdl");
     DO_TEST("graphics-sdl-fullscreen");
     DO_TEST("input-usbmouse");
-- 
1.6.2.5


-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


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