[PATCH virt-manager v2 1/4] virt-xml: add support for mediated devices

Shalini Chellathurai Saroja shalini at linux.ibm.com
Mon May 31 19:54:26 UTC 2021


Provide support to add/remove MDEV in a guest domain, which is in
shut-off or running state (hotplug/unplug). Also support update of
already existing MDEV device, when the guest domain is in shut-off
state. Please note that libvirt does not support update of MDEV
device, when the guest domain is in running state.

Signed-off-by: Shalini Chellathurai Saroja <shalini at linux.ibm.com>
---
 virtinst/nodedev.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/virtinst/nodedev.py b/virtinst/nodedev.py
index 97841794..3e00455b 100644
--- a/virtinst/nodedev.py
+++ b/virtinst/nodedev.py
@@ -5,6 +5,7 @@
 # See the COPYING file in the top-level directory.
 
 import os
+import uuid
 
 from .logger import log
 from .xmlbuilder import XMLBuilder, XMLProperty, XMLChildProperty
@@ -25,6 +26,16 @@ def _compare_int(nodedev_val, hostdev_val):
     return (nodedev_val == hostdev_val or hostdev_val == -1)
 
 
+def _compare_uuid(nodedev_val, hostdev_val):
+    try:
+        nodedev_val = uuid.UUID(nodedev_val)
+        hostdev_val = uuid.UUID(hostdev_val)
+    except Exception:
+        return -1
+
+    return (nodedev_val == hostdev_val)
+
+
 class DevNode(XMLBuilder):
     XML_NAME = "devnode"
 
@@ -82,6 +93,9 @@ class NodeDevice(XMLBuilder):
     parent = XMLProperty("./parent")
     device_type = XMLProperty("./capability/@type")
 
+    def get_mdev_uuid(self):
+        return self.name[5:].replace('_', '-')
+
     def compare_to_hostdev(self, hostdev):
         if self.device_type == "pci":
             if hostdev.type != "pci":
@@ -101,6 +115,12 @@ class NodeDevice(XMLBuilder):
                 _compare_int(self.bus, hostdev.bus) and
                 _compare_int(self.device, hostdev.device))
 
+        if self.device_type == "mdev":
+            if hostdev.type != "mdev":
+                return False
+
+            return _compare_uuid(self.get_mdev_uuid(), hostdev.uuid)
+
         return False
 
 
-- 
2.30.2




More information about the virt-tools-list mailing list