summaryrefslogtreecommitdiff
path: root/nova/virt
diff options
context:
space:
mode:
authorArtom Lifshitz <alifshit@redhat.com>2018-01-15 15:52:11 -0500
committerArtom Lifshitz <alifshit@redhat.com>2018-07-10 11:21:17 -0400
commite57f66a26daf858d1348c8406108a33a323b7b2e (patch)
treeb657e220f63c1e1a7561c0a7df7e8abb3622421b /nova/virt
parent0f253ea9c5f3f3d97bc049f00d1bcdf2761f0736 (diff)
downloadnova-e57f66a26daf858d1348c8406108a33a323b7b2e.tar.gz
Consider hostdev devices when building metadata
Previously, device role tagging metadata would only be built for LibvirtConfigGuestInterface and LibvirtConfigGuestDisk. This didn't account for passed through PFs, which can also be tagged and appear as <hostdev> in the libvirt XML. This caused device role tagging to not work for PFs. This patch adds support for <hostdev> devices to _build_device_metadata. NOTE(artom): Conflicts in nova/tests/unit/virt/libvirt/test_driver.py due to trusted VFs not being present in Queens. Change-Id: I24e5ff1b446f2ac41d589c026ce8ee8adad4bcbc Closes-bug: 1743458 Closes-bug: 1694183 (cherry picked from commit abd01a757b8a83d714a6ab8b5085e7cc1b4a2c5c)
Diffstat (limited to 'nova/virt')
-rw-r--r--nova/virt/libvirt/driver.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index 404a096171..907abe7327 100644
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -8675,6 +8675,42 @@ class LibvirtDriver(driver.ComputeDriver):
device.bus = bus
return device
+ def _build_hostdev_metadata(self, dev, vifs_to_expose, vlans_by_mac):
+ """Builds a metadata object for a hostdev. This can only be a PF, so we
+ don't need trusted_by_mac like in _build_interface_metadata because
+ only VFs can be trusted.
+
+ :param dev: The LibvirtConfigGuestHostdevPCI to build metadata for.
+ :param vifs_to_expose: The list of tagged and/or vlan'ed
+ VirtualInterface objects.
+ :param vlans_by_mac: A dictionary of mac address -> vlan associations.
+ :return: A NetworkInterfaceMetadata object, or None.
+ """
+ # Strip out the leading '0x'
+ pci_address = pci_utils.get_pci_address(
+ *[x[2:] for x in (dev.domain, dev.bus, dev.slot, dev.function)])
+ try:
+ mac = pci_utils.get_mac_by_pci_address(pci_address,
+ pf_interface=True)
+ except exception.PciDeviceNotFoundById:
+ LOG.debug('Not exposing metadata for not found PCI device %s',
+ pci_address)
+ return None
+
+ vif = vifs_to_expose.get(mac)
+ if not vif:
+ LOG.debug('No VIF found with MAC %s, not building metadata', mac)
+ return None
+
+ device = objects.NetworkInterfaceMetadata(mac=mac)
+ device.bus = objects.PCIDeviceBus(address=pci_address)
+ if 'tag' in vif and vif.tag:
+ device.tags = [vif.tag]
+ vlan = vlans_by_mac.get(mac)
+ if vlan:
+ device.vlan = int(vlan)
+ return device
+
def _build_device_metadata(self, context, instance):
"""Builds a metadata object for instance devices, that maps the user
provided tag to the hypervisor assigned device address.
@@ -8710,6 +8746,9 @@ class LibvirtDriver(driver.ComputeDriver):
vlans_by_mac)
if isinstance(dev, vconfig.LibvirtConfigGuestDisk):
device = self._build_disk_metadata(dev, tagged_bdms)
+ if isinstance(dev, vconfig.LibvirtConfigGuestHostdevPCI):
+ device = self._build_hostdev_metadata(dev, vifs_to_expose,
+ vlans_by_mac)
if device:
devices.append(device)
if devices: