mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-08 16:54:49 +00:00
qemu: Do not free the device from activePciHostdevs if it's in use
* src/qemu/qemu_hostdev.c (qemuDomainReAttachHostdevDevices): pciDeviceListFree(pcidevs) in the end free()s the device even if it's in use by other domain, which can cause a race. How to reproduce: <script> virsh nodedev-dettach pci_0000_00_19_0 virsh start test virsh attach-device test hostdev.xml virsh start test2 for i in {1..5}; do echo "[ -- ${i}th time --]" virsh nodedev-reattach pci_0000_00_19_0 done echo "clean up" virsh destroy test virsh nodedev-reattach pci_0000_00_19_0 </script> Device pci_0000_00_19_0 dettached Domain test started Device attached successfully error: Failed to start domain test2 error: Requested operation is not valid: PCI device 0000:00:19.0 is in use by domain test [ -- 1th time --] Device pci_0000_00_19_0 re-attached [ -- 2th time --] Device pci_0000_00_19_0 re-attached [ -- 3th time --] Device pci_0000_00_19_0 re-attached [ -- 4th time --] Device pci_0000_00_19_0 re-attached [ -- 5th time --] Device pci_0000_00_19_0 re-attached clean up Domain test destroyed Device pci_0000_00_19_0 re-attached The patch also fixes another problem, there won't be error like "qemuDomainReAttachHostdevDevices: Not reattaching active device 0000:00:19.0" in daemon log if some device is in active. As pciResetDevice and pciReattachDevice won't be called for the device anymore. This is sensible as we already reported error when preparing the device if it's active. Blindly trying to pciResetDevice & pciReattachDevice on the device and getting an error is just redundant.
This commit is contained in:
parent
a0aec362e8
commit
3f29d6c91f
@ -414,8 +414,10 @@ void qemuDomainReAttachHostdevDevices(struct qemud_driver *driver,
|
|||||||
*/
|
*/
|
||||||
activeDev = pciDeviceListFind(driver->activePciHostdevs, dev);
|
activeDev = pciDeviceListFind(driver->activePciHostdevs, dev);
|
||||||
if (activeDev &&
|
if (activeDev &&
|
||||||
STRNEQ_NULLABLE(name, pciDeviceGetUsedBy(activeDev)))
|
STRNEQ_NULLABLE(name, pciDeviceGetUsedBy(activeDev))) {
|
||||||
|
pciDeviceListSteal(pcidevs, dev);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* pciDeviceListFree() will take care of freeing the dev. */
|
/* pciDeviceListFree() will take care of freeing the dev. */
|
||||||
pciDeviceListSteal(driver->activePciHostdevs, dev);
|
pciDeviceListSteal(driver->activePciHostdevs, dev);
|
||||||
|
Loading…
Reference in New Issue
Block a user