]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: fix exceptions in qemuAssignDeviceControllerAlias
authorLaine Stump <laine@laine.org>
Tue, 12 May 2015 00:51:52 +0000 (20:51 -0400)
committerLaine Stump <laine@laine.org>
Fri, 15 May 2015 19:36:21 +0000 (15:36 -0400)
There are a few extra exceptions that weren't being accounted for when
creating the alias for a controller. This resulted in 1) incorrect
status XML, and 2) exceptions/printfs of what *should* have been
directly available in the controller alias when constructing device
commandline arguments:

1) The primary (and only) IDE controller on a 440FX machinetype is
hardcoded to be "ide" in qemu.

2) The primary SATA controller on a 440FX machinetype is also
hardcoded to be "ide" in qemu.

3) On machinetypes that don't support multiple PCI buses, the PCI bus
is hardcoded in qemu to have the name "pci".

4) The first usb master controller is "usb", all others are the normal
"usb%d". (note that usb controllers that are not a "master" will have
the same index, and thus alias, as the master).

We needed to pass in the full domainDef and qemuCaps in order to
properly make the decisions about these exceptions.

src/qemu/qemu_command.c
src/qemu/qemu_command.h
src/qemu/qemu_hotplug.c

index 2939f8d7c6e025558836cd320c6b04d80f75812a..603ff126fc48d48c46bc5e0984d582055106e4f0 100644 (file)
@@ -1031,21 +1031,52 @@ qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, virDomainRedirdevDefPtr redir
 
 
 int
-qemuAssignDeviceControllerAlias(virDomainControllerDefPtr controller)
+qemuAssignDeviceControllerAlias(virDomainDefPtr domainDef,
+                                virQEMUCapsPtr qemuCaps,
+                                virDomainControllerDefPtr controller)
 {
     const char *prefix = virDomainControllerTypeToString(controller->type);
 
     if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) {
-        /* only pcie-root uses a different naming convention
-         * ("pcie.0"), because it is hardcoded that way in qemu. All
-         * other buses use the consistent "pci.%u".
-         */
-        if (controller->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT)
+        if (!virQEMUCapsHasPCIMultiBus(qemuCaps, domainDef)) {
+            /* qemus that don't support multiple PCI buses have
+             * hardcoded the name of their single PCI controller as
+             * "pci".
+             */
+            return VIR_STRDUP(controller->info.alias, "pci");
+        } else if (controller->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT) {
+            /* The pcie-root controller on Q35 machinetypes uses a
+             * different naming convention ("pcie.0"), because it is
+             * hardcoded that way in qemu.
+             */
             return virAsprintf(&controller->info.alias, "pcie.%d", controller->idx);
-        else
-            return virAsprintf(&controller->info.alias, "pci.%d", controller->idx);
-    }
-
+        }
+        /* All other PCI controllers use the consistent "pci.%u"
+         * (including the hardcoded pci-root controller on
+         * multibus-capable qemus).
+         */
+        return virAsprintf(&controller->info.alias, "pci.%d", controller->idx);
+    } else if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_IDE) {
+        /* for any machine based on I440FX, the first (and currently
+         * only) IDE controller is an integrated controller hardcoded
+         * with id "ide"
+         */
+        if (qemuDomainMachineIsI440FX(domainDef) && controller->idx == 0)
+            return VIR_STRDUP(controller->info.alias, "ide");
+    } else if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_SATA) {
+        /* for any Q35 machine, the first SATA controller is the
+         * integrated one, and it too is hardcoded with id "ide"
+         */
+        if (qemuDomainMachineIsQ35(domainDef) && controller->idx == 0)
+            return VIR_STRDUP(controller->info.alias, "ide");
+    } else if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_USB) {
+        /* first USB device is "usb", others are normal "usb%d" */
+        if (controller->idx == 0)
+            return VIR_STRDUP(controller->info.alias, "usb");
+    }
+    /* all other controllers use the default ${type}${index} naming
+     * scheme for alias/id.
+     */
     return virAsprintf(&controller->info.alias, "%s%d", prefix, controller->idx);
 }
 
@@ -1174,7 +1205,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
             return -1;
     }
     for (i = 0; i < def->ncontrollers; i++) {
-        if (qemuAssignDeviceControllerAlias(def->controllers[i]) < 0)
+        if (qemuAssignDeviceControllerAlias(def, qemuCaps, def->controllers[i]) < 0)
             return -1;
     }
     for (i = 0; i < def->ninputs; i++) {
index 675eb6240102477f35c1f766f400b96251632367..9ef7046189fdc6747493ffa73433002f0da4130b 100644 (file)
@@ -287,7 +287,10 @@ int qemuAssignDeviceDiskAlias(virDomainDefPtr vmdef,
                               virDomainDiskDefPtr def,
                               virQEMUCapsPtr qemuCaps);
 int qemuAssignDeviceHostdevAlias(virDomainDefPtr def, virDomainHostdevDefPtr hostdev, int idx);
-int qemuAssignDeviceControllerAlias(virDomainControllerDefPtr controller);
+int
+qemuAssignDeviceControllerAlias(virDomainDefPtr domainDef,
+                                virQEMUCapsPtr qemuCaps,
+                                virDomainControllerDefPtr controller);
 int qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, virDomainRedirdevDefPtr redirdev, int idx);
 int qemuAssignDeviceChrAlias(virDomainDefPtr def,
                              virDomainChrDefPtr chr,
index fc45de1a5b67a6a9f7e19390f0b9a46ac81d3deb..4c743bfeed9aff11438666cbfc54928aabef4d0e 100644 (file)
@@ -465,7 +465,7 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver,
                 goto cleanup;
         }
         releaseaddr = true;
-        if (qemuAssignDeviceControllerAlias(controller) < 0)
+        if (qemuAssignDeviceControllerAlias(vm->def, priv->qemuCaps, controller) < 0)
             goto cleanup;
 
         if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_USB &&
@@ -3639,7 +3639,7 @@ int qemuDomainDetachControllerDevice(virQEMUDriverPtr driver,
 
     if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) &&
         !detach->info.alias) {
-        if (qemuAssignDeviceControllerAlias(detach) < 0)
+        if (qemuAssignDeviceControllerAlias(vm->def, priv->qemuCaps, detach) < 0)
             goto cleanup;
     }