virt-xml: add support for mediated devices

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.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Shalini Chellathurai Saroja <shalini@linux.ibm.com>
This commit is contained in:
Shalini Chellathurai Saroja 2021-05-31 21:54:26 +02:00 committed by Cole Robinson
parent 0f6b73d4f1
commit 9363e1e692
1 changed files with 20 additions and 0 deletions

View File

@ -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: # pragma: no cover
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