mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
qemuBuildDeviceAddressPCIStr: Extract PCI bus name lookup
Split up the bus lookup into a function called 'qemuBuildDeviceAddressPCIGetBus'. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
2fbda628c6
commit
e1eae5c430
@ -320,10 +320,9 @@ qemuVirCommandGetDevSet(virCommand *cmd, int fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static char *
|
||||||
qemuBuildDeviceAddressPCIStr(virBuffer *buf,
|
qemuBuildDeviceAddressPCIGetBus(const virDomainDef *domainDef,
|
||||||
const virDomainDef *domainDef,
|
virDomainDeviceInfo *info)
|
||||||
virDomainDeviceInfo *info)
|
|
||||||
{
|
{
|
||||||
g_autofree char *devStr = NULL;
|
g_autofree char *devStr = NULL;
|
||||||
const char *contAlias = NULL;
|
const char *contAlias = NULL;
|
||||||
@ -332,7 +331,7 @@ qemuBuildDeviceAddressPCIStr(virBuffer *buf,
|
|||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (!(devStr = virPCIDeviceAddressAsString(&info->addr.pci)))
|
if (!(devStr = virPCIDeviceAddressAsString(&info->addr.pci)))
|
||||||
return -1;
|
return NULL;
|
||||||
|
|
||||||
for (i = 0; i < domainDef->ncontrollers; i++) {
|
for (i = 0; i < domainDef->ncontrollers; i++) {
|
||||||
virDomainControllerDef *cont = domainDef->controllers[i];
|
virDomainControllerDef *cont = domainDef->controllers[i];
|
||||||
@ -347,7 +346,7 @@ qemuBuildDeviceAddressPCIStr(virBuffer *buf,
|
|||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Device alias was not set for PCI controller with index '%u' required for device at address '%s'"),
|
_("Device alias was not set for PCI controller with index '%u' required for device at address '%s'"),
|
||||||
info->addr.pci.bus, devStr);
|
info->addr.pci.bus, devStr);
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virDomainDeviceAliasIsUserAlias(contAlias)) {
|
if (virDomainDeviceAliasIsUserAlias(contAlias)) {
|
||||||
@ -372,20 +371,33 @@ qemuBuildDeviceAddressPCIStr(virBuffer *buf,
|
|||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Could not find PCI controller with index '%u' required for device at address '%s'"),
|
_("Could not find PCI controller with index '%u' required for device at address '%s'"),
|
||||||
info->addr.pci.bus, devStr);
|
info->addr.pci.bus, devStr);
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contIsPHB && contTargetIndex > 0) {
|
/* The PCI bus created by a spapr-pci-host-bridge device with
|
||||||
/* The PCI bus created by a spapr-pci-host-bridge device with
|
* alias 'x' will be called 'x.0' rather than 'x'; however,
|
||||||
* alias 'x' will be called 'x.0' rather than 'x'; however,
|
* this does not apply to the implicit PHB in a pSeries guest,
|
||||||
* this does not apply to the implicit PHB in a pSeries guest,
|
* which always has the hardcoded name 'pci.0' */
|
||||||
* which always has the hardcoded name 'pci.0' */
|
if (contIsPHB && contTargetIndex > 0)
|
||||||
virBufferAsprintf(buf, ",bus=%s.0", contAlias);
|
return g_strdup_printf("%s.0", contAlias);
|
||||||
} else {
|
|
||||||
/* For all other controllers, the bus name matches the alias
|
/* For all other controllers, the bus name matches the alias
|
||||||
* of the corresponding controller */
|
* of the corresponding controller */
|
||||||
virBufferAsprintf(buf, ",bus=%s", contAlias);
|
return g_strdup(contAlias);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuBuildDeviceAddressPCIStr(virBuffer *buf,
|
||||||
|
const virDomainDef *domainDef,
|
||||||
|
virDomainDeviceInfo *info)
|
||||||
|
{
|
||||||
|
g_autofree char *bus = NULL;
|
||||||
|
|
||||||
|
if (!(bus = qemuBuildDeviceAddressPCIGetBus(domainDef, info)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
virBufferStrcat(buf, ",bus=", bus, NULL);
|
||||||
|
|
||||||
if (info->addr.pci.multi == VIR_TRISTATE_SWITCH_ON)
|
if (info->addr.pci.multi == VIR_TRISTATE_SWITCH_ON)
|
||||||
virBufferAddLit(buf, ",multifunction=on");
|
virBufferAddLit(buf, ",multifunction=on");
|
||||||
|
Loading…
Reference in New Issue
Block a user