提交 75cd7d9b 编写于 作者: L Laine Stump

qemu: fix exceptions in qemuAssignDeviceControllerAlias

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.
上级 a3dfaf12
......@@ -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++) {
......
......@@ -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,
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册