[PATCH v2 15/17] qemu: Extend qemuDomainDefaultUSBControllerModel()

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

 



In addition to the code in qemuDomainControllerDefPostParse(),
which we have just factored into its own function, we also have
some code in qemuDomainDefAddDefaultDevices() that deals with
choosing the model for a USB controller, specifically for q35
guests. Integrate it into the newly-created function.

Since we want slightly different behaviors depending on whether
the USB controller that we're working on is the one that we try
to automatically add for certain new guests (addDefaultUSB), we
need to introduce a new parameter to the function.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 src/qemu/qemu_domain.c | 50 ++++++++++++++++++++++++++++--------------
 1 file changed, 33 insertions(+), 17 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index a970bf5c18..6801a883f4 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4159,6 +4159,7 @@ qemuDomainDefaultSCSIControllerModel(virDomainControllerModelSCSI *model,
 
 static int
 qemuDomainDefaultUSBControllerModel(virDomainControllerModelUSB *model,
+                                    bool autoAdded,
                                     const virDomainDef *def,
                                     virQEMUCaps *qemuCaps,
                                     unsigned int parseFlags)
@@ -4195,16 +4196,34 @@ qemuDomainDefaultUSBControllerModel(virDomainControllerModelUSB *model,
             *model = VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI;
     }
 
+    if (ARCH_IS_X86(def->os.arch)) {
+        if (qemuDomainIsQ35(def) && autoAdded) {
+            /* Prefer adding a USB3 controller if supported, fall back
+             * to USB2 if there is no USB3 available, and if that's
+             * unavailable don't add anything.
+             */
+            if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QEMU_XHCI))
+                *model = VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI;
+            else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI))
+                *model = VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI;
+            else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_ICH9_USB_EHCI1))
+                *model = VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_EHCI1;
+            else
+                *model = VIR_DOMAIN_CONTROLLER_MODEL_USB_DEFAULT;
+        }
+    }
+
     return 0;
 }
 
 static int
 qemuDomainDefAddDefaultDevices(virQEMUDriver *driver,
                                virDomainDef *def,
-                               virQEMUCaps *qemuCaps)
+                               virQEMUCaps *qemuCaps,
+                               unsigned int parseFlags)
 {
     bool addDefaultUSB = false;
-    int usbModel = -1; /* "default for machinetype" */
+    virDomainControllerModelUSB usbModel = VIR_DOMAIN_CONTROLLER_MODEL_USB_DEFAULT;
     int pciRoot;       /* index within def->controllers */
     bool addImplicitSATA = false;
     bool addPCIRoot = false;
@@ -4235,19 +4254,6 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver,
             addPCIeRoot = true;
             addImplicitSATA = true;
             addITCOWatchdog = true;
-
-            /* Prefer adding a USB3 controller if supported, fall back
-             * to USB2 if there is no USB3 available, and if that's
-             * unavailable don't add anything.
-             */
-            if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QEMU_XHCI))
-                usbModel = VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI;
-            else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI))
-                usbModel = VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI;
-            else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_ICH9_USB_EHCI1))
-                usbModel = VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_EHCI1;
-            else
-                addDefaultUSB = false;
             break;
         }
         if (qemuDomainIsI440FX(def))
@@ -4340,6 +4346,16 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver,
         break;
     }
 
+    if (addDefaultUSB) {
+        /* If no reasonable model can be figured out, we should
+         * simply not add the default USB controller */
+        if (qemuDomainDefaultUSBControllerModel(&usbModel, true, def, qemuCaps, parseFlags) < 0 ||
+            usbModel == VIR_DOMAIN_CONTROLLER_MODEL_USB_DEFAULT) {
+            addDefaultUSB = false;
+        }
+    }
+
+
     if (addDefaultUSB &&
         virDomainControllerFind(def, VIR_DOMAIN_CONTROLLER_TYPE_USB, 0) < 0 &&
         virDomainDefAddUSBController(def, 0, usbModel) < 0)
@@ -5083,7 +5099,7 @@ qemuDomainDefPostParse(virDomainDef *def,
     if (qemuDomainDefBootPostParse(def, driver, parseFlags) < 0)
         return -1;
 
-    if (qemuDomainDefAddDefaultDevices(driver, def, qemuCaps) < 0)
+    if (qemuDomainDefAddDefaultDevices(driver, def, qemuCaps, parseFlags) < 0)
         return -1;
 
     if (qemuDomainDefSetDefaultCPU(def, driver->hostarch, qemuCaps) < 0)
@@ -5695,7 +5711,7 @@ qemuDomainControllerDefPostParse(virDomainControllerDef *cont,
     case VIR_DOMAIN_CONTROLLER_TYPE_USB:
         if (qemuCaps &&
             cont->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_DEFAULT &&
-            qemuDomainDefaultUSBControllerModel(&cont->model, def, qemuCaps, parseFlags) < 0) {
+            qemuDomainDefaultUSBControllerModel(&cont->model, false, def, qemuCaps, parseFlags) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Unable to determine model for USB controller idx=%1$d"),
                            cont->idx);
-- 
2.43.0
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[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