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

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