From 8534499b4a76a8aaf39005f251da33a25e95a67c Mon Sep 17 00:00:00 2001 From: Mohammed Naser Date: Fri, 6 May 2022 17:18:35 -0400 Subject: [PATCH] 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 --- nova/virt/libvirt/driver.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 34526abc3888..197ffb568125 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -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,