2013-03-18 05:06:52 +08:00
|
|
|
#
|
2013-10-28 04:59:46 +08:00
|
|
|
# Copyright 2009, 2013 Red Hat, Inc.
|
2013-03-18 05:06:52 +08:00
|
|
|
#
|
2018-04-04 21:35:41 +08:00
|
|
|
# This work is licensed under the GNU GPLv2 or later.
|
2018-03-21 03:00:02 +08:00
|
|
|
# See the COPYING file in the top-level directory.
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2021-04-14 23:18:55 +08:00
|
|
|
import re
|
|
|
|
|
2020-11-15 07:14:45 +08:00
|
|
|
from ..logger import log
|
|
|
|
|
2018-03-21 00:18:35 +08:00
|
|
|
from .device import Device
|
2018-03-21 00:27:37 +08:00
|
|
|
from ..nodedev import NodeDevice
|
|
|
|
from ..xmlbuilder import XMLProperty
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2018-03-21 00:18:35 +08:00
|
|
|
class DeviceHostdev(Device):
|
2018-03-21 22:53:34 +08:00
|
|
|
XML_NAME = "hostdev"
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-07-23 19:15:26 +08:00
|
|
|
def set_from_nodedev(self, nodedev):
|
2020-11-15 07:14:45 +08:00
|
|
|
log.debug("set_from_nodedev xml=\n%s", nodedev.get_xml())
|
|
|
|
|
2013-09-23 06:13:24 +08:00
|
|
|
if nodedev.device_type == NodeDevice.CAPABILITY_TYPE_PCI:
|
2013-07-16 05:45:43 +08:00
|
|
|
self.type = "pci"
|
|
|
|
self.domain = nodedev.domain
|
2013-03-18 05:06:52 +08:00
|
|
|
self.bus = nodedev.bus
|
2013-07-16 05:45:43 +08:00
|
|
|
self.slot = nodedev.slot
|
|
|
|
self.function = nodedev.function
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-09-23 06:13:24 +08:00
|
|
|
elif nodedev.device_type == NodeDevice.CAPABILITY_TYPE_USBDEV:
|
2013-07-16 05:45:43 +08:00
|
|
|
self.type = "usb"
|
|
|
|
self.vendor = nodedev.vendor_id
|
|
|
|
self.product = nodedev.product_id
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-07-23 19:15:26 +08:00
|
|
|
count = 0
|
|
|
|
for dev in self.conn.fetch_all_nodedevs():
|
|
|
|
if (dev.device_type == NodeDevice.CAPABILITY_TYPE_USBDEV and
|
|
|
|
dev.vendor_id == self.vendor and
|
|
|
|
dev.product_id == self.product):
|
|
|
|
count += 1
|
|
|
|
|
|
|
|
if count > 1:
|
2013-07-16 05:45:43 +08:00
|
|
|
self.bus = nodedev.bus
|
|
|
|
self.device = nodedev.device
|
2013-09-28 06:06:39 +08:00
|
|
|
|
|
|
|
elif nodedev.device_type == nodedev.CAPABILITY_TYPE_NET:
|
2014-09-20 23:30:24 +08:00
|
|
|
founddev = None
|
|
|
|
for checkdev in self.conn.fetch_all_nodedevs():
|
|
|
|
if checkdev.name == nodedev.parent:
|
|
|
|
founddev = checkdev
|
|
|
|
break
|
|
|
|
|
2015-07-23 19:15:26 +08:00
|
|
|
self.set_from_nodedev(founddev)
|
2013-09-28 06:06:39 +08:00
|
|
|
|
2015-04-12 03:52:42 +08:00
|
|
|
elif nodedev.device_type == nodedev.CAPABILITY_TYPE_SCSIDEV:
|
|
|
|
self.type = "scsi"
|
|
|
|
self.scsi_adapter = "scsi_host%s" % nodedev.host
|
|
|
|
self.scsi_bus = nodedev.bus
|
|
|
|
self.scsi_target = nodedev.target
|
|
|
|
self.scsi_unit = nodedev.lun
|
|
|
|
self.managed = False
|
|
|
|
|
2021-04-14 23:18:55 +08:00
|
|
|
elif nodedev.device_type == nodedev.CAPABILITY_TYPE_MDEV:
|
|
|
|
self.type = "mdev"
|
|
|
|
|
|
|
|
if nodedev.type_id == "vfio_ccw-io":
|
|
|
|
self.model = "vfio-ccw"
|
|
|
|
self.managed = "no"
|
|
|
|
|
|
|
|
elif nodedev.type_id == "vfio_ap-passthrough":
|
|
|
|
self.model = "vfio-ap"
|
|
|
|
self.managed = "no"
|
|
|
|
|
|
|
|
elif (re.match("^nvidia-[0-9]{2}", nodedev.type_id) or
|
|
|
|
re.match("^i915-GVTg_V[0-9]_[0-9]", nodedev.type_id)):
|
|
|
|
self.model = "vfio-pci"
|
|
|
|
self.managed = "yes"
|
|
|
|
self.display = "off"
|
|
|
|
self.ramfb = "off"
|
|
|
|
|
|
|
|
else:
|
|
|
|
raise ValueError( # pragma: no cover
|
|
|
|
_("Don't know how to generate nodedev for mdev type id '%s'") %
|
|
|
|
nodedev.type_id)
|
|
|
|
|
2021-06-01 03:54:27 +08:00
|
|
|
self.uuid = nodedev.get_mdev_uuid()
|
2021-04-14 23:18:55 +08:00
|
|
|
|
2013-07-16 05:45:43 +08:00
|
|
|
else:
|
2022-02-12 03:22:48 +08:00
|
|
|
raise ValueError(_("Unsupported node device type '%s'") %
|
|
|
|
nodedev.device_type)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
2013-07-16 05:45:43 +08:00
|
|
|
_XML_PROP_ORDER = ["mode", "type", "managed", "vendor", "product",
|
2021-04-14 23:18:55 +08:00
|
|
|
"domain", "bus", "slot", "function", "model",
|
|
|
|
"display", "ramfb"]
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2018-09-02 08:44:14 +08:00
|
|
|
mode = XMLProperty("./@mode")
|
2013-09-20 01:27:30 +08:00
|
|
|
type = XMLProperty("./@type")
|
2018-09-02 08:44:14 +08:00
|
|
|
managed = XMLProperty("./@managed", is_yesno=True)
|
2021-04-14 23:18:55 +08:00
|
|
|
model = XMLProperty("./@model")
|
|
|
|
display = XMLProperty("./@display")
|
|
|
|
ramfb = XMLProperty("./@ramfb")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-09-20 01:27:30 +08:00
|
|
|
vendor = XMLProperty("./source/vendor/@id")
|
|
|
|
product = XMLProperty("./source/product/@id")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-09-20 01:27:30 +08:00
|
|
|
device = XMLProperty("./source/address/@device")
|
|
|
|
bus = XMLProperty("./source/address/@bus")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2018-09-02 08:44:14 +08:00
|
|
|
domain = XMLProperty("./source/address/@domain")
|
2013-09-20 01:27:30 +08:00
|
|
|
function = XMLProperty("./source/address/@function")
|
|
|
|
slot = XMLProperty("./source/address/@slot")
|
2013-07-24 20:46:55 +08:00
|
|
|
|
2014-01-15 07:09:21 +08:00
|
|
|
driver_name = XMLProperty("./driver/@name")
|
2014-02-11 03:24:22 +08:00
|
|
|
rom_bar = XMLProperty("./rom/@bar", is_onoff=True)
|
2014-01-15 07:09:21 +08:00
|
|
|
|
2015-04-12 03:52:42 +08:00
|
|
|
# type=scsi handling
|
|
|
|
scsi_adapter = XMLProperty("./source/adapter/@name")
|
|
|
|
scsi_bus = XMLProperty("./source/address/@bus", is_int=True)
|
|
|
|
scsi_target = XMLProperty("./source/address/@target", is_int=True)
|
|
|
|
scsi_unit = XMLProperty("./source/address/@unit", is_int=True)
|
2018-06-15 17:29:34 +08:00
|
|
|
|
|
|
|
# type=net handling
|
|
|
|
net_interface = XMLProperty("./source/interface")
|
2018-06-15 17:29:35 +08:00
|
|
|
|
|
|
|
# type=misc handling
|
|
|
|
misc_char = XMLProperty("./source/char")
|
2018-06-15 17:29:36 +08:00
|
|
|
|
|
|
|
# type=misc handling
|
|
|
|
storage_block = XMLProperty("./source/block")
|
2018-09-02 08:44:14 +08:00
|
|
|
|
2021-04-14 23:18:55 +08:00
|
|
|
# type=mdev
|
|
|
|
uuid = XMLProperty("./source/address/@uuid")
|
|
|
|
|
2018-09-02 08:44:14 +08:00
|
|
|
|
|
|
|
##################
|
|
|
|
# Default config #
|
|
|
|
##################
|
|
|
|
|
|
|
|
def set_defaults(self, guest):
|
|
|
|
if self.managed is None:
|
|
|
|
self.managed = self.conn.is_xen() and "no" or "yes"
|
|
|
|
if not self.mode:
|
|
|
|
self.mode = "subsystem"
|