Blame SOURCES/virt-manager-Handle-new-nodedev-name-for-mediated-devices.patch

610fa1
From 9cb766bec0296720e98101807726dd9a488486c4 Mon Sep 17 00:00:00 2001
610fa1
From: Jonathon Jongsma <jjongsma@redhat.com>
610fa1
Date: Tue, 26 Oct 2021 14:18:40 -0500
610fa1
Subject: [PATCH] Handle new nodedev name for mediated devices
610fa1
610fa1
libvirt recently changed the nodedev names for mediated devices due to
610fa1
the fact that mdevctl supports defining multiple mediated devices with
610fa1
the same UUID as long as only one is active at a time. This means that
610fa1
the nodedev name changed from the format 'mdev_$UUID' to the format
610fa1
'mdev_$UUID_$PARENT'.
610fa1
610fa1
Unfortunately, virt-install was parsing the nodedev name to extract the
610fa1
UUID of a mediated device. This fails with the new name format.
610fa1
Fortunately, in libvirt 7.3.0, a <uuid> field was added to the xml
610fa1
schema for mdev devices, so we can simply use this instead, and fall
610fa1
back to the name parsing if it doesn't exist.
610fa1
610fa1
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
610fa1
(cherry picked from commit 0c146b250384ddddcefd2cc0d76b9e808377ebe5)
610fa1
610fa1
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2023650
610fa1
610fa1
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
610fa1
---
610fa1
 tests/data/testdriver/testdriver.xml | 14 ++++++++++++++
610fa1
 tests/test_nodedev.py                | 14 ++++++++++++++
610fa1
 virtinst/nodedev.py                  |  7 +++++++
610fa1
 3 files changed, 35 insertions(+)
610fa1
610fa1
diff --git a/tests/data/testdriver/testdriver.xml b/tests/data/testdriver/testdriver.xml
610fa1
index 5875732a..e4880936 100644
610fa1
--- a/tests/data/testdriver/testdriver.xml
610fa1
+++ b/tests/data/testdriver/testdriver.xml
610fa1
@@ -3725,4 +3725,18 @@ ba</description>
610fa1
   </capability>
610fa1
 </device>
610fa1
 
610fa1
+<device>
610fa1
+  <name>mdev_35ceae7f_eea5_4f28_b7f3_7b12a3e62d3c_0000_06_00_0</name>
610fa1
+  <path>/sys/devices/pci0000:00/0000:00:02.0/35ceae7f-eea5-4f28-b7f3-7b12a3e62d3c</path>
610fa1
+  <parent>pci_0000_06_00_0</parent>
610fa1
+  <driver>
610fa1
+    <name>vfio_mdev</name>
610fa1
+  </driver>
610fa1
+ <capability type='mdev'>
610fa1
+    <type id='nvidia-11'/>
610fa1
+    <iommuGroup number='12'/>
610fa1
+    <uuid>35ceae7f-eea5-4f28-b7f3-7b12a3e62d3c</uuid>
610fa1
+  </capability>
610fa1
+</device>
610fa1
+
610fa1
 </node>
610fa1
diff --git a/tests/test_nodedev.py b/tests/test_nodedev.py
610fa1
index 79678bc8..41435262 100644
610fa1
--- a/tests/test_nodedev.py
610fa1
+++ b/tests/test_nodedev.py
610fa1
@@ -8,6 +8,7 @@
610fa1
 import os.path
610fa1
 
610fa1
 import pytest
610fa1
+import libvirt
610fa1
 
610fa1
 from virtinst import Guest
610fa1
 from virtinst import NodeDevice
610fa1
@@ -154,6 +155,19 @@ def testPCIMdev():
610fa1
     assert dev.parent == "pci_0000_06_00_0"
610fa1
     assert dev.device_type == "mdev"
610fa1
     assert dev.type_id == "nvidia-11"
610fa1
+    assert dev.get_mdev_uuid() == "4b20d080-1b54-4048-85b3-a6a62d165c01"
610fa1
+
610fa1
+# libvirt <7.3.0 doesn't support <uuid> in the mdev node device xml
610fa1
+@pytest.mark.skipif(libvirt.getVersion() < 7003000, reason="libvirt version doesn't support new mdev format")
610fa1
+def testPCIMdevNewFormat():
610fa1
+    conn = utils.URIs.open_testdriver_cached()
610fa1
+    devname = "mdev_35ceae7f_eea5_4f28_b7f3_7b12a3e62d3c_0000_06_00_0"
610fa1
+    dev = _nodeDevFromName(conn, devname)
610fa1
+    assert dev.name == devname
610fa1
+    assert dev.parent == "pci_0000_06_00_0"
610fa1
+    assert dev.device_type == "mdev"
610fa1
+    assert dev.type_id == "nvidia-11"
610fa1
+    assert dev.get_mdev_uuid() == "35ceae7f-eea5-4f28-b7f3-7b12a3e62d3c"
610fa1
 
610fa1
 
610fa1
 # NodeDevice 2 Device XML tests
610fa1
diff --git a/virtinst/nodedev.py b/virtinst/nodedev.py
610fa1
index f54a311c..248723b9 100644
610fa1
--- a/virtinst/nodedev.py
610fa1
+++ b/virtinst/nodedev.py
610fa1
@@ -94,6 +94,12 @@ class NodeDevice(XMLBuilder):
610fa1
     device_type = XMLProperty("./capability/@type")
610fa1
 
610fa1
     def get_mdev_uuid(self):
610fa1
+        # libvirt 7.3.0 added a <uuid> element to the nodedev xml for mdev
610fa1
+        # types. For older versions, we unfortunately have to parse the nodedev
610fa1
+        # name, which uses the format "mdev_$UUID_WITH_UNDERSCORES"
610fa1
+        if self.uuid is not None:
610fa1
+            return self.uuid
610fa1
+
610fa1
         return self.name[5:].replace('_', '-')
610fa1
 
610fa1
     def compare_to_hostdev(self, hostdev):
610fa1
@@ -191,6 +197,7 @@ class NodeDevice(XMLBuilder):
610fa1
 
610fa1
     # type='mdev' options
610fa1
     type_id = XMLProperty("./capability/type/@id")
610fa1
+    uuid = XMLProperty("./capability/uuid")
610fa1
 
610fa1
 
610fa1
 def _AddressStringToHostdev(conn, addrstr):
610fa1
-- 
610fa1
2.31.1
610fa1