virt-install: add --network hostdev=HOSTDEV

This is a special convenience option for filling in `type=hostdev`
config using the same format of lookup string that can be
passed to `--hostdev`

Fixes: https://github.com/virt-manager/virt-manager/issues/500

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2024-11-11 15:30:25 -05:00
parent 300f934cae
commit afa8231525
6 changed files with 64 additions and 0 deletions

View File

@ -1332,6 +1332,11 @@ Some example suboptions:
This option deprecates -m/--mac, -b/--bridge, and --nonetworks
``hostdev=HOSTDEV``
Use the referenced nodedev device as the source for ``type=hostdev``
as described here: https://libvirt.org/formatdomain.html#pci-passthrough
For ``HOSTDEV`` format, see ``--hostdev`` documentation
GRAPHICS OPTIONS

View File

@ -633,6 +633,20 @@
<address type="pci" domain="0" bus="0" slot="7" function="0"/>
</source>
</interface>
<interface type="hostdev" managed="yes">
<mac address="00:11:22:33:44:55"/>
<model type="virtio"/>
<source>
<address type="pci" domain="0" bus="0" slot="9" function="0"/>
</source>
</interface>
<interface type="hostdev" managed="yes">
<mac address="00:11:22:33:44:55"/>
<model type="virtio"/>
<source>
<address type="pci" domain="0" bus="0" slot="4" function="0"/>
</source>
</interface>
<smartcard mode="passthrough" type="spicevmc"/>
<smartcard mode="host" type="tcp"/>
<smartcard mode="passthrough" type="spicevmc"/>

View File

@ -3589,6 +3589,23 @@ ba</description>
</device>
<!-- End duplicate USB devices -->
<device>
<name>pci_0000_00_09_0</name>
<path>/sys/devices/pci0000:00/0000:00:09.0</path>
<parent>computer</parent>
<driver>
<name>i915</name>
</driver>
<capability type='pci'>
<domain>0</domain>
<bus>0</bus>
<slot>9</slot>
<function>0</function>
<product id='0x191b'>HD Graphics 530</product>
<vendor id='0x8086'>Intel Corporation</vendor>
</capability>
</device>
<device>
<name>pci_0000_00_02_0</name>
<path>/sys/devices/pci0000:00/0000:00:02.0</path>

View File

@ -653,6 +653,8 @@ source.reservations.managed=no,source.reservations.source.type=unix,source.reser
--network model=vmxnet3
--network backend.type=passt,backend.logFile=/tmp/foo.log,portForward0.proto=tcp,portForward0.address=192.168.10.10,portForward0.dev=eth0,portForward0.range0.start=4000,portForward0.range0.end=5000,portForward0.range0.to=10000,portForward0.range0.exclude=no,portForward0.range1.start=6000,portForward1.proto=tcp,portForward1.range0.start=2022,portForward1.range0.to=22
--network type=hostdev,source.address.type=pci,source.address.domain=0x0,source.address.bus=0x00,source.address.slot=0x07,source.address.function=0x0
--network hostdev=pci_0000_00_09_0
--network hostdev=0:0:4.0
--graphics sdl

View File

@ -3913,6 +3913,10 @@ class ParserNetwork(VirtCLIParser):
cb = self._make_find_inst_cb(cliarg, list_propname)
return cb(inst, *args, **kwargs)
def set_hostdev_cb(self, inst, val, virtarg):
val = _lookupNodedevFromString(inst.conn, val)
inst.set_from_nodedev(val)
@classmethod
def _virtcli_class_init(cls):
VirtCLIParser._virtcli_class_init_common(cls)
@ -3942,6 +3946,8 @@ class ParserNetwork(VirtCLIParser):
cls.add_arg("source.address.slot", "source_address.slot")
cls.add_arg("source.address.function", "source_address.function")
cls.add_arg("hostdev", None, cb=cls.set_hostdev_cb, lookup_cb=None)
cls.add_arg("target.dev", "target_dev")
cls.add_arg("model.type", "model")
cls.add_arg("mac.address", "macaddr", cb=cls.set_mac_cb)

View File

@ -8,6 +8,7 @@ import os
import random
from .device import Device, DeviceAddress
from ..nodedev import NodeDevice
from ..logger import log
from ..xmlbuilder import XMLBuilder, XMLChildProperty, XMLProperty
@ -291,6 +292,7 @@ class DeviceInterface(Device):
source_address = XMLChildProperty(_DeviceInterfaceSourceAddress,
is_single=True,
relative_xpath="./source")
managed = XMLProperty("./@managed", is_yesno=True)
portgroup = XMLProperty("./source/@portgroup")
model = XMLProperty("./model/@type")
@ -327,6 +329,24 @@ class DeviceInterface(Device):
self.type = nettype
self.source = source
def set_from_nodedev(self, nodedev):
log.debug("set_from_nodedev xml=\n%s", nodedev.get_xml())
self.type = "hostdev"
if self.managed is None:
self.managed = True
if nodedev.device_type == NodeDevice.CAPABILITY_TYPE_PCI:
self.source_address.type = "pci"
self.source_address.domain = nodedev.domain
self.source_address.bus = nodedev.bus
self.source_address.slot = nodedev.slot
self.source_address.function = nodedev.function
else: # pragma: no cover
raise ValueError(_("Unsupported node device type '%s'") %
nodedev.device_type)
##################
# Default config #