'-device VGA' maps to '-vga std' '-device cirrus-vga' maps to '-vga cirrus' '-device qxl-vga' maps to '-vga qxl' (there is also '-device qxl' for secondary devices) '-device vmware-svga' maps to '-vga vmware' For qemu(>=1.2), we can use -device to replace -vga for video device. For the primary video device, the patch trys to use 0x2 slot for matching old qemu. If the 0x2 slot is allocated already, the addr property could help for using any available slot. For qemu(< 1.2), we keep using -vga for primary device. --- src/qemu/qemu_command.c | 132 ++++++++++++++++++++++++++++++++++++----------- src/qemu/qemu_command.h | 4 +- tests/qemuxml2argvtest.c | 9 ++-- 3 files changed, 110 insertions(+), 35 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 5335dcf..7f1f3ee 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -93,6 +93,16 @@ VIR_ENUM_IMPL(qemuVideo, VIR_DOMAIN_VIDEO_TYPE_LAST, "", /* don't support vbox */ "qxl"); +VIR_ENUM_DECL(qemuDeviceVideo) + +VIR_ENUM_IMPL(qemuDeviceVideo, VIR_DOMAIN_VIDEO_TYPE_LAST, + "VGA", + "cirrus-vga", + "vmware-svga", + "", /* no device for xen */ + "", /* don't support vbox */ + "qxl-vga"); + VIR_ENUM_DECL(qemuSoundCodec) VIR_ENUM_IMPL(qemuSoundCodec, VIR_DOMAIN_SOUND_CODEC_TYPE_LAST, @@ -1057,7 +1067,7 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, if (!(addrs = qemuDomainPCIAddressSetCreate(def))) goto cleanup; - if (qemuAssignDevicePCISlots(def, addrs) < 0) + if (qemuAssignDevicePCISlots(def, caps, addrs) < 0) goto cleanup; } @@ -1415,12 +1425,15 @@ int qemuDomainPCIAddressSetNextAddr(qemuDomainPCIAddressSetPtr addrs, * skip over info.type == PCI */ int -qemuAssignDevicePCISlots(virDomainDefPtr def, qemuDomainPCIAddressSetPtr addrs) +qemuAssignDevicePCISlots(virDomainDefPtr def, + qemuCapsPtr caps, + qemuDomainPCIAddressSetPtr addrs) { size_t i, j; bool reservedIDE = false; bool reservedUSB = false; int function; + bool qemu1dot2plus = qemuCapsGetVersion(caps) >= 1002000; /* Host bridge */ if (qemuDomainPCIAddressReserveSlot(addrs, 0) < 0) @@ -1487,29 +1500,42 @@ qemuAssignDevicePCISlots(virDomainDefPtr def, qemuDomainPCIAddressSetPtr addrs) goto error; } - /* First VGA is hardcoded slot=2 */ if (def->nvideos > 0) { - if (def->videos[0]->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) { - if (def->videos[0]->info.addr.pci.domain != 0 || - def->videos[0]->info.addr.pci.bus != 0 || - def->videos[0]->info.addr.pci.slot != 2 || - def->videos[0]->info.addr.pci.function != 0) { + virDomainVideoDefPtr primaryVideo = def->videos[0]; + if (primaryVideo->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) { + primaryVideo->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; + primaryVideo->info.addr.pci.domain = 0; + primaryVideo->info.addr.pci.bus = 0; + primaryVideo->info.addr.pci.slot = 2; + primaryVideo->info.addr.pci.function = 0; + + if (qemuDomainPCIAddressCheckSlot(addrs, &primaryVideo->info) < 0) { + if (qemu1dot2plus) { + virResetLastError(); + if (qemuDomainPCIAddressSetNextAddr(addrs, &primaryVideo->info) < 0) + goto error; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("PCI address 0:0:2.0 is in use, " + "QEMU needs it for primary video")); + goto error; + } + } else if (qemuDomainPCIAddressReserveSlot(addrs, 2) < 0) { + goto error; + } + } else if (!qemu1dot2plus) { + if (primaryVideo->info.addr.pci.domain != 0 || + primaryVideo->info.addr.pci.bus != 0 || + primaryVideo->info.addr.pci.slot != 2 || + primaryVideo->info.addr.pci.function != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Primary video card must have PCI address 0:0:2.0")); goto error; } /* If TYPE==PCI, then qemuCollectPCIAddress() function * has already reserved the address, so we must skip */ - } else { - def->videos[0]->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; - def->videos[0]->info.addr.pci.domain = 0; - def->videos[0]->info.addr.pci.bus = 0; - def->videos[0]->info.addr.pci.slot = 2; - def->videos[0]->info.addr.pci.function = 0; - if (qemuDomainPCIAddressReserveSlot(addrs, 2) < 0) - goto error; } - } else { + } else if (!qemu1dot2plus) { virDomainDeviceInfo dev; memset(&dev, 0, sizeof(dev)); dev.addr.pci.slot = 2; @@ -1682,8 +1708,13 @@ qemuAssignDevicePCISlots(virDomainDefPtr def, qemuDomainPCIAddressSetPtr addrs) goto error; } - /* Further non-primary video cards */ + /* Further non-primary video cards which have to be qxl type */ for (i = 1; i < def->nvideos ; i++) { + if (def->videos[i]->type != VIR_DOMAIN_VIDEO_TYPE_QXL) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("non-primary video device must be type of 'qxl'")); + goto error; + } if (def->videos[i]->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) continue; if (qemuDomainPCIAddressSetNextAddr(addrs, &def->videos[i]->info) < 0) @@ -3501,16 +3532,35 @@ error: } static char * -qemuBuildVideoDevStr(virDomainVideoDefPtr video, - qemuCapsPtr caps) +qemuBuildDeviceVideoStr(virDomainVideoDefPtr video, + qemuCapsPtr caps, + bool primary) { virBuffer buf = VIR_BUFFER_INITIALIZER; - const char *model = qemuVideoTypeToString(video->type); + const char *model; - if (!model) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("invalid video model")); - goto error; + if (primary) { + model = qemuDeviceVideoTypeToString(video->type); + if (!model || STREQ(model, "")) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("video type %s is not supported with QEMU"), + virDomainVideoTypeToString(video->type)); + goto error; + } + } else { + if (video->type != VIR_DOMAIN_VIDEO_TYPE_QXL) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", _("non-primary video device must be type of 'qxl'")); + goto error; + } + + if (!qemuCapsGet(caps, QEMU_CAPS_DEVICE_QXL)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", _("only one video card is currently supported")); + goto error; + } + + model = "qxl"; } virBufferAsprintf(&buf, "%s,id=%s", model, video->info.alias); @@ -6427,22 +6477,42 @@ qemuBuildCommandLine(virConnectPtr conn, goto error; } if (def->nvideos > 0) { - if (qemuCapsGet(caps, QEMU_CAPS_VGA)) { - if (def->videos[0]->type == VIR_DOMAIN_VIDEO_TYPE_XEN) { + int primaryVideoType = def->videos[0]->type; + if (qemuCapsGetVersion(caps) >= 1002000 && + ((primaryVideoType == VIR_DOMAIN_VIDEO_TYPE_VGA && + qemuCapsGet(caps, QEMU_CAPS_DEVICE_VGA)) || + (primaryVideoType == VIR_DOMAIN_VIDEO_TYPE_CIRRUS && + qemuCapsGet(caps, QEMU_CAPS_DEVICE_CIRRUS_VGA)) || + (primaryVideoType == VIR_DOMAIN_VIDEO_TYPE_VMVGA && + qemuCapsGet(caps, QEMU_CAPS_DEVICE_VMWARE_SVGA)) || + (primaryVideoType == VIR_DOMAIN_VIDEO_TYPE_QXL && + qemuCapsGet(caps, QEMU_CAPS_DEVICE_QXL_VGA))) + ) { + for (i = 0 ; i < def->nvideos ; i++) { + char *str; + virCommandAddArg(cmd, "-device"); + if (!(str = qemuBuildDeviceVideoStr(def->videos[i], caps, !i))) + goto error; + + virCommandAddArg(cmd, str); + VIR_FREE(str); + } + } else if (qemuCapsGet(caps, QEMU_CAPS_VGA)) { + if (primaryVideoType == VIR_DOMAIN_VIDEO_TYPE_XEN) { /* nothing - vga has no effect on Xen pvfb */ } else { - if ((def->videos[0]->type == VIR_DOMAIN_VIDEO_TYPE_QXL) && + if ((primaryVideoType == VIR_DOMAIN_VIDEO_TYPE_QXL) && !qemuCapsGet(caps, QEMU_CAPS_VGA_QXL)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("This QEMU does not support QXL graphics adapters")); goto error; } - const char *vgastr = qemuVideoTypeToString(def->videos[0]->type); + const char *vgastr = qemuVideoTypeToString(primaryVideoType); if (!vgastr || STREQ(vgastr, "")) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("video type %s is not supported with QEMU"), - virDomainVideoTypeToString(def->videos[0]->type)); + virDomainVideoTypeToString(primaryVideoType)); goto error; } @@ -6506,7 +6576,7 @@ qemuBuildCommandLine(virConnectPtr conn, virCommandAddArg(cmd, "-device"); - if (!(str = qemuBuildVideoDevStr(def->videos[i], caps))) + if (!(str = qemuBuildDeviceVideoStr(def->videos[i], caps, false))) goto error; virCommandAddArg(cmd, str); diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 6556e6e..0dde4be 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -211,7 +211,9 @@ int qemuDomainPCIAddressReleaseFunction(qemuDomainPCIAddressSetPtr addrs, int qemuDomainPCIAddressReleaseSlot(qemuDomainPCIAddressSetPtr addrs, int slot); void qemuDomainPCIAddressSetFree(qemuDomainPCIAddressSetPtr addrs); -int qemuAssignDevicePCISlots(virDomainDefPtr def, qemuDomainPCIAddressSetPtr addrs); +int qemuAssignDevicePCISlots(virDomainDefPtr def, + qemuCapsPtr caps, + qemuDomainPCIAddressSetPtr addrs); int qemuAssignDeviceAliases(virDomainDefPtr def, qemuCapsPtr caps); int qemuDomainNetVLAN(virDomainNetDefPtr def); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index bb233ed..ae6c2a8 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -574,7 +574,8 @@ mymain(void) QEMU_CAPS_VGA, QEMU_CAPS_VGA_NONE); DO_TEST("graphics-spice", QEMU_CAPS_VGA, QEMU_CAPS_VGA_QXL, - QEMU_CAPS_DEVICE, QEMU_CAPS_SPICE); + QEMU_CAPS_DEVICE, QEMU_CAPS_SPICE, + QEMU_CAPS_DEVICE_QXL); DO_TEST("graphics-spice-agentmouse", QEMU_CAPS_VGA, QEMU_CAPS_VGA_QXL, QEMU_CAPS_DEVICE, QEMU_CAPS_SPICE, @@ -582,7 +583,8 @@ mymain(void) QEMU_CAPS_NODEFCONFIG); DO_TEST("graphics-spice-compression", QEMU_CAPS_VGA, QEMU_CAPS_VGA_QXL, - QEMU_CAPS_DEVICE, QEMU_CAPS_SPICE); + QEMU_CAPS_DEVICE, QEMU_CAPS_SPICE, + QEMU_CAPS_DEVICE_QXL); DO_TEST("graphics-spice-timeout", QEMU_CAPS_DRIVE, QEMU_CAPS_VGA, QEMU_CAPS_VGA_QXL, @@ -591,7 +593,8 @@ mymain(void) DO_TEST("graphics-spice-qxl-vga", QEMU_CAPS_VGA, QEMU_CAPS_VGA_QXL, QEMU_CAPS_DEVICE, QEMU_CAPS_SPICE, - QEMU_CAPS_DEVICE_QXL_VGA); + QEMU_CAPS_DEVICE_QXL_VGA, + QEMU_CAPS_DEVICE_QXL); DO_TEST("graphics-spice-usb-redir", QEMU_CAPS_VGA, QEMU_CAPS_SPICE, QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG, -- 1.7.11.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list