Move the remainder of the qemuBuildUSBControllerDevStr checks over
to qemuDomainDeviceDefValidateControllerUSB. This also allows the
command code to shorten up a bit and become a void procedure.
This also requires modifying the xml2xml test a bit in order to
include the correct capability bit and modifying the xml2argv test
in order to use the PARSE_ERROR macro.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/qemu/qemu_command.c | 64 +++---------------------------------------------
src/qemu/qemu_command.h | 2 ++
src/qemu/qemu_domain.c | 55 +++++++++++++++++++++++++++++++++++++++--
tests/qemuxml2argvtest.c | 10 ++++----
tests/qemuxml2xmltest.c | 17 ++++++++-----
5 files changed, 74 insertions(+), 74 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 7ea01e008..0d4355abc 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -142,8 +142,6 @@ VIR_ENUM_IMPL(qemuSoundCodec, VIR_DOMAIN_SOUND_CODEC_TYPE_LAST,
"hda-duplex",
"hda-micro");
-VIR_ENUM_DECL(qemuControllerModelUSB)
-
VIR_ENUM_IMPL(qemuControllerModelUSB, VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST,
"piix3-usb-uhci",
"piix4-usb-uhci",
@@ -2503,66 +2501,13 @@ qemuBuildFSDevCommandLine(virCommandPtr cmd,
}
-static int
-qemuControllerModelUSBToCaps(int model)
-{
- switch (model) {
- case VIR_DOMAIN_CONTROLLER_MODEL_USB_PIIX3_UHCI:
- return QEMU_CAPS_PIIX3_USB_UHCI;
- case VIR_DOMAIN_CONTROLLER_MODEL_USB_PIIX4_UHCI:
- return QEMU_CAPS_PIIX4_USB_UHCI;
- case VIR_DOMAIN_CONTROLLER_MODEL_USB_EHCI:
- return QEMU_CAPS_USB_EHCI;
- case VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_EHCI1:
- case VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_UHCI1:
- case VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_UHCI2:
- case VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_UHCI3:
- return QEMU_CAPS_ICH9_USB_EHCI1;
- case VIR_DOMAIN_CONTROLLER_MODEL_USB_VT82C686B_UHCI:
- return QEMU_CAPS_VT82C686B_USB_UHCI;
- case VIR_DOMAIN_CONTROLLER_MODEL_USB_PCI_OHCI:
- return QEMU_CAPS_PCI_OHCI;
- case VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI:
- return QEMU_CAPS_NEC_USB_XHCI;
- case VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI:
- return QEMU_CAPS_DEVICE_QEMU_XHCI;
- default:
- return -1;
- }
-}
-
-
-static int
+static void
qemuBuildUSBControllerDevStr(virDomainControllerDefPtr def,
- virQEMUCapsPtr qemuCaps,
virBuffer *buf)
{
- const char *smodel;
- int model, flags;
-
- model = def->model;
-
- smodel = qemuControllerModelUSBTypeToString(model);
- flags = qemuControllerModelUSBToCaps(model);
-
- if (flags == -1 || !virQEMUCapsGet(qemuCaps, flags)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("%s not supported in this QEMU binary"), smodel);
- return -1;
- }
-
- virBufferAsprintf(buf, "%s", smodel);
+ virBufferAsprintf(buf, "%s",
qemuControllerModelUSBTypeToString(def->model));
if (def->opts.usbopts.ports != -1) {
- if ((model != VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI ||
- !virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI_PORTS)) &&
- model != VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("usb controller type %s doesn't support
'ports' "
- "with this QEMU binary"), smodel);
- return -1;
- }
-
virBufferAsprintf(buf, ",p2=%d,p3=%d",
def->opts.usbopts.ports, def->opts.usbopts.ports);
}
@@ -2572,8 +2517,6 @@ qemuBuildUSBControllerDevStr(virDomainControllerDefPtr def,
def->info.alias, def->info.master.usb.startport);
else
virBufferAsprintf(buf, ",id=%s", def->info.alias);
-
- return 0;
}
@@ -2697,8 +2640,7 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
break;
case VIR_DOMAIN_CONTROLLER_TYPE_USB:
- if (qemuBuildUSBControllerDevStr(def, qemuCaps, &buf) == -1)
- goto error;
+ qemuBuildUSBControllerDevStr(def, &buf);
if (nusbcontroller)
*nusbcontroller += 1;
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index bdde6f918..3551b8cfb 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -43,6 +43,8 @@
VIR_ENUM_DECL(qemuVideo)
+VIR_ENUM_DECL(qemuControllerModelUSB)
+
virCommandPtr qemuBuildCommandLine(virQEMUDriverPtr driver,
virLogManagerPtr logManager,
virDomainObjPtr vm,
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 3ab3aa181..118216d84 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4344,15 +4344,66 @@ qemuDomainDeviceDefValidateControllerSATA(virQEMUCapsPtr
qemuCaps)
}
+static unsigned int
+qemuDomainControllerModelUSBToCaps(int model)
+{
+ switch (model) {
+ case VIR_DOMAIN_CONTROLLER_MODEL_USB_PIIX3_UHCI:
+ return QEMU_CAPS_PIIX3_USB_UHCI;
+ case VIR_DOMAIN_CONTROLLER_MODEL_USB_PIIX4_UHCI:
+ return QEMU_CAPS_PIIX4_USB_UHCI;
+ case VIR_DOMAIN_CONTROLLER_MODEL_USB_EHCI:
+ return QEMU_CAPS_USB_EHCI;
+ case VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_EHCI1:
+ case VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_UHCI1:
+ case VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_UHCI2:
+ case VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_UHCI3:
+ return QEMU_CAPS_ICH9_USB_EHCI1;
+ case VIR_DOMAIN_CONTROLLER_MODEL_USB_VT82C686B_UHCI:
+ return QEMU_CAPS_VT82C686B_USB_UHCI;
+ case VIR_DOMAIN_CONTROLLER_MODEL_USB_PCI_OHCI:
+ return QEMU_CAPS_PCI_OHCI;
+ case VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI:
+ return QEMU_CAPS_NEC_USB_XHCI;
+ case VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI:
+ return QEMU_CAPS_DEVICE_QEMU_XHCI;
+ default:
+ return -1;
+ }
+}
+
+
static int
-qemuDomainDeviceDefValidateControllerUSB(const virDomainControllerDef *controller)
+qemuDomainDeviceDefValidateControllerUSB(const virDomainControllerDef *controller,
+ virQEMUCapsPtr qemuCaps)
{
+ unsigned int flags;
+
if (controller->model == -1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("no model provided for USB controller"));
return -1;
}
+ flags = qemuDomainControllerModelUSBToCaps(controller->model);
+ if (flags == -1 || !virQEMUCapsGet(qemuCaps, flags)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("%s not supported in this QEMU binary"),
+ qemuControllerModelUSBTypeToString(controller->model));
+ return -1;
+ }
+
+ if (controller->opts.usbopts.ports != -1 &&
+ (controller->model != VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI ||
+ !virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI_PORTS)) &&
+ controller->model != VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("usb controller type %s doesn't support 'ports'
"
+ "with this QEMU binary"),
+ qemuControllerModelUSBTypeToString(controller->model));
+ return -1;
+ }
+
return 0;
}
@@ -4394,7 +4445,7 @@ qemuDomainDeviceDefValidateController(const virDomainControllerDef
*controller,
break;
case VIR_DOMAIN_CONTROLLER_TYPE_USB:
- ret = qemuDomainDeviceDefValidateControllerUSB(controller);
+ ret = qemuDomainDeviceDefValidateControllerUSB(controller, qemuCaps);
break;
case VIR_DOMAIN_CONTROLLER_TYPE_FDC:
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 3fcc76baa..439d570d8 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1517,10 +1517,10 @@ mymain(void)
QEMU_CAPS_PCI_OHCI,
QEMU_CAPS_PIIX3_USB_UHCI,
QEMU_CAPS_NEC_USB_XHCI);
- DO_TEST_FAILURE("usb-controller-explicit-unavailable-q35",
- QEMU_CAPS_DEVICE_IOH3420,
- QEMU_CAPS_PCI_OHCI,
- QEMU_CAPS_PIIX3_USB_UHCI);
+ DO_TEST_PARSE_ERROR("usb-controller-explicit-unavailable-q35",
+ QEMU_CAPS_DEVICE_IOH3420,
+ QEMU_CAPS_PCI_OHCI,
+ QEMU_CAPS_PIIX3_USB_UHCI);
DO_TEST("usb-controller-xhci",
QEMU_CAPS_NODEFCONFIG,
QEMU_CAPS_PIIX3_USB_UHCI,
@@ -1538,7 +1538,7 @@ mymain(void)
QEMU_CAPS_NEC_USB_XHCI,
QEMU_CAPS_NEC_USB_XHCI_PORTS);
DO_TEST("usb-controller-qemu-xhci", QEMU_CAPS_DEVICE_QEMU_XHCI);
- DO_TEST_FAILURE("usb-controller-qemu-xhci-unavailable", NONE);
+ DO_TEST_PARSE_ERROR("usb-controller-qemu-xhci-unavailable", NONE);
DO_TEST_PARSE_ERROR("usb-controller-qemu-xhci-limit",
QEMU_CAPS_DEVICE_QEMU_XHCI);
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 790d976f4..d4f599a99 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -678,15 +678,18 @@ mymain(void)
DO_TEST("ppc64-usb-controller-legacy",
QEMU_CAPS_PIIX3_USB_UHCI);
DO_TEST("usb-port-missing", NONE);
- DO_TEST("usb-redir", NONE);
- DO_TEST("usb-redir-filter", NONE);
+ DO_TEST("usb-redir",
+ QEMU_CAPS_ICH9_USB_EHCI1);
+ DO_TEST("usb-redir-filter",
+ QEMU_CAPS_ICH9_USB_EHCI1);
DO_TEST("usb-redir-filter-version", NONE);
DO_TEST("blkdeviotune", NONE);
DO_TEST("blkdeviotune-max", NONE);
DO_TEST("blkdeviotune-group-num", NONE);
DO_TEST("blkdeviotune-max-length", NONE);
- DO_TEST("controller-usb-order", NONE);
-
+ DO_TEST("controller-usb-order",
+ QEMU_CAPS_NEC_USB_XHCI,
+ QEMU_CAPS_ICH9_USB_EHCI1);
DO_TEST_FULL("seclabel-dynamic-baselabel", WHEN_INACTIVE, GIC_NONE, NONE);
DO_TEST_FULL("seclabel-dynamic-override", WHEN_INACTIVE, GIC_NONE, NONE);
DO_TEST_FULL("seclabel-dynamic-labelskip", WHEN_INACTIVE, GIC_NONE, NONE);
@@ -829,7 +832,8 @@ mymain(void)
DO_TEST("numad-auto-vcpu-no-numatune", NONE);
DO_TEST("numad-auto-memory-vcpu-no-cpuset-and-placement", NONE);
DO_TEST("numad-auto-memory-vcpu-cpuset", NONE);
- DO_TEST("usb-ich9-ehci-addr", NONE);
+ DO_TEST("usb-ich9-ehci-addr",
+ QEMU_CAPS_ICH9_USB_EHCI1);
DO_TEST("disk-copy_on_read", NONE);
DO_TEST("tpm-passthrough", NONE);
@@ -1313,7 +1317,8 @@ mymain(void)
DO_TEST("intel-iommu-caching-mode",
QEMU_CAPS_DEVICE_PCI_BRIDGE,
QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE,
- QEMU_CAPS_DEVICE_IOH3420);
+ QEMU_CAPS_DEVICE_IOH3420,
+ QEMU_CAPS_ICH9_USB_EHCI1);
DO_TEST("intel-iommu-eim", NONE);
DO_TEST("intel-iommu-device-iotlb", NONE);
--
2.13.6