virpci.c: use virPCIDeviceAddressPtr in virPCIDeviceListFind()

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Daniel Henrique Barboza 2021-01-04 09:54:41 -03:00
parent d7d1479fc0
commit f1370f9ca6
3 changed files with 17 additions and 13 deletions

View File

@ -633,7 +633,8 @@ virHostdevReattachAllPCIDevices(virHostdevManagerPtr mgr,
/* We need to look up the actual device because that's what /* We need to look up the actual device because that's what
* virPCIDeviceReattach() expects as its argument */ * virPCIDeviceReattach() expects as its argument */
if (!(actual = virPCIDeviceListFind(mgr->inactivePCIHostdevs, pci))) if (!(actual = virPCIDeviceListFind(mgr->inactivePCIHostdevs,
virPCIDeviceGetAddress(pci))))
continue; continue;
if (virPCIDeviceGetManaged(actual)) { if (virPCIDeviceGetManaged(actual)) {
@ -753,7 +754,8 @@ virHostdevPreparePCIDevicesImpl(virHostdevManagerPtr mgr,
/* Unmanaged devices should already have been marked as /* Unmanaged devices should already have been marked as
* inactive: if that's the case, we can simply move on */ * inactive: if that's the case, we can simply move on */
if (virPCIDeviceListFind(mgr->inactivePCIHostdevs, pci)) { if (virPCIDeviceListFind(mgr->inactivePCIHostdevs,
virPCIDeviceGetAddress(pci))) {
VIR_DEBUG("Not detaching unmanaged PCI device %s", VIR_DEBUG("Not detaching unmanaged PCI device %s",
virPCIDeviceGetName(pci)); virPCIDeviceGetName(pci));
continue; continue;
@ -836,7 +838,8 @@ virHostdevPreparePCIDevicesImpl(virHostdevManagerPtr mgr,
* there because 'pci' only contain address information and will * there because 'pci' only contain address information and will
* be released at the end of the function */ * be released at the end of the function */
pci = virPCIDeviceListGet(pcidevs, i); pci = virPCIDeviceListGet(pcidevs, i);
actual = virPCIDeviceListFind(mgr->activePCIHostdevs, pci); actual = virPCIDeviceListFind(mgr->activePCIHostdevs,
virPCIDeviceGetAddress(pci));
VIR_DEBUG("Setting driver and domain information for PCI device %s", VIR_DEBUG("Setting driver and domain information for PCI device %s",
virPCIDeviceGetName(pci)); virPCIDeviceGetName(pci));
@ -967,7 +970,8 @@ virHostdevReAttachPCIDevicesImpl(virHostdevManagerPtr mgr,
* information such as by which domain and driver it is used. As a * information such as by which domain and driver it is used. As a
* side effect, by looking it up we can also tell whether it was * side effect, by looking it up we can also tell whether it was
* really active in the first place */ * really active in the first place */
actual = virPCIDeviceListFind(mgr->activePCIHostdevs, pci); actual = virPCIDeviceListFind(mgr->activePCIHostdevs,
virPCIDeviceGetAddress(pci));
if (actual) { if (actual) {
const char *actual_drvname; const char *actual_drvname;
const char *actual_domname; const char *actual_domname;

View File

@ -705,7 +705,7 @@ virPCIDeviceSharesBusWithActive(virPCIDevicePtr dev, virPCIDevicePtr check, void
return 0; return 0;
/* same bus, but inactive, i.e. about to be assigned to guest */ /* same bus, but inactive, i.e. about to be assigned to guest */
if (inactiveDevs && virPCIDeviceListFind(inactiveDevs, check)) if (inactiveDevs && virPCIDeviceListFind(inactiveDevs, &check->address))
return 0; return 0;
return 1; return 1;
@ -1022,7 +1022,7 @@ virPCIDeviceReset(virPCIDevicePtr dev,
return -1; return -1;
} }
if (activeDevs && virPCIDeviceListFind(activeDevs, dev)) { if (activeDevs && virPCIDeviceListFind(activeDevs, &dev->address)) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Not resetting active device %s"), dev->name); _("Not resetting active device %s"), dev->name);
return -1; return -1;
@ -1294,7 +1294,7 @@ virPCIDeviceDetach(virPCIDevicePtr dev,
if (virPCIProbeStubDriver(dev->stubDriver) < 0) if (virPCIProbeStubDriver(dev->stubDriver) < 0)
return -1; return -1;
if (activeDevs && virPCIDeviceListFind(activeDevs, dev)) { if (activeDevs && virPCIDeviceListFind(activeDevs, &dev->address)) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Not detaching active device %s"), dev->name); _("Not detaching active device %s"), dev->name);
return -1; return -1;
@ -1306,7 +1306,7 @@ virPCIDeviceDetach(virPCIDevicePtr dev,
/* Add *a copy of* the dev into list inactiveDevs, if /* Add *a copy of* the dev into list inactiveDevs, if
* it's not already there. * it's not already there.
*/ */
if (inactiveDevs && !virPCIDeviceListFind(inactiveDevs, dev)) { if (inactiveDevs && !virPCIDeviceListFind(inactiveDevs, &dev->address)) {
VIR_DEBUG("Adding PCI device %s to inactive list", dev->name); VIR_DEBUG("Adding PCI device %s to inactive list", dev->name);
if (virPCIDeviceListAddCopy(inactiveDevs, dev) < 0) if (virPCIDeviceListAddCopy(inactiveDevs, dev) < 0)
return -1; return -1;
@ -1324,7 +1324,7 @@ virPCIDeviceReattach(virPCIDevicePtr dev,
virPCIDeviceListPtr activeDevs, virPCIDeviceListPtr activeDevs,
virPCIDeviceListPtr inactiveDevs) virPCIDeviceListPtr inactiveDevs)
{ {
if (activeDevs && virPCIDeviceListFind(activeDevs, dev)) { if (activeDevs && virPCIDeviceListFind(activeDevs, &dev->address)) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Not reattaching active device %s"), dev->name); _("Not reattaching active device %s"), dev->name);
return -1; return -1;
@ -1684,7 +1684,7 @@ int
virPCIDeviceListAdd(virPCIDeviceListPtr list, virPCIDeviceListAdd(virPCIDeviceListPtr list,
virPCIDevicePtr dev) virPCIDevicePtr dev)
{ {
if (virPCIDeviceListFind(list, dev)) { if (virPCIDeviceListFind(list, &dev->address)) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Device %s is already in use"), dev->name); _("Device %s is already in use"), dev->name);
return -1; return -1;
@ -1795,11 +1795,11 @@ virPCIDeviceListFindByIDs(virPCIDeviceListPtr list,
virPCIDevicePtr virPCIDevicePtr
virPCIDeviceListFind(virPCIDeviceListPtr list, virPCIDevicePtr dev) virPCIDeviceListFind(virPCIDeviceListPtr list, virPCIDeviceAddressPtr devAddr)
{ {
int idx; int idx;
if ((idx = virPCIDeviceListFindIndex(list, &dev->address)) >= 0) if ((idx = virPCIDeviceListFindIndex(list, devAddr)) >= 0)
return list->devs[idx]; return list->devs[idx];
else else
return NULL; return NULL;

View File

@ -172,7 +172,7 @@ virPCIDevicePtr virPCIDeviceListStealIndex(virPCIDeviceListPtr list,
void virPCIDeviceListDel(virPCIDeviceListPtr list, void virPCIDeviceListDel(virPCIDeviceListPtr list,
virPCIDevicePtr dev); virPCIDevicePtr dev);
virPCIDevicePtr virPCIDeviceListFind(virPCIDeviceListPtr list, virPCIDevicePtr virPCIDeviceListFind(virPCIDeviceListPtr list,
virPCIDevicePtr dev); virPCIDeviceAddressPtr devAddr);
virPCIDevicePtr virPCIDevicePtr
virPCIDeviceListFindByIDs(virPCIDeviceListPtr list, virPCIDeviceListFindByIDs(virPCIDeviceListPtr list,
unsigned int domain, unsigned int domain,