diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 1753544cd8..32b486b012 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -3251,6 +3251,36 @@ error:
}
+static char *
+qemuBuildVideoDevStr(virDomainVideoDefPtr video)
+{
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+ const char *model = qemuVideoTypeToString(video->type);
+
+ if (!model) {
+ qemuReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("invalid video model"));
+ goto error;
+ }
+
+ virBufferVSprintf(&buf, "%s", model);
+ virBufferVSprintf(&buf, ",id=%s", video->info.alias);
+ if (qemuBuildDeviceAddressStr(&buf, &video->info) < 0)
+ goto error;
+
+ if (virBufferError(&buf)) {
+ virReportOOMError();
+ goto error;
+ }
+
+ return virBufferContentAndReset(&buf);
+
+error:
+ virBufferFreeAndReset(&buf);
+ return NULL;
+}
+
+
int
qemudOpenPCIConfig(virDomainHostdevDefPtr dev)
{
@@ -5171,13 +5201,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
goto error;
}
- if (def->nvideos) {
- if (def->nvideos > 1) {
- qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- "%s", _("only one video card is currently supported"));
- goto error;
- }
-
+ if (def->nvideos > 0) {
if (qemuCmdFlags & QEMUD_CMD_FLAG_VGA) {
if (def->videos[0]->type == VIR_DOMAIN_VIDEO_TYPE_XEN) {
/* nothing - vga has no effect on Xen pvfb */
@@ -5223,6 +5247,32 @@ int qemudBuildCommandLine(virConnectPtr conn,
goto error;
}
}
+
+ if (def->nvideos > 1) {
+ if (qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE) {
+ for (i = 1 ; i < def->nvideos ; i++) {
+ char *str;
+ if (def->videos[i]->type != VIR_DOMAIN_VIDEO_TYPE_QXL) {
+ qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("video type %s is only valid as primary video card"),
+ virDomainVideoTypeToString(def->videos[0]->type));
+ goto error;
+ }
+
+ ADD_ARG_LIT("-device");
+
+ if (!(str = qemuBuildVideoDevStr(def->videos[i])))
+ goto error;
+
+ ADD_ARG(str);
+ }
+ } else {
+ qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ "%s", _("only one video card is currently supported"));
+ goto error;
+ }
+ }
+
} else {
/* If we have -device, then we set -nodefault already */
if (!(qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE) &&
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice.args b/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice.args
index e412fdb196..44809b040d 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 QEMU_AUDIO_DRV=spice /usr/bin/qemu -S -M pc -m 214 -smp 1 -nodefaults -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -usb -spice port=5903,tls-port=5904,addr=127.0.0.1,x509-dir=/etc/pki/libvirt-spice -vga qxl -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=spice /usr/bin/qemu -S -M pc -m 214 -smp 1 -nodefaults -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -usb -spice port=5903,tls-port=5904,addr=127.0.0.1,x509-dir=/etc/pki/libvirt-spice -vga qxl -device qxl,id=video1,bus=pci.0,addr=0x4 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice.xml
index 08dfb264ff..6fe9a60c06 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice.xml
@@ -25,5 +25,8 @@
+