提交 a307143e 编写于 作者: M Michal Privoznik

virhostdev: Check driver name too in virHostdevIsPCINodeDeviceUsed()

It may happen that there are two domains with the same name in
two separate drivers (e.g. qemu and lxc). That is why for PCI
devices we track both names of driver and domain combination
which has taken the device. However, when we check if given PCI
device is in use (or PCI devices from the same IOMMU group) we
compare only domain name. This means that we can mistakenly claim
device as free to use while in fact it isn't.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Tested-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
上级 324b576c
...@@ -51,6 +51,7 @@ static virHostdevManagerPtr virHostdevManagerNew(void); ...@@ -51,6 +51,7 @@ static virHostdevManagerPtr virHostdevManagerNew(void);
struct virHostdevIsPCINodeDeviceUsedData { struct virHostdevIsPCINodeDeviceUsedData {
virHostdevManagerPtr mgr; virHostdevManagerPtr mgr;
const char *driverName;
const char *domainName; const char *domainName;
const bool usesVFIO; const bool usesVFIO;
}; };
...@@ -91,8 +92,8 @@ static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceAddressPtr devAddr, void *o ...@@ -91,8 +92,8 @@ static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceAddressPtr devAddr, void *o
virPCIDeviceGetUsedBy(actual, &actual_drvname, &actual_domname); virPCIDeviceGetUsedBy(actual, &actual_drvname, &actual_domname);
if (helperData->usesVFIO && if (helperData->usesVFIO &&
(actual_domname && helperData->domainName) && STREQ_NULLABLE(actual_drvname, helperData->driverName) &&
(STREQ(actual_domname, helperData->domainName))) STREQ_NULLABLE(actual_domname, helperData->domainName))
goto iommu_owner; goto iommu_owner;
if (actual_drvname && actual_domname) if (actual_drvname && actual_domname)
...@@ -706,7 +707,7 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, ...@@ -706,7 +707,7 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr,
virPCIDevicePtr pci = virPCIDeviceListGet(pcidevs, i); virPCIDevicePtr pci = virPCIDeviceListGet(pcidevs, i);
bool strict_acs_check = !!(flags & VIR_HOSTDEV_STRICT_ACS_CHECK); bool strict_acs_check = !!(flags & VIR_HOSTDEV_STRICT_ACS_CHECK);
bool usesVFIO = (virPCIDeviceGetStubDriver(pci) == VIR_PCI_STUB_DRIVER_VFIO); bool usesVFIO = (virPCIDeviceGetStubDriver(pci) == VIR_PCI_STUB_DRIVER_VFIO);
struct virHostdevIsPCINodeDeviceUsedData data = { mgr, dom_name, usesVFIO }; struct virHostdevIsPCINodeDeviceUsedData data = {mgr, drv_name, dom_name, usesVFIO};
int hdrType = -1; int hdrType = -1;
if (virPCIGetHeaderType(pci, &hdrType) < 0) if (virPCIGetHeaderType(pci, &hdrType) < 0)
...@@ -1995,7 +1996,7 @@ int ...@@ -1995,7 +1996,7 @@ int
virHostdevPCINodeDeviceDetach(virHostdevManagerPtr mgr, virHostdevPCINodeDeviceDetach(virHostdevManagerPtr mgr,
virPCIDevicePtr pci) virPCIDevicePtr pci)
{ {
struct virHostdevIsPCINodeDeviceUsedData data = { mgr, NULL, false }; struct virHostdevIsPCINodeDeviceUsedData data = {mgr, NULL, NULL, false};
int ret = -1; int ret = -1;
virObjectLock(mgr->activePCIHostdevs); virObjectLock(mgr->activePCIHostdevs);
...@@ -2021,7 +2022,7 @@ int ...@@ -2021,7 +2022,7 @@ int
virHostdevPCINodeDeviceReAttach(virHostdevManagerPtr mgr, virHostdevPCINodeDeviceReAttach(virHostdevManagerPtr mgr,
virPCIDevicePtr pci) virPCIDevicePtr pci)
{ {
struct virHostdevIsPCINodeDeviceUsedData data = { mgr, NULL, false }; struct virHostdevIsPCINodeDeviceUsedData data = {mgr, NULL, NULL, false};
int ret = -1; int ret = -1;
virObjectLock(mgr->activePCIHostdevs); virObjectLock(mgr->activePCIHostdevs);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册