Blame SOURCES/virt-manager-virt-xml-add-support-for-mediated-devices.patch

610fa1
From d4a11d8f8a0b7990c9d349da2306c7f4103a43e0 Mon Sep 17 00:00:00 2001
610fa1
From: Shalini Chellathurai Saroja <shalini@linux.ibm.com>
610fa1
Date: Mon, 31 May 2021 21:54:26 +0200
610fa1
Subject: [PATCH] virt-xml: add support for mediated devices
610fa1
610fa1
Provide support to add/remove MDEV in a guest domain, which is in
610fa1
shut-off or running state (hotplug/unplug). Also support update of
610fa1
already existing MDEV device, when the guest domain is in shut-off
610fa1
state. Please note that libvirt does not support update of MDEV
610fa1
device, when the guest domain is in running state.
610fa1
610fa1
Reviewed-by: Cole Robinson <crobinso@redhat.com>
610fa1
Signed-off-by: Shalini Chellathurai Saroja <shalini@linux.ibm.com>
610fa1
610fa1
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1995131
610fa1
610fa1
(cherry picked from commit 9363e1e692bb0d01184ecc7991d61c95542f690b)
610fa1
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
610fa1
---
610fa1
 virtinst/nodedev.py | 20 ++++++++++++++++++++
610fa1
 1 file changed, 20 insertions(+)
610fa1
610fa1
diff --git a/virtinst/nodedev.py b/virtinst/nodedev.py
610fa1
index 97841794..f54a311c 100644
610fa1
--- a/virtinst/nodedev.py
610fa1
+++ b/virtinst/nodedev.py
610fa1
@@ -5,6 +5,7 @@
610fa1
 # See the COPYING file in the top-level directory.
610fa1
 
610fa1
 import os
610fa1
+import uuid
610fa1
 
610fa1
 from .logger import log
610fa1
 from .xmlbuilder import XMLBuilder, XMLProperty, XMLChildProperty
610fa1
@@ -25,6 +26,16 @@ def _compare_int(nodedev_val, hostdev_val):
610fa1
     return (nodedev_val == hostdev_val or hostdev_val == -1)
610fa1
 
610fa1
 
610fa1
+def _compare_uuid(nodedev_val, hostdev_val):
610fa1
+    try:
610fa1
+        nodedev_val = uuid.UUID(nodedev_val)
610fa1
+        hostdev_val = uuid.UUID(hostdev_val)
610fa1
+    except Exception:  # pragma: no cover
610fa1
+        return -1
610fa1
+
610fa1
+    return (nodedev_val == hostdev_val)
610fa1
+
610fa1
+
610fa1
 class DevNode(XMLBuilder):
610fa1
     XML_NAME = "devnode"
610fa1
 
610fa1
@@ -82,6 +93,9 @@ class NodeDevice(XMLBuilder):
610fa1
     parent = XMLProperty("./parent")
610fa1
     device_type = XMLProperty("./capability/@type")
610fa1
 
610fa1
+    def get_mdev_uuid(self):
610fa1
+        return self.name[5:].replace('_', '-')
610fa1
+
610fa1
     def compare_to_hostdev(self, hostdev):
610fa1
         if self.device_type == "pci":
610fa1
             if hostdev.type != "pci":
610fa1
@@ -101,6 +115,12 @@ class NodeDevice(XMLBuilder):
610fa1
                 _compare_int(self.bus, hostdev.bus) and
610fa1
                 _compare_int(self.device, hostdev.device))
610fa1
 
610fa1
+        if self.device_type == "mdev":
610fa1
+            if hostdev.type != "mdev":
610fa1
+                return False
610fa1
+
610fa1
+            return _compare_uuid(self.get_mdev_uuid(), hostdev.uuid)
610fa1
+
610fa1
         return False
610fa1
 
610fa1
 
610fa1
-- 
610fa1
2.31.1
610fa1