nodedev: add DRMDevice

drm capability has been proposed for libvirt 3.1, it provide Direct
Rendering Manager (DRM) devices.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau 2017-02-21 17:00:54 +04:00 committed by Cole Robinson
parent a861629f0c
commit 35e6003ba5
3 changed files with 54 additions and 0 deletions

View File

@ -236,6 +236,21 @@ class TestNodeDev(unittest.TestCase):
"type": "disk"}
self._testCompare(devname, vals)
def testDRMDevice(self):
devname = "drm_renderD129"
vals = {"name": "drm_renderD129",
"parent": "pci_0000_00_02_0",
"devnodes": [
{"path": "/dev/dri/renderD129", "node_type": "dev"},
{"path": "/dev/dri/by-path/pci-0000:00:02.0-render", "node_type": "link"},
{"path": "/dev/dri/by-id/foo-render", "node_type": "link"}
],
"device_type": NodeDevice.CAPABILITY_TYPE_DRM,
"drm_type": "render"}
dev = self._testCompare(devname, vals)
self.assertEqual(dev.drm_pretty_name(conn),
"0000:00:02:0 Intel Corporation HD Graphics 530 (render)")
def testUnknownDevice(self):
vals = {"name": "foodevice", "parent": "computer",
"device_type": "frobtype"}

View File

@ -3469,7 +3469,34 @@ ba</description>
</device>
<!-- End duplicate USB devices -->
<device>
<name>pci_0000_00_02_0</name>
<path>/sys/devices/pci0000:00/0000:00:02.0</path>
<parent>computer</parent>
<driver>
<name>i915</name>
</driver>
<capability type='pci'>
<domain>0</domain>
<bus>0</bus>
<slot>2</slot>
<function>0</function>
<product id='0x191b'>HD Graphics 530</product>
<vendor id='0x8086'>Intel Corporation</vendor>
</capability>
</device>
<device>
<name>drm_renderD129</name>
<path>/sys/devices/pci0000:00/0000:00:02.0/drm/renderD129</path>
<devnode type='dev'>/dev/dri/renderD129</devnode>
<devnode type='link'>/dev/dri/by-path/pci-0000:00:02.0-render</devnode>
<devnode type='link'>/dev/dri/by-id/foo-render</devnode>
<parent>pci_0000_00_02_0</parent>
<capability type='drm'>
<type>render</type>
</capability>
</device>

View File

@ -54,6 +54,7 @@ class NodeDevice(XMLBuilder):
CAPABILITY_TYPE_STORAGE = "storage"
CAPABILITY_TYPE_SCSIBUS = "scsi_host"
CAPABILITY_TYPE_SCSIDEV = "scsi"
CAPABILITY_TYPE_DRM = "drm"
@staticmethod
def lookupNodedevFromString(conn, idstring):
@ -328,6 +329,15 @@ class SCSIBus(NodeDevice):
wwpn = XMLProperty("./capability/capability[@type='fc_host']/wwpn")
class DRMDevice(NodeDevice):
drm_type = XMLProperty("./capability/type")
def drm_pretty_name(self, conn):
parent = NodeDevice.lookupNodedevFromString(conn, self.parent)
return "%s (%s)" % (parent.pretty_name(), self.drm_type)
def _AddressStringToHostdev(conn, addrstr):
from .devicehostdev import VirtualHostDevice
hostdev = VirtualHostDevice(conn)
@ -410,5 +420,7 @@ def _typeToDeviceClass(t):
return SCSIBus
elif t == NodeDevice.CAPABILITY_TYPE_SCSIDEV:
return SCSIDevice
elif t == NodeDevice.CAPABILITY_TYPE_DRM:
return DRMDevice
else:
return NodeDevice