Fix race condition in _get_pci_passthrough_devices

The call to _get_pci_passthrough_devices could fail because a
network device could have disappeared which would cause a traceback
in the logs.

This wraps the function in a safe way to return an empty array
if it fails, which will clean-up the logs if the device disappears

Closes-Bug: #1972028
Change-Id: I46d3bbe122d9f8452f168286391bab67ecea3128
This commit is contained in:
Mohammed Naser 2022-05-06 17:18:35 -04:00
parent b7e1d1219c
commit 8534499b4a
1 changed files with 17 additions and 3 deletions

View File

@ -7950,13 +7950,27 @@ class LibvirtDriver(driver.ComputeDriver):
dev.name(): dev for dev in
self._host.list_all_devices(flags=dev_flags)
}
net_devs = [dev for dev in devices.values() if "net" in dev.listCaps()]
# NOTE(mnaser): The listCaps() function can raise an exception if the
# device disappeared while we're looping, this method
# returns an empty list rather than raising an exception
# which will remove the device for Nova's resource
# tracker, but that is OK since the device disappeared.
def _safe_list_caps(dev):
try:
return dev.listCaps()
except libvirt.libvirtError:
return []
net_devs = [
dev for dev in devices.values() if "net" in _safe_list_caps(dev)
]
vdpa_devs = [
dev for dev in devices.values() if "vdpa" in dev.listCaps()
dev for dev in devices.values() if "vdpa" in _safe_list_caps(dev)
]
pci_devs = {
name: dev for name, dev in devices.items()
if "pci" in dev.listCaps()}
if "pci" in _safe_list_caps(dev)}
pci_info = [
self._host._get_pcidev_info(
name, dev, net_devs,