bhyve: Tie the 'passthru' option to the 'hostdev' XML config

Signed-off-by: Alexander Shursha <kekek2@ya.ru>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Alexander Shursha
2025-11-08 10:27:56 +01:00
committed by Roman Bogorodskiy
parent 447252a54c
commit 43579767f4
4 changed files with 96 additions and 0 deletions
+66
View File
@@ -6,6 +6,7 @@
* Copyright (c) 2011 NetApp, Inc.
* Copyright (C) 2020 Fabian Freyer
* Copyright (C) 2025 The FreeBSD Foundation
* Copyright (C) 2024-2025 Future Crew, LLC
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -666,6 +667,69 @@ bhyveParsePCIRND(virDomainDef *def,
return 0;
}
static int
bhyveParsePassthru(virDomainDef *def G_GNUC_UNUSED,
unsigned pcibus,
unsigned pcislot,
unsigned pcifunction,
char *addr)
{
/* -s slot,bus/slot/function */
/* -s slot,pcibus:slot:function */
virDomainHostdevDef *hostdev = NULL;
g_auto(GStrv) params = NULL;
GStrv param;
char *p = NULL;
if (!addr) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("No PCI address provided"));
return -1;
}
hostdev = virDomainHostdevDefNew();
hostdev->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI;
hostdev->info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
hostdev->info->addr.pci.bus = pcibus;
hostdev->info->addr.pci.slot = pcislot;
hostdev->info->addr.pci.function = pcifunction;
if (!(params = g_strsplit(addr, ":", -1))) {
virReportError(VIR_ERR_OPERATION_FAILED, _("Failed to parse PCI address %1$s"), addr);
goto error;
}
if (g_str_equal(addr, *params)) {
g_free(params);
if (!(params = g_strsplit(addr, "/", -1))) {
virReportError(VIR_ERR_OPERATION_FAILED, _("Failed to parse PCI address %1$s"), addr);
goto error;
}
}
if (g_strv_length(params) != 3) {
virReportError(VIR_ERR_OPERATION_FAILED, _("Failed to parse PCI address %1$s"), addr);
goto error;
}
param = params;
if (virStrToLong_uip(*param++, &p, 10, &hostdev->source.subsys.u.pci.addr.bus) < 0 ||
virStrToLong_uip(*param++, &p, 10, &hostdev->source.subsys.u.pci.addr.slot) < 0 ||
virStrToLong_uip(*param++, &p, 10, &hostdev->source.subsys.u.pci.addr.function) < 0) {
virReportError(VIR_ERR_OPERATION_FAILED, _("Failed to parse PCI address %1$s"), addr);
goto error;
}
hostdev->source.subsys.u.pci.addr.domain = 0;
hostdev->managed = false;
VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev);
return 0;
error:
virDomainHostdevDefFree(hostdev);
return -1;
}
static int
bhyveParseBhyvePCIArg(virDomainDef *def,
virDomainXMLOption *xmlopt,
@@ -732,6 +796,8 @@ bhyveParseBhyvePCIArg(virDomainDef *def,
bhyveParsePCIFbuf(def, xmlopt, caps, bus, slot, function, conf);
else if (STREQ(emulation, "virtio-rnd"))
bhyveParsePCIRND(def, xmlopt, caps, bus, slot, function, conf);
else if (STREQ(emulation, "passthru"))
bhyveParsePassthru(def, bus, slot, function, conf);
VIR_FREE(emulation);
VIR_FREE(slotdef);
@@ -0,0 +1,7 @@
/usr/sbin/bhyve \
-c 1 \
-m 214 \
-H \
-P \
-s 0:0,hostbridge \
-s 7,passthru,3/0/0 bhyve
@@ -0,0 +1,22 @@
<domain type='bhyve'>
<name>bhyve</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>219136</memory>
<currentMemory unit='KiB'>219136</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
<type>hvm</type>
</os>
<clock offset='localtime'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>destroy</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<hostdev mode='subsystem' type='pci' managed='no'>
<source>
<address domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
</source>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</hostdev>
</devices>
</domain>
+1
View File
@@ -161,6 +161,7 @@ mymain(void)
DO_TEST("virtio-blk");
DO_TEST("virtio-net");
DO_TEST("e1000");
DO_TEST("passthru");
DO_TEST_WARN("virtio-net2");
DO_TEST_WARN("virtio-net3");
DO_TEST_WARN("virtio-net4");