*
* Copyright (C) 2014 Roman Bogorodskiy
* 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
return 0;
}
+static int
+bhyveBuildHostdevArgStr(const virDomainDef *def,
+ virCommand *cmd)
+{
+ size_t i;
+
+ for (i = 0; i < def->nhostdevs; i++) {
+ virDomainHostdevDef *hostdev = def->hostdevs[i];
+ virDomainHostdevSubsys *subsys = &hostdev->source.subsys;
+
+ if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
+ subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
+ continue;
+ }
+
+ virCommandAddArg(cmd, "-s");
+ virCommandAddArgFormat(cmd, "%d:%d,passthru,%d/%d/%d",
+ hostdev->info->addr.pci.slot,
+ hostdev->info->addr.pci.function,
+ subsys->u.pci.addr.bus,
+ subsys->u.pci.addr.slot,
+ subsys->u.pci.addr.function);
+ }
+
+ return 0;
+}
+
static int
bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
virDomainControllerDef *controller,
virCommandAddArg(cmd, bhyvecmd->args[i]);
}
+ if (bhyveBuildHostdevArgStr(def, cmd) < 0)
+ return NULL;
+
virCommandAddArg(cmd, def->name);
return g_steal_pointer(&cmd);
--- /dev/null
+<domain type='bhyve'>
+ <name>bhyve</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219136</memory>
+ <currentMemory unit='KiB'>219136</currentMemory>
+ <memoryBacking>
+ <locked/>
+ </memoryBacking>
+ <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>
+ <disk type='file'>
+ <driver name='file' type='raw'/>
+ <source file='/tmp/freebsd.img'/>
+ <target dev='hda' bus='sata'/>
+ <address type='drive' controller='0' bus='0' target='2' unit='0'/>
+ </disk>
+ <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>