From: Shivaprasad G Bhat <sb...@linux.vnet.ibm.com> Signed-off-by: Shivaprasad G Bhat <sb...@linux.vnet.ibm.com> Signed-off-by: Daniel Henrique Barboza <danielhb...@gmail.com> --- src/hypervisor/virhostdev.c | 29 +++++++++++++++++++++++++++++ src/hypervisor/virhostdev.h | 2 ++ src/libvirt_private.syms | 1 + 3 files changed, 32 insertions(+)
diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index 9017cc3be8..03e0c5b470 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -312,6 +312,35 @@ virHostdevIsVirtualFunction(virDomainHostdevDefPtr hostdev) } +bool +virHostdevPCIDevicesBelongToSameSlot(virDomainHostdevDefPtr dev1, + virDomainHostdevDefPtr dev2) +{ + virPCIDeviceAddressPtr devAddr1 = NULL, devAddr2 = NULL; + + if (!dev1 || !dev2) + return false; + + devAddr1 = &dev1->source.subsys.u.pci.addr; + devAddr2 = &dev2->source.subsys.u.pci.addr; + if ((devAddr1->domain != devAddr2->domain) || + (devAddr1->bus != devAddr2->bus) || + (devAddr1->slot != devAddr2->slot) || + (virPCIDeviceAddressEqual(devAddr1, devAddr2))) { + return false; + } + + /* The Virtual Functions have multifunction false even though they have same + * domain:bus:slot as the Physical function. They are to be treated + * like non-multifunction devices + */ + if (virHostdevIsVirtualFunction(dev1) || virHostdevIsVirtualFunction(dev2)) + return false; + + return true; +} + + static int virHostdevNetDevice(virDomainHostdevDefPtr hostdev, int pfNetDevIdx, diff --git a/src/hypervisor/virhostdev.h b/src/hypervisor/virhostdev.h index 811bda40ed..84515d83fd 100644 --- a/src/hypervisor/virhostdev.h +++ b/src/hypervisor/virhostdev.h @@ -202,6 +202,8 @@ int virHostdevPCINodeDeviceReAttach(virHostdevManagerPtr mgr, int virHostdevPCINodeDeviceReset(virHostdevManagerPtr mgr, virPCIDevicePtr pci) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); +bool virHostdevPCIDevicesBelongToSameSlot(virDomainHostdevDefPtr dev1, + virDomainHostdevDefPtr dev2); int virHostdevPrepareOneNVMeDevice(virHostdevManagerPtr hostdev_mgr, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c143264382..e74174ffbd 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -726,6 +726,7 @@ virHostdevIsMdevDevice; virHostdevIsPCIMultifunctionDevice; virHostdevIsSCSIDevice; virHostdevIsVFIODevice; +virHostdevPCIDevicesBelongToSameSlot; # conf/domain_nwfilter.h -- 2.26.2