mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-23 17:34:21 +03:00
nodedev: Fold DRMDevice into NodeDevice
This commit is contained in:
parent
87b2ea4672
commit
ab0c99057b
@ -138,18 +138,15 @@ class TestNodeDev(unittest.TestCase):
|
||||
|
||||
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(self.conn),
|
||||
"0000:00:02:0 Intel Corporation HD Graphics 530 (render)")
|
||||
dev = self._nodeDevFromName(devname)
|
||||
self.assertEqual(dev.devnodes[0].path, "/dev/dri/renderD129")
|
||||
self.assertEqual(dev.devnodes[0].node_type, "dev")
|
||||
self.assertEqual(dev.devnodes[1].path,
|
||||
"/dev/dri/by-path/pci-0000:00:02.0-render")
|
||||
self.assertEqual(dev.devnodes[1].node_type, "link")
|
||||
self.assertEqual(dev.is_drm_render(), True)
|
||||
self.assertEqual(dev.pretty_name(),
|
||||
"0000:00:02:0 Intel Corporation HD Graphics 530 (render)")
|
||||
|
||||
|
||||
# NodeDevice 2 Device XML tests
|
||||
|
@ -106,12 +106,10 @@ class vmmGraphicsDetails(vmmGObjectUI):
|
||||
devs = self.conn.filter_nodedevs("drm")
|
||||
for i in devs:
|
||||
drm = i.xmlobj
|
||||
if drm.drm_type != 'render':
|
||||
if not drm.is_drm_render():
|
||||
continue
|
||||
rendernode = drm.get_devnode().path
|
||||
|
||||
model.append([rendernode,
|
||||
i.xmlobj.drm_pretty_name(self.conn.get_backend())])
|
||||
model.append([rendernode, i.xmlobj.pretty_name()])
|
||||
|
||||
def _get_config_graphics_ports(self):
|
||||
port = uiutil.spin_get_helper(self.widget("graphics-port"))
|
||||
|
@ -259,8 +259,7 @@ class DeviceGraphics(Device):
|
||||
if not self.rendernode and self.conn.check_support(
|
||||
self.conn.SUPPORT_CONN_SPICE_RENDERNODE):
|
||||
for nodedev in self.conn.fetch_all_nodedevs():
|
||||
if (nodedev.device_type != 'drm' or
|
||||
nodedev.drm_type != 'render'):
|
||||
if not nodedev.is_drm_render():
|
||||
continue
|
||||
self.rendernode = nodedev.get_devnode().path
|
||||
break
|
||||
|
@ -97,16 +97,6 @@ class NodeDevice(XMLBuilder):
|
||||
name = XMLProperty("./name")
|
||||
parent = XMLProperty("./parent")
|
||||
device_type = XMLProperty("./capability/@type")
|
||||
devnodes = XMLChildProperty(DevNode)
|
||||
|
||||
def get_devnode(self, parent="by-path"):
|
||||
for d in self.devnodes:
|
||||
paths = d.path.split(os.sep)
|
||||
if len(paths) > 2 and paths[-2] == parent:
|
||||
return d
|
||||
if len(self.devnodes) > 0:
|
||||
return self.devnodes[0]
|
||||
return None
|
||||
|
||||
def compare_to_hostdev(self, hostdev):
|
||||
if self.device_type == "pci":
|
||||
@ -184,6 +174,11 @@ class NodeDevice(XMLBuilder):
|
||||
if self.device_type == "usb_device":
|
||||
return self._usb_pretty_name()
|
||||
|
||||
if self.device_type == "drm":
|
||||
parent = NodeDevice.lookupNodedevFromString(
|
||||
self.conn, self.parent)
|
||||
return "%s (%s)" % (parent.pretty_name(), self._drm_type)
|
||||
|
||||
return self.name
|
||||
|
||||
|
||||
@ -200,6 +195,9 @@ class NodeDevice(XMLBuilder):
|
||||
return (self.vendor_id == "0x1d6b" and
|
||||
self.product_id in ["0x0001", "0x0002", "0x0003"])
|
||||
|
||||
def is_drm_render(self):
|
||||
return self.device_type == "drm" and self._drm_type == "render"
|
||||
|
||||
|
||||
##################
|
||||
# XML properties #
|
||||
@ -237,14 +235,18 @@ class NodeDevice(XMLBuilder):
|
||||
"./capability/capability[@type='removable']/media_available",
|
||||
is_int=True)
|
||||
|
||||
# type='drm' options
|
||||
_drm_type = XMLProperty("./capability/type")
|
||||
devnodes = XMLChildProperty(DevNode)
|
||||
|
||||
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 get_devnode(self, parent="by-path"):
|
||||
for d in self.devnodes:
|
||||
paths = d.path.split(os.sep)
|
||||
if len(paths) > 2 and paths[-2] == parent:
|
||||
return d
|
||||
if len(self.devnodes) > 0:
|
||||
return self.devnodes[0]
|
||||
return None
|
||||
|
||||
|
||||
def _AddressStringToHostdev(conn, addrstr):
|
||||
@ -313,7 +315,4 @@ def _AddressStringToNodedev(conn, addrstr):
|
||||
|
||||
|
||||
def _typeToDeviceClass(t):
|
||||
if t == NodeDevice.CAPABILITY_TYPE_DRM:
|
||||
return DRMDevice
|
||||
else:
|
||||
return NodeDevice
|
||||
return NodeDevice
|
||||
|
Loading…
Reference in New Issue
Block a user