]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: domain: Reflect USB controller model in guest XML
authorAndrea Bolognani <abologna@redhat.com>
Thu, 28 Jul 2016 13:33:29 +0000 (15:33 +0200)
committerAndrea Bolognani <abologna@redhat.com>
Fri, 12 Aug 2016 15:38:02 +0000 (17:38 +0200)
When the user doesn't specify any model for a USB controller,
we use an architecture-dependent default, but we don't reflect
it in the guest XML.

Pick the default USB controller model when parsing the guest
XML instead of when creating the QEMU command line, so that
our choice is saved back to disk.

src/qemu/qemu_domain.c
tests/qemuxml2xmloutdata/qemuxml2xmlout-ppc64-usb-controller.xml
tests/qemuxml2xmloutdata/qemuxml2xmlout-usb-controller-default-q35.xml

index efc46f991692a51b2d8a164166cadf0974912322..ec64ae01c71fce71c4c1f69d1f13ff53f84a4f8b 100644 (file)
@@ -2614,6 +2614,26 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
                                virDomainNumaGetNodeCount(def->numa));
                 goto cleanup;
             }
+        } else if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_USB &&
+                   cont->model == -1) {
+            /* Pick a suitable default model for the USB controller if none
+             * has been selected by the user.
+             *
+             * We rely on device availability instead of setting the model
+             * unconditionally because, for some machine types, there's a
+             * chance we will get away with using the legacy USB controller
+             * when the relevant device is not available.
+             *
+             * See qemuBuildControllerDevCommandLine() */
+            if (ARCH_IS_PPC64(def->os.arch)) {
+                /* Default USB controller for ppc64 is pci-ohci */
+                if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_PCI_OHCI))
+                    cont->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_PCI_OHCI;
+            } else {
+                /* Default USB controller for anything else is piix3-uhci */
+                if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_PIIX3_USB_UHCI))
+                    cont->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_PIIX3_UHCI;
+            }
         }
     }
 
index 33e78100721ef56753eb85a729a0018835d5b24a..30932e5afd4cf943f10a14aa24927b753c945103 100644 (file)
@@ -19,7 +19,7 @@
   <on_crash>restart</on_crash>
   <devices>
     <emulator>/usr/libexec/qemu-system-ppc64</emulator>
-    <controller type='usb' index='0'>
+    <controller type='usb' index='0' model='pci-ohci'>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
     </controller>
     <controller type='pci' index='0' model='pci-root'/>
index 8c4f1f5da27acb68b54ac2b322b0820be79c6e49..082a92e452c50d7ba09d6efccd07a5c663bc5394 100644 (file)
@@ -20,7 +20,7 @@
       <target chassisNr='56'/>
       <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
     </controller>
-    <controller type='usb' index='0'>
+    <controller type='usb' index='0' model='piix3-uhci'>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
     </controller>
     <controller type='sata' index='0'>