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. --- Changes from V1: (this was 06/13 in V1) * no longer changed into switch statement, since so few of the types actually need an exception. * Added exception for USB controller aliases. (thanks for pointing that one out, John!) src/qemu/qemu_command.c | 53 +++++++++++++++++++++++++++++++++++++++---------- src/qemu/qemu_command.h | 5 ++++- src/qemu/qemu_hotplug.c | 4 ++-- 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 5d0a167..a75664c 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -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++) { diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 675eb62..9ef7046 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -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, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index fc45de1..4c743bf 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -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; } -- 2.1.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list