[PATCH 088/103] qemuBuildUSBControllerDevStr: Split out validation of USB controller

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

 



Move the validation code into a separate function. For now the
validation is still kept in the commandline format step as simply just
moving it to the validator causes failures in the test suite, which will
need to be investigated deeper.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_command.c                       | 62 ++++++++++---------
 ...sb-controller-explicit-unavailable-q35.err |  2 +-
 .../usb-controller-qemu-xhci-unavailable.err  |  2 +-
 3 files changed, 36 insertions(+), 30 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 68b6bf868e..f7a2304d5c 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2771,6 +2771,38 @@ qemuControllerModelUSBToCaps(int model)
 }


+static int
+qemuValidateDomainDeviceDefControllerUSB(const virDomainControllerDef *def,
+                                         virQEMUCaps *qemuCaps)
+{
+    if (def->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_DEFAULT) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("no model provided for USB controller"));
+        return -1;
+    }
+
+    if (!virQEMUCapsGet(qemuCaps, qemuControllerModelUSBToCaps(def->model))) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("USB controller model '%s' not supported in this QEMU binary"),
+                       virDomainControllerModelUSBTypeToString(def->model));
+        return -1;
+    }
+
+    if (def->opts.usbopts.ports != -1) {
+        if ((def->model != VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI ||
+             !virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI_PORTS)) &&
+            def->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"),
+                           virDomainControllerModelUSBTypeToString(def->model));
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+
 static const char *
 qemuBuildUSBControllerFindMasterAlias(const virDomainDef *domainDef,
                                       const virDomainControllerDef *def)
@@ -2802,38 +2834,12 @@ qemuBuildUSBControllerDevStr(const virDomainDef *domainDef,
                              virQEMUCaps *qemuCaps,
                              virBuffer *buf)
 {
-    const char *smodel;
-    int model, flags;
-
-    model = def->model;
-
-    if (model == VIR_DOMAIN_CONTROLLER_MODEL_USB_DEFAULT) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       "%s", _("no model provided for USB controller"));
-        return -1;
-    }
-
-    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);
+    if (qemuValidateDomainDeviceDefControllerUSB(def, qemuCaps) < 0)
         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);
     }
diff --git a/tests/qemuxml2argvdata/usb-controller-explicit-unavailable-q35.err b/tests/qemuxml2argvdata/usb-controller-explicit-unavailable-q35.err
index 4940f896cc..6907a51505 100644
--- a/tests/qemuxml2argvdata/usb-controller-explicit-unavailable-q35.err
+++ b/tests/qemuxml2argvdata/usb-controller-explicit-unavailable-q35.err
@@ -1 +1 @@
-unsupported configuration: nec-usb-xhci not supported in this QEMU binary
+unsupported configuration: USB controller model 'nec-xhci' not supported in this QEMU binary
diff --git a/tests/qemuxml2argvdata/usb-controller-qemu-xhci-unavailable.err b/tests/qemuxml2argvdata/usb-controller-qemu-xhci-unavailable.err
index 1b797dd343..aec91f7559 100644
--- a/tests/qemuxml2argvdata/usb-controller-qemu-xhci-unavailable.err
+++ b/tests/qemuxml2argvdata/usb-controller-qemu-xhci-unavailable.err
@@ -1 +1 @@
-unsupported configuration: qemu-xhci not supported in this QEMU binary
+unsupported configuration: USB controller model 'qemu-xhci' not supported in this QEMU binary
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux