[virt-tools-list] [PATCH 04/12] virtinst: add DRMDevice

marcandre.lureau at redhat.com marcandre.lureau at redhat.com
Tue Feb 21 13:00:54 UTC 2017


From: Marc-André Lureau <marcandre.lureau at redhat.com>

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

Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
---
 tests/nodedev.py     | 15 +++++++++++++++
 tests/testdriver.xml | 27 +++++++++++++++++++++++++++
 virtinst/nodedev.py  | 12 ++++++++++++
 3 files changed, 54 insertions(+)

diff --git a/tests/nodedev.py b/tests/nodedev.py
index 0d214afe..15e54b1d 100644
--- a/tests/nodedev.py
+++ b/tests/nodedev.py
@@ -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"}
diff --git a/tests/testdriver.xml b/tests/testdriver.xml
index daf74f26..ff1f97a7 100644
--- a/tests/testdriver.xml
+++ b/tests/testdriver.xml
@@ -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>
 
 
 
diff --git a/virtinst/nodedev.py b/virtinst/nodedev.py
index 07ffe01e..f27cfbb2 100644
--- a/virtinst/nodedev.py
+++ b/virtinst/nodedev.py
@@ -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
-- 
2.11.0.295.gd7dffce1c.dirty




More information about the virt-tools-list mailing list