guest: Query availability of usb redirdevs in domcaps

Signed-off-by: Lin Ma <lma@suse.com>
This commit is contained in:
Lin Ma 2022-11-10 15:57:08 +08:00 committed by Cole Robinson
parent cbc5b89707
commit 8cc6ee8da3
2 changed files with 15 additions and 0 deletions

View File

@ -113,6 +113,7 @@ class _Devices(_CapsBlock):
graphics = XMLChildProperty(_make_capsblock("graphics"), is_single=True)
tpm = XMLChildProperty(_make_capsblock("tpm"), is_single=True)
filesystem = XMLChildProperty(_make_capsblock("filesystem"), is_single=True)
redirdev = XMLChildProperty(_make_capsblock("redirdev"), is_single=True)
class _Features(_CapsBlock):
@ -448,6 +449,18 @@ class DomainCapabilities(XMLBuilder):
return self.devices.graphics.get_enum("type").has_value("spice")
def supports_redirdev_usb(self):
"""
Return False if libvirt explicitly advertises no support for
USB redirect
"""
if self.devices.redirdev.supported is None:
# Follow the original behavior in case of talking to older
# libvirt.
return True
return self.devices.redirdev.get_enum("bus").has_value("usb")
def supports_filesystem_virtiofs(self):
"""
Return True if libvirt advertises support for virtiofs

View File

@ -1155,6 +1155,8 @@ class Guest(XMLBuilder):
self.add_device(dev)
def _add_spice_usbredir(self):
if not self.lookup_domcaps().supports_redirdev_usb():
return
if self.skip_default_usbredir:
return
if self.devices.redirdev: