From 7529627488886f981a4c3d3d7994f92ef7956cee Mon Sep 17 00:00:00 2001 From: Sylvain Bauza Date: Tue, 17 Apr 2018 15:46:05 +0200 Subject: [PATCH] libvirt: mdevs returning parent and vendor PCI info In order to provide inventories per physical GPUs, the libvirt driver needs to know the parent ID for each mediated device. Also, given we need to limit the max unit of vGPUs per guest to 1 if that's a nvidia GPU, we also need to pass the PCI vendor ID down to the driver. Related-Bug: #1758086 Change-Id: Ib80af55ccf4e578e7f8b58531da1b1e95783c779 --- nova/tests/unit/virt/libvirt/test_driver.py | 10 ++++++++++ nova/virt/libvirt/driver.py | 3 +++ 2 files changed, 13 insertions(+) diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 81af44d22fb9..a754c45516a1 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -20251,6 +20251,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin): def test_get_vgpu_total(self, get_mdev_devs, get_mdevs): get_mdev_devs.return_value = [ {'dev_id': 'pci_0000_84_00_0', + 'vendor_id': 0x10de, 'types': {'nvidia-11': {'availableInstances': 14, 'name': 'GRID M60-0B', 'deviceAPI': 'vfio-pci'}, @@ -20258,11 +20259,13 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin): get_mdevs.return_value = [ {'dev_id': 'mdev_4b20d080_1b54_4048_85b3_a6a62d165c01', 'uuid': "4b20d080-1b54-4048-85b3-a6a62d165c01", + 'parent': 'pci_0000_84_00_0', 'type': 'nvidia-11', 'iommuGroup': 1 }, {'dev_id': 'mdev_4b20d080_1b54_4048_85b3_a6a62d165c02', 'uuid': "4b20d080-1b54-4048-85b3-a6a62d165c02", + 'parent': 'pci_0000_84_00_0', 'type': 'nvidia-11', 'iommuGroup': 1 }, @@ -20294,6 +20297,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin): drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) expected = [{"dev_id": "pci_0000_06_00_0", + "vendor_id": 0x10de, "types": {'nvidia-11': {'availableInstances': 16, 'name': 'GRID M60-0B', 'deviceAPI': 'vfio-pci'}, @@ -20340,6 +20344,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin): drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) expected = [{"dev_id": "mdev_4b20d080_1b54_4048_85b3_a6a62d165c01", "uuid": "4b20d080-1b54-4048-85b3-a6a62d165c01", + "parent": "pci_0000_00_02_0", "type": "nvidia-11", "iommu_group": 12 }] @@ -20463,6 +20468,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin): unallocated_mdevs.return_value = set() get_mdev_capable_devs.return_value = [ {"dev_id": "pci_0000_06_00_0", + "vendor_id": 0x10de, "types": {'nvidia-11': {'availableInstances': 16, 'name': 'GRID M60-0B', 'deviceAPI': 'vfio-pci'}, @@ -20498,6 +20504,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin): # them being assigned get_mdev_capable_devs.return_value = [ {"dev_id": "pci_0000_06_00_0", + "vendor_id": 0x10de, "types": {'nvidia-11': {'availableInstances': 0, 'name': 'GRID M60-0B', 'deviceAPI': 'vfio-pci'}, @@ -20517,10 +20524,12 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin): # there is a total of 2 mdevs, mdev1 and mdev2 get_mediated_devices.return_value = [{'dev_id': 'mdev_some_uuid1', 'uuid': uuids.mdev1, + 'parent': "pci_some", 'type': 'nvidia-11', 'iommu_group': 1}, {'dev_id': 'mdev_some_uuid2', 'uuid': uuids.mdev2, + 'parent': "pci_some", 'type': 'nvidia-11', 'iommu_group': 1}] @@ -20555,6 +20564,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin): exists.side_effect = _exists get_mdev_capable_devs.return_value = [ {"dev_id": "pci_0000_06_00_0", + "vendor_id": 0x10de, "types": {'nvidia-11': {'availableInstances': 16, 'name': 'GRID M60-0B', 'deviceAPI': 'vfio-pci'}, diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index b1bf5c5bd732..4e8da1d299fe 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -5993,6 +5993,7 @@ class LibvirtDriver(driver.ComputeDriver): device = { "dev_id": cfgdev.name, "types": {}, + "vendor_id": cfgdev.pci_capability.vendor_id, } for mdev_cap in cfgdev.pci_capability.mdev_capability: for cap in mdev_cap.mdev_types: @@ -6033,6 +6034,8 @@ class LibvirtDriver(driver.ComputeDriver): "dev_id": cfgdev.name, # name is like mdev_00ead764_fdc0_46b6_8db9_2963f5c815b4 "uuid": str(uuid.UUID(cfgdev.name[5:].replace('_', '-'))), + # the physical GPU PCI device + "parent": cfgdev.parent, "type": cfgdev.mdev_information.type, "iommu_group": cfgdev.mdev_information.iommu_group, }