mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
hostdev: Look up devices using IDs when possible
When we want to look up a device in a device list and we already have the IDs from another source, we can simply use virPCIDeviceListFindByIDs() instead of creating a temporary device object.
This commit is contained in:
parent
e57e9413ac
commit
36243a0c62
@ -64,15 +64,11 @@ static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceAddressPtr devAddr, void *o
|
|||||||
{
|
{
|
||||||
virPCIDevicePtr other;
|
virPCIDevicePtr other;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virPCIDevicePtr pci = NULL;
|
|
||||||
struct virHostdevIsPCINodeDeviceUsedData *helperData = opaque;
|
struct virHostdevIsPCINodeDeviceUsedData *helperData = opaque;
|
||||||
|
|
||||||
if (!(pci = virPCIDeviceNew(devAddr->domain, devAddr->bus,
|
other = virPCIDeviceListFindByIDs(helperData->hostdev_mgr->activePCIHostdevs,
|
||||||
devAddr->slot, devAddr->function)))
|
devAddr->domain, devAddr->bus,
|
||||||
goto cleanup;
|
devAddr->slot, devAddr->function);
|
||||||
|
|
||||||
other = virPCIDeviceListFind(helperData->hostdev_mgr->activePCIHostdevs,
|
|
||||||
pci);
|
|
||||||
if (other) {
|
if (other) {
|
||||||
const char *other_drvname = NULL;
|
const char *other_drvname = NULL;
|
||||||
const char *other_domname = NULL;
|
const char *other_domname = NULL;
|
||||||
@ -87,18 +83,17 @@ static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceAddressPtr devAddr, void *o
|
|||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
_("PCI device %s is in use by "
|
_("PCI device %s is in use by "
|
||||||
"driver %s, domain %s"),
|
"driver %s, domain %s"),
|
||||||
virPCIDeviceGetName(pci),
|
virPCIDeviceGetName(other),
|
||||||
other_drvname, other_domname);
|
other_drvname, other_domname);
|
||||||
else
|
else
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
_("PCI device %s is in use"),
|
_("PCI device %s is in use"),
|
||||||
virPCIDeviceGetName(pci));
|
virPCIDeviceGetName(other));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
iommu_owner:
|
iommu_owner:
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virPCIDeviceFree(pci);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -669,7 +664,6 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr hostdev_mgr,
|
|||||||
/* Step 8: Now set the original states for hostdev def */
|
/* Step 8: Now set the original states for hostdev def */
|
||||||
for (i = 0; i < nhostdevs; i++) {
|
for (i = 0; i < nhostdevs; i++) {
|
||||||
virPCIDevicePtr dev;
|
virPCIDevicePtr dev;
|
||||||
virPCIDevicePtr pcidev;
|
|
||||||
virDomainHostdevDefPtr hostdev = hostdevs[i];
|
virDomainHostdevDefPtr hostdev = hostdevs[i];
|
||||||
virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
|
virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
|
||||||
|
|
||||||
@ -678,24 +672,25 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr hostdev_mgr,
|
|||||||
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
|
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
dev = virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
|
dev = virPCIDeviceListFindByIDs(pcidevs,
|
||||||
pcisrc->addr.slot, pcisrc->addr.function);
|
pcisrc->addr.domain,
|
||||||
|
pcisrc->addr.bus,
|
||||||
|
pcisrc->addr.slot,
|
||||||
|
pcisrc->addr.function);
|
||||||
|
|
||||||
/* Appropriate values for the unbind_from_stub, remove_slot
|
/* Appropriate values for the unbind_from_stub, remove_slot
|
||||||
* and reprobe properties of the device were set earlier
|
* and reprobe properties of the device were set earlier
|
||||||
* by virPCIDeviceDetach() */
|
* by virPCIDeviceDetach() */
|
||||||
|
if (dev) {
|
||||||
VIR_DEBUG("Saving network configuration of PCI device %s",
|
VIR_DEBUG("Saving network configuration of PCI device %s",
|
||||||
virPCIDeviceGetName(dev));
|
virPCIDeviceGetName(dev));
|
||||||
if ((pcidev = virPCIDeviceListFind(pcidevs, dev))) {
|
|
||||||
hostdev->origstates.states.pci.unbind_from_stub =
|
hostdev->origstates.states.pci.unbind_from_stub =
|
||||||
virPCIDeviceGetUnbindFromStub(pcidev);
|
virPCIDeviceGetUnbindFromStub(dev);
|
||||||
hostdev->origstates.states.pci.remove_slot =
|
hostdev->origstates.states.pci.remove_slot =
|
||||||
virPCIDeviceGetRemoveSlot(pcidev);
|
virPCIDeviceGetRemoveSlot(dev);
|
||||||
hostdev->origstates.states.pci.reprobe =
|
hostdev->origstates.states.pci.reprobe =
|
||||||
virPCIDeviceGetReprobe(pcidev);
|
virPCIDeviceGetReprobe(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
virPCIDeviceFree(dev);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Step 9: Now steal all the devices from pcidevs */
|
/* Step 9: Now steal all the devices from pcidevs */
|
||||||
@ -859,19 +854,21 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr hostdev_mgr,
|
|||||||
|
|
||||||
if (virHostdevIsPCINetDevice(hostdev)) {
|
if (virHostdevIsPCINetDevice(hostdev)) {
|
||||||
virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
|
virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
|
||||||
virPCIDevicePtr dev = NULL;
|
virPCIDevicePtr dev;
|
||||||
dev = virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,
|
|
||||||
pcisrc->addr.slot, pcisrc->addr.function);
|
dev = virPCIDeviceListFindByIDs(pcidevs,
|
||||||
|
pcisrc->addr.domain,
|
||||||
|
pcisrc->addr.bus,
|
||||||
|
pcisrc->addr.slot,
|
||||||
|
pcisrc->addr.function);
|
||||||
|
|
||||||
if (dev) {
|
if (dev) {
|
||||||
if (virPCIDeviceListFind(pcidevs, dev)) {
|
|
||||||
VIR_DEBUG("Restoring network configuration of PCI device %s",
|
VIR_DEBUG("Restoring network configuration of PCI device %s",
|
||||||
virPCIDeviceGetName(dev));
|
virPCIDeviceGetName(dev));
|
||||||
virHostdevNetConfigRestore(hostdev, hostdev_mgr->stateDir,
|
virHostdevNetConfigRestore(hostdev, hostdev_mgr->stateDir,
|
||||||
oldStateDir);
|
oldStateDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virPCIDeviceFree(dev);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Step 3: perform a PCI Reset on all devices */
|
/* Step 3: perform a PCI Reset on all devices */
|
||||||
|
Loading…
Reference in New Issue
Block a user