Skip to content

Commit 3c88b76

Browse files
melwittpriteau
authored andcommitted
libvirt: Wrap un-proxied listDevices() and listAllDevices()
This is similar to change I668643c836d46a25df46d4c99a973af5e50a39db where the objects returned in a list from a libvirt call were not tpool.Proxy wrapped. Because the objects are not wrapped, calling methods on them such as listCaps() can block all other greenthreads and can cause nova-compute to freeze for hours in certain scenarios. This adds the same wrapping to libvirt calls which return lists of virNodeDevice. Closes-Bug: #2091033 Change-Id: I60d6f04d374e9ede5895a43b7a75e955b0fea3c5 (cherry picked from commit f304b9e)
1 parent 5fc31aa commit 3c88b76

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

nova/tests/unit/virt/libvirt/test_host.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,6 +2152,48 @@ def test_tpool_list_all_connections(self):
21522152
self.assertIsInstance(domain, tpool.Proxy)
21532153
self.assertIn(domain.UUIDString(), (uuids.vm1, uuids.vm2))
21542154

2155+
def _add_fake_host_devices(self):
2156+
self.conn._obj.pci_info = fakelibvirt.HostPCIDevicesInfo(
2157+
num_pci=1, num_pfs=2, num_vfs=2, num_mdevcap=3)
2158+
mdevs = {
2159+
'mdev_4b20d080_1b54_4048_85b3_a6a62d165c01':
2160+
fakelibvirt.FakeMdevDevice(
2161+
dev_name='mdev_4b20d080_1b54_4048_85b3_a6a62d165c01',
2162+
type_id=fakelibvirt.NVIDIA_11_VGPU_TYPE,
2163+
parent=fakelibvirt.MDEVCAP_DEV1_PCI_ADDR),
2164+
}
2165+
self.conn._obj.mdev_info = fakelibvirt.HostMdevDevicesInfo(
2166+
devices=mdevs)
2167+
2168+
def test_tpool_list_all_devices(self):
2169+
self._add_fake_host_devices()
2170+
devs = self.host.list_all_devices(
2171+
fakelibvirt.VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV)
2172+
self.assertEqual(8, len(devs))
2173+
for dev in devs:
2174+
self.assertIsInstance(dev, tpool.Proxy)
2175+
2176+
def test_tpool_list_pci_devices(self):
2177+
self._add_fake_host_devices()
2178+
devs = self.host.list_pci_devices()
2179+
self.assertEqual(8, len(devs))
2180+
for dev in devs:
2181+
self.assertIsInstance(dev, tpool.Proxy)
2182+
2183+
def test_tpool_list_mdev_capable_devices(self):
2184+
self._add_fake_host_devices()
2185+
devs = self.host.list_mdev_capable_devices()
2186+
self.assertEqual(3, len(devs))
2187+
for dev in devs:
2188+
self.assertIsInstance(dev, tpool.Proxy)
2189+
2190+
def test_tpool_list_mediated_devices(self):
2191+
self._add_fake_host_devices()
2192+
devs = self.host.list_mediated_devices()
2193+
self.assertEqual(1, len(devs))
2194+
for dev in devs:
2195+
self.assertIsInstance(dev, tpool.Proxy)
2196+
21552197

21562198
class LoadersTestCase(test.NoDBTestCase):
21572199

nova/virt/libvirt/host.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,9 @@ def _list_devices(self, cap, flags=0):
15921592
:returns: a list of virNodeDevice instance
15931593
"""
15941594
try:
1595-
return self.get_connection().listDevices(cap, flags)
1595+
devs = [self._wrap_libvirt_proxy(dev)
1596+
for dev in self.get_connection().listDevices(cap, flags)]
1597+
return devs
15961598
except libvirt.libvirtError as ex:
15971599
error_code = ex.get_error_code()
15981600
if error_code == libvirt.VIR_ERR_NO_SUPPORT:
@@ -1612,7 +1614,10 @@ def list_all_devices(
16121614
:returns: a list of virNodeDevice xml strings.
16131615
"""
16141616
try:
1615-
return self.get_connection().listAllDevices(flags) or []
1617+
alldevs = [
1618+
self._wrap_libvirt_proxy(dev)
1619+
for dev in self.get_connection().listAllDevices(flags)] or []
1620+
return alldevs
16161621
except libvirt.libvirtError as ex:
16171622
LOG.warning(ex)
16181623
return []
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fixes:
2+
- |
3+
`Bug #2091033`_: Fixed calls to libvirt ``listDevices()`` and
4+
``listAllDevices()`` from potentially blocking all other greenthreads
5+
in ``nova-compute``. Under certain circumstances, it was possible for
6+
the ``nova-compute`` service to freeze with all other greenthreads
7+
blocked and unable to perform any other activities including logging.
8+
This issue has been fixed by wrapping the libvirt ``listDevices()``
9+
and ``listAllDevices()`` calls with ``eventlet.tpool.Proxy``.
10+
11+
.. _Bug #2091033: https://bugs.launchpad.net/nova/+bug/2091033

0 commit comments

Comments
 (0)