提交 aad479dc 编写于 作者: R Roman Bogorodskiy

bhyve: implement PCI address allocation

Automatically allocate PCI addresses for devices instead
of hardcoding them in the driver code. The current
allocation schema is to dedicate an entire slot for each devices.

Also, allow having arbitrary number of devices.
上级 90ba5ef1
...@@ -9,6 +9,7 @@ gnulib/lib/regcomp.c ...@@ -9,6 +9,7 @@ gnulib/lib/regcomp.c
src/access/viraccessdriverpolkit.c src/access/viraccessdriverpolkit.c
src/access/viraccessmanager.c src/access/viraccessmanager.c
src/bhyve/bhyve_command.c src/bhyve/bhyve_command.c
src/bhyve/bhyve_device.c
src/bhyve/bhyve_driver.c src/bhyve/bhyve_driver.c
src/bhyve/bhyve_process.c src/bhyve/bhyve_process.c
src/conf/capabilities.c src/conf/capabilities.c
......
...@@ -789,6 +789,10 @@ BHYVE_DRIVER_SOURCES = \ ...@@ -789,6 +789,10 @@ BHYVE_DRIVER_SOURCES = \
bhyve/bhyve_capabilities.h \ bhyve/bhyve_capabilities.h \
bhyve/bhyve_command.c \ bhyve/bhyve_command.c \
bhyve/bhyve_command.h \ bhyve/bhyve_command.h \
bhyve/bhyve_device.c \
bhyve/bhyve_device.h \
bhyve/bhyve_domain.c \
bhyve/bhyve_domain.h \
bhyve/bhyve_driver.h \ bhyve/bhyve_driver.h \
bhyve/bhyve_driver.c \ bhyve/bhyve_driver.c \
bhyve/bhyve_process.c \ bhyve/bhyve_process.c \
......
...@@ -39,23 +39,15 @@ ...@@ -39,23 +39,15 @@
VIR_LOG_INIT("bhyve.bhyve_command"); VIR_LOG_INIT("bhyve.bhyve_command");
static int static int
bhyveBuildNetArgStr(const virDomainDef *def, virCommandPtr cmd, bool dryRun) bhyveBuildNetArgStr(const virDomainDef *def,
virDomainNetDefPtr net,
virCommandPtr cmd,
bool dryRun)
{ {
virDomainNetDefPtr net = NULL; char macaddr[VIR_MAC_STRING_BUFLEN];
char *brname = NULL;
char *realifname = NULL; char *realifname = NULL;
int *tapfd = NULL; int *tapfd = NULL;
char macaddr[VIR_MAC_STRING_BUFLEN]; char *brname = NULL;
if (def->nnets != 1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("domain should have one and only one net defined"));
return -1;
}
net = def->nets[0];
if (net) {
int actualType = virDomainNetGetActualType(net); int actualType = virDomainNetGetActualType(net);
if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) { if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
...@@ -78,7 +70,7 @@ bhyveBuildNetArgStr(const virDomainDef *def, virCommandPtr cmd, bool dryRun) ...@@ -78,7 +70,7 @@ bhyveBuildNetArgStr(const virDomainDef *def, virCommandPtr cmd, bool dryRun)
} }
} }
if (!dryRun) if (!dryRun) {
if (virNetDevTapCreateInBridgePort(brname, &net->ifname, &net->mac, if (virNetDevTapCreateInBridgePort(brname, &net->ifname, &net->mac,
def->uuid, tapfd, 1, def->uuid, tapfd, 1,
virDomainNetGetActualVirtPortProfile(net), virDomainNetGetActualVirtPortProfile(net),
...@@ -88,9 +80,7 @@ bhyveBuildNetArgStr(const virDomainDef *def, virCommandPtr cmd, bool dryRun) ...@@ -88,9 +80,7 @@ bhyveBuildNetArgStr(const virDomainDef *def, virCommandPtr cmd, bool dryRun)
VIR_FREE(brname); VIR_FREE(brname);
return -1; return -1;
} }
}
if (!dryRun) {
realifname = virNetDevTapGetRealDeviceName(net->ifname); realifname = virNetDevTapGetRealDeviceName(net->ifname);
if (realifname == NULL) { if (realifname == NULL) {
...@@ -105,6 +95,7 @@ bhyveBuildNetArgStr(const virDomainDef *def, virCommandPtr cmd, bool dryRun) ...@@ -105,6 +95,7 @@ bhyveBuildNetArgStr(const virDomainDef *def, virCommandPtr cmd, bool dryRun)
* name * name
*/ */
if (virNetDevSetOnline(net->ifname, true) != 0) { if (virNetDevSetOnline(net->ifname, true) != 0) {
VIR_FREE(realifname);
VIR_FREE(net->ifname); VIR_FREE(net->ifname);
VIR_FREE(brname); VIR_FREE(brname);
return -1; return -1;
...@@ -116,8 +107,10 @@ bhyveBuildNetArgStr(const virDomainDef *def, virCommandPtr cmd, bool dryRun) ...@@ -116,8 +107,10 @@ bhyveBuildNetArgStr(const virDomainDef *def, virCommandPtr cmd, bool dryRun)
virCommandAddArg(cmd, "-s"); virCommandAddArg(cmd, "-s");
virCommandAddArgFormat(cmd, "1:0,virtio-net,%s,mac=%s", virCommandAddArgFormat(cmd, "%d:0,virtio-net,%s,mac=%s",
net->info.addr.pci.slot,
realifname, virMacAddrFormat(&net->mac, macaddr)); realifname, virMacAddrFormat(&net->mac, macaddr));
VIR_FREE(realifname);
return 0; return 0;
} }
...@@ -146,7 +139,7 @@ bhyveBuildConsoleArgStr(const virDomainDef *def, virCommandPtr cmd) ...@@ -146,7 +139,7 @@ bhyveBuildConsoleArgStr(const virDomainDef *def, virCommandPtr cmd)
return -1; return -1;
} }
virCommandAddArgList(cmd, "-s", "31,lpc", NULL); virCommandAddArgList(cmd, "-s", "1,lpc", NULL);
virCommandAddArg(cmd, "-l"); virCommandAddArg(cmd, "-l");
virCommandAddArgFormat(cmd, "com%d,%s", virCommandAddArgFormat(cmd, "com%d,%s",
chr->target.port + 1, chr->source.data.file.path); chr->target.port + 1, chr->source.data.file.path);
...@@ -155,19 +148,12 @@ bhyveBuildConsoleArgStr(const virDomainDef *def, virCommandPtr cmd) ...@@ -155,19 +148,12 @@ bhyveBuildConsoleArgStr(const virDomainDef *def, virCommandPtr cmd)
} }
static int static int
bhyveBuildDiskArgStr(const virDomainDef *def, virCommandPtr cmd) bhyveBuildDiskArgStr(const virDomainDef *def ATTRIBUTE_UNUSED,
virDomainDiskDefPtr disk,
virCommandPtr cmd)
{ {
virDomainDiskDefPtr disk;
const char *bus_type; const char *bus_type;
if (def->ndisks != 1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("domain should have one and only one disk defined"));
return -1;
}
disk = def->disks[0];
switch (disk->bus) { switch (disk->bus) {
case VIR_DOMAIN_DISK_BUS_SATA: case VIR_DOMAIN_DISK_BUS_SATA:
bus_type = "ahci-hd"; bus_type = "ahci-hd";
...@@ -194,7 +180,8 @@ bhyveBuildDiskArgStr(const virDomainDef *def, virCommandPtr cmd) ...@@ -194,7 +180,8 @@ bhyveBuildDiskArgStr(const virDomainDef *def, virCommandPtr cmd)
} }
virCommandAddArg(cmd, "-s"); virCommandAddArg(cmd, "-s");
virCommandAddArgFormat(cmd, "2:0,%s,%s", bus_type, virCommandAddArgFormat(cmd, "%d:0,%s,%s",
disk->info.addr.pci.slot, bus_type,
virDomainDiskGetSource(disk)); virDomainDiskGetSource(disk));
return 0; return 0;
...@@ -212,6 +199,8 @@ virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver ATTRIBUTE_UNUSED, ...@@ -212,6 +199,8 @@ virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver ATTRIBUTE_UNUSED,
* -S 31,uart,stdio \ * -S 31,uart,stdio \
* vm0 * vm0
*/ */
size_t i;
virCommandPtr cmd = virCommandNew(BHYVE); virCommandPtr cmd = virCommandNew(BHYVE);
/* CPUs */ /* CPUs */
...@@ -245,10 +234,17 @@ virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver ATTRIBUTE_UNUSED, ...@@ -245,10 +234,17 @@ virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver ATTRIBUTE_UNUSED,
virCommandAddArgList(cmd, "-s", "0:0,hostbridge", NULL); virCommandAddArgList(cmd, "-s", "0:0,hostbridge", NULL);
/* Devices */ /* Devices */
if (bhyveBuildNetArgStr(def, cmd, dryRun) < 0) for (i = 0; i < def->nnets; i++) {
virDomainNetDefPtr net = def->nets[i];
if (bhyveBuildNetArgStr(def, net, cmd, dryRun) < 0)
goto error; goto error;
if (bhyveBuildDiskArgStr(def, cmd) < 0) }
for (i = 0; i < def->ndisks; i++) {
virDomainDiskDefPtr disk = def->disks[i];
if (bhyveBuildDiskArgStr(def, disk, cmd) < 0)
goto error; goto error;
}
if (bhyveBuildConsoleArgStr(def, cmd) < 0) if (bhyveBuildConsoleArgStr(def, cmd) < 0)
goto error; goto error;
virCommandAddArg(cmd, def->name); virCommandAddArg(cmd, def->name);
...@@ -279,9 +275,9 @@ virBhyveProcessBuildLoadCmd(bhyveConnPtr driver ATTRIBUTE_UNUSED, ...@@ -279,9 +275,9 @@ virBhyveProcessBuildLoadCmd(bhyveConnPtr driver ATTRIBUTE_UNUSED,
virCommandPtr cmd; virCommandPtr cmd;
virDomainDiskDefPtr disk; virDomainDiskDefPtr disk;
if (def->ndisks != 1) { if (def->ndisks < 1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("domain should have one and only one disk defined")); _("domain should have at least one disk defined"));
return NULL; return NULL;
} }
......
/*
* bhyve_device.c: bhyve device management
*
* Copyright (C) 2014 Roman Bogorodskiy
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
* Author: Roman Bogorodskiy
*/
#include <config.h>
#include "bhyve_device.h"
#include "domain_addr.h"
#include "viralloc.h"
#include "virlog.h"
#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_BHYVE
VIR_LOG_INIT("bhyve.bhyve_device");
static int
bhyveCollectPCIAddress(virDomainDefPtr def ATTRIBUTE_UNUSED,
virDomainDeviceDefPtr device ATTRIBUTE_UNUSED,
virDomainDeviceInfoPtr info,
void *opaque)
{
int ret = -1;
virDomainPCIAddressSetPtr addrs = opaque;
virDevicePCIAddressPtr addr = &info->addr.pci;
if (addr->domain == 0 && addr->bus == 0) {
if (addr->slot == 0) {
return 0;
} else if (addr->slot == 1) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("PCI bus 0 slot 1 is reserved for the implicit "
"LPC PCI-ISA bridge"));
return -1;
}
}
if (virDomainPCIAddressReserveSlot(addrs, addr, VIR_PCI_CONNECT_TYPE_PCI) < 0)
goto cleanup;
ret = 0;
cleanup:
return ret;
}
virDomainPCIAddressSetPtr
bhyveDomainPCIAddressSetCreate(virDomainDefPtr def ATTRIBUTE_UNUSED, unsigned int nbuses)
{
virDomainPCIAddressSetPtr addrs;
if ((addrs = virDomainPCIAddressSetAlloc(nbuses)) == NULL)
return NULL;
if (virDomainPCIAddressBusSetModel(&addrs->buses[0],
VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) < 0)
goto error;
if (virDomainDeviceInfoIterate(def, bhyveCollectPCIAddress, addrs) < 0)
goto error;
return addrs;
error:
virDomainPCIAddressSetFree(addrs);
return NULL;
}
static int
bhyveAssignDevicePCISlots(virDomainDefPtr def,
virDomainPCIAddressSetPtr addrs)
{
size_t i;
virDevicePCIAddress lpc_addr;
/* explicitly reserve slot 1 for LPC-ISA bridge */
memset(&lpc_addr, 0, sizeof(lpc_addr));
lpc_addr.slot = 0x1;
if (virDomainPCIAddressReserveSlot(addrs, &lpc_addr, VIR_PCI_CONNECT_TYPE_PCI) < 0)
goto error;
for (i = 0; i < def->nnets; i++) {
if (def->nets[i]->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
continue;
if (virDomainPCIAddressReserveNextSlot(addrs,
&def->nets[i]->info,
VIR_PCI_CONNECT_TYPE_PCI) < 0)
goto error;
}
for (i = 0; i < def->ndisks; i++) {
if (def->disks[i]->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
def->disks[i]->info.addr.pci.slot != 0)
continue;
if (virDomainPCIAddressReserveNextSlot(addrs,
&def->disks[i]->info,
VIR_PCI_CONNECT_TYPE_PCI) < 0)
goto error;
}
for (i = 0; i < def->ncontrollers; i++) {
if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) {
if (def->controllers[i]->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
continue;
if (def->controllers[i]->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT)
continue;
if (virDomainPCIAddressReserveNextSlot(addrs,
&def->controllers[i]->info,
VIR_PCI_CONNECT_TYPE_PCI) < 0)
goto error;
}
}
return 0;
error:
return -1;
}
int bhyveDomainAssignPCIAddresses(virDomainDefPtr def,
virDomainObjPtr obj)
{
virDomainPCIAddressSetPtr addrs = NULL;
bhyveDomainObjPrivatePtr priv = NULL;
int ret = -1;
if (!(addrs = bhyveDomainPCIAddressSetCreate(def, 1)))
goto cleanup;
if (bhyveAssignDevicePCISlots(def, addrs) < 0)
goto cleanup;
if (obj && obj->privateData) {
priv = obj->privateData;
if (addrs) {
virDomainPCIAddressSetFree(priv->pciaddrs);
priv->persistentAddrs = 1;
priv->pciaddrs = addrs;
} else {
priv->persistentAddrs = 0;
}
}
ret = 0;
cleanup:
return ret;
}
int bhyveDomainAssignAddresses(virDomainDefPtr def, virDomainObjPtr obj)
{
return bhyveDomainAssignPCIAddresses(def, obj);
}
/*
* bhyve_device.h: bhyve device management headers
*
* Copyright (C) 2014 Roman Bogorodskiy
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
* Author: Roman Bogorodskiy
*/
#ifndef __BHYVE_DEVICE_H__
# define __BHYVE_DEVICE_H__
# include "domain_conf.h"
# include "virpci.h"
# include "bhyve_domain.h"
int bhyveDomainAssignPCIAddresses(virDomainDefPtr def, virDomainObjPtr obj);
virDomainPCIAddressSetPtr bhyveDomainPCIAddressSetCreate(virDomainDefPtr def,
unsigned int nbuses);
int bhyveDomainAssignAddresses(virDomainDefPtr def, virDomainObjPtr obj)
ATTRIBUTE_NONNULL(1);
#endif /* __BHYVE_DEVICE_H__ */
/*
* bhyve_domain.c: bhyve domain private state
*
* Copyright (C) 2014 Roman Bogorodskiy
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
* Author: Roman Bogorodskiy
*/
#include <config.h>
#include "bhyve_device.h"
#include "bhyve_domain.h"
#include "viralloc.h"
#include "virlog.h"
#define VIR_FROM_THIS VIR_FROM_BHYVE
VIR_LOG_INIT("bhyve.bhyve_domain");
static void *
bhyveDomainObjPrivateAlloc(void)
{
bhyveDomainObjPrivatePtr priv;
if (VIR_ALLOC(priv) < 0)
return NULL;
return priv;
}
static void
bhyveDomainObjPrivateFree(void *data)
{
bhyveDomainObjPrivatePtr priv = data;
virDomainPCIAddressSetFree(priv->pciaddrs);
VIR_FREE(priv);
}
virDomainXMLPrivateDataCallbacks virBhyveDriverPrivateDataCallbacks = {
.alloc = bhyveDomainObjPrivateAlloc,
.free = bhyveDomainObjPrivateFree,
};
static int
bhyveDomainDefPostParse(virDomainDefPtr def,
virCapsPtr caps ATTRIBUTE_UNUSED,
void *opaque ATTRIBUTE_UNUSED)
{
/* Add an implicit PCI root controller */
if (virDomainDefMaybeAddController(def, VIR_DOMAIN_CONTROLLER_TYPE_PCI, 0,
VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) < 0)
return -1;
return 0;
}
virDomainDefParserConfig virBhyveDriverDomainDefParserConfig = {
.domainPostParseCallback = bhyveDomainDefPostParse,
};
/*
* bhyve_domain.h: bhyve domain private state headers
*
* Copyright (C) 2014 Roman Bogorodskiy
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
* Author: Roman Bogorodskiy
*/
#ifndef __BHYVE_DOMAIN_H__
# define __BHYVE_DOMAIN_H__
# include "domain_addr.h"
# include "domain_conf.h"
typedef struct _bhyveDomainObjPrivate bhyveDomainObjPrivate;
typedef bhyveDomainObjPrivate *bhyveDomainObjPrivatePtr;
struct _bhyveDomainObjPrivate {
virDomainPCIAddressSetPtr pciaddrs;
bool persistentAddrs;
};
extern virDomainXMLPrivateDataCallbacks virBhyveDriverPrivateDataCallbacks;
extern virDomainDefParserConfig virBhyveDriverDomainDefParserConfig;
#endif /* __BHYVE_DOMAIN_H__ */
...@@ -53,8 +53,10 @@ ...@@ -53,8 +53,10 @@
#include "viraccessapicheck.h" #include "viraccessapicheck.h"
#include "nodeinfo.h" #include "nodeinfo.h"
#include "bhyve_device.h"
#include "bhyve_driver.h" #include "bhyve_driver.h"
#include "bhyve_command.h" #include "bhyve_command.h"
#include "bhyve_domain.h"
#include "bhyve_process.h" #include "bhyve_process.h"
#include "bhyve_utils.h" #include "bhyve_utils.h"
#include "bhyve_capabilities.h" #include "bhyve_capabilities.h"
...@@ -509,6 +511,9 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml) ...@@ -509,6 +511,9 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml)
if (virDomainDefineXMLEnsureACL(conn, def) < 0) if (virDomainDefineXMLEnsureACL(conn, def) < 0)
goto cleanup; goto cleanup;
if (bhyveDomainAssignAddresses(def, NULL) < 0)
goto cleanup;
if (!(vm = virDomainObjListAdd(privconn->domains, def, if (!(vm = virDomainObjListAdd(privconn->domains, def,
privconn->xmlopt, privconn->xmlopt,
0, &oldDef))) 0, &oldDef)))
...@@ -685,6 +690,9 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn, ...@@ -685,6 +690,9 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn,
VIR_DOMAIN_XML_INACTIVE))) VIR_DOMAIN_XML_INACTIVE)))
goto cleanup; goto cleanup;
if (bhyveDomainAssignAddresses(def, NULL) < 0)
goto cleanup;
if (!(loadcmd = virBhyveProcessBuildLoadCmd(privconn, def))) if (!(loadcmd = virBhyveProcessBuildLoadCmd(privconn, def)))
goto cleanup; goto cleanup;
...@@ -897,6 +905,9 @@ bhyveDomainCreateXML(virConnectPtr conn, ...@@ -897,6 +905,9 @@ bhyveDomainCreateXML(virConnectPtr conn,
if (virDomainCreateXMLEnsureACL(conn, def) < 0) if (virDomainCreateXMLEnsureACL(conn, def) < 0)
goto cleanup; goto cleanup;
if (bhyveDomainAssignAddresses(def, NULL) < 0)
goto cleanup;
if (!(vm = virDomainObjListAdd(privconn->domains, def, if (!(vm = virDomainObjListAdd(privconn->domains, def,
privconn->xmlopt, privconn->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL)))
...@@ -1160,7 +1171,9 @@ bhyveStateInitialize(bool priveleged ATTRIBUTE_UNUSED, ...@@ -1160,7 +1171,9 @@ bhyveStateInitialize(bool priveleged ATTRIBUTE_UNUSED,
if (!(bhyve_driver->caps = virBhyveCapsBuild())) if (!(bhyve_driver->caps = virBhyveCapsBuild()))
goto cleanup; goto cleanup;
if (!(bhyve_driver->xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL))) if (!(bhyve_driver->xmlopt = virDomainXMLOptionNew(&virBhyveDriverDomainDefParserConfig,
&virBhyveDriverPrivateDataCallbacks,
NULL)))
goto cleanup; goto cleanup;
if (!(bhyve_driver->domains = virDomainObjListNew())) if (!(bhyve_driver->domains = virDomainObjListNew()))
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <net/if.h> #include <net/if.h>
#include <net/if_tap.h> #include <net/if_tap.h>
#include "bhyve_device.h"
#include "bhyve_process.h" #include "bhyve_process.h"
#include "bhyve_command.h" #include "bhyve_command.h"
#include "datatypes.h" #include "datatypes.h"
...@@ -130,6 +131,9 @@ virBhyveProcessStart(virConnectPtr conn, ...@@ -130,6 +131,9 @@ virBhyveProcessStart(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
if (bhyveDomainAssignAddresses(vm->def, NULL) < 0)
goto cleanup;
/* Call bhyve to start the VM */ /* Call bhyve to start the VM */
if (!(cmd = virBhyveProcessBuildBhyveCmd(driver, if (!(cmd = virBhyveProcessBuildBhyveCmd(driver,
vm->def, vm->def,
......
/usr/sbin/bhyve -c 1 -m 214 -A -I -H -P -s 0:0,hostbridge \ /usr/sbin/bhyve -c 1 -m 214 -A -I -H -P -s 0:0,hostbridge \
-s 1:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \ -s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
-s 2:0,ahci-hd,/tmp/freebsd.img bhyve -s 2:0,ahci-hd,/tmp/freebsd.img bhyve
...@@ -15,10 +15,12 @@ ...@@ -15,10 +15,12 @@
<driver name='file' type='raw'/> <driver name='file' type='raw'/>
<source file='/tmp/freebsd.img'/> <source file='/tmp/freebsd.img'/>
<target dev='hda' bus='sata'/> <target dev='hda' bus='sata'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</disk> </disk>
<interface type='bridge'> <interface type='bridge'>
<model type='virtio'/> <model type='virtio'/>
<source bridge="virbr0"/> <source bridge="virbr0"/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface> </interface>
</devices> </devices>
</domain> </domain>
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \ /usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
-s 1:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \ -s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
-s 2:0,ahci-hd,/tmp/freebsd.img bhyve -s 2:0,ahci-hd,/tmp/freebsd.img bhyve
...@@ -11,10 +11,12 @@ ...@@ -11,10 +11,12 @@
<driver name='file' type='raw'/> <driver name='file' type='raw'/>
<source file='/tmp/freebsd.img'/> <source file='/tmp/freebsd.img'/>
<target dev='hda' bus='sata'/> <target dev='hda' bus='sata'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</disk> </disk>
<interface type='bridge'> <interface type='bridge'>
<model type='virtio'/> <model type='virtio'/>
<source bridge="virbr0"/> <source bridge="virbr0"/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface> </interface>
</devices> </devices>
</domain> </domain>
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \ /usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
-s 1:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \ -s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
-s 2:0,ahci-hd,/tmp/freebsd.img \ -s 2:0,ahci-hd,/tmp/freebsd.img \
-s 31,lpc -l com1,/dev/nmdm0A bhyve -s 1,lpc -l com1,/dev/nmdm0A bhyve
...@@ -11,10 +11,12 @@ ...@@ -11,10 +11,12 @@
<driver name='file' type='raw'/> <driver name='file' type='raw'/>
<source file='/tmp/freebsd.img'/> <source file='/tmp/freebsd.img'/>
<target dev='hda' bus='sata'/> <target dev='hda' bus='sata'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</disk> </disk>
<interface type='bridge'> <interface type='bridge'>
<model type='virtio'/> <model type='virtio'/>
<source bridge="virbr0"/> <source bridge="virbr0"/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface> </interface>
<console type='nmdm'> <console type='nmdm'>
<source master='/dev/nmdm0A' slave='/dev/nmdm0B'/> <source master='/dev/nmdm0A' slave='/dev/nmdm0B'/>
......
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \ /usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
-s 1:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \ -s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
-s 2:0,virtio-blk,/tmp/freebsd.img bhyve -s 2:0,virtio-blk,/tmp/freebsd.img bhyve
...@@ -11,10 +11,12 @@ ...@@ -11,10 +11,12 @@
<driver name='file' type='raw'/> <driver name='file' type='raw'/>
<source file='/tmp/freebsd.img'/> <source file='/tmp/freebsd.img'/>
<target dev='vda' bus='virtio'/> <target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</disk> </disk>
<interface type='bridge'> <interface type='bridge'>
<model type='virtio'/> <model type='virtio'/>
<source bridge="virbr0"/> <source bridge="virbr0"/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface> </interface>
</devices> </devices>
</domain> </domain>
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \ /usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
-s 1:0,virtio-net,faketapdev,mac=52:54:00:22:ee:11 \ -s 3:0,virtio-net,faketapdev,mac=52:54:00:22:ee:11 \
-s 2:0,ahci-hd,/tmp/freebsd.img bhyve -s 2:0,ahci-hd,/tmp/freebsd.img bhyve
...@@ -11,11 +11,13 @@ ...@@ -11,11 +11,13 @@
<driver name='file' type='raw'/> <driver name='file' type='raw'/>
<source file='/tmp/freebsd.img'/> <source file='/tmp/freebsd.img'/>
<target dev='hda' bus='sata'/> <target dev='hda' bus='sata'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</disk> </disk>
<interface type='bridge'> <interface type='bridge'>
<mac address="52:54:00:22:ee:11"/> <mac address="52:54:00:22:ee:11"/>
<model type='virtio'/> <model type='virtio'/>
<source bridge="virbr0"/> <source bridge="virbr0"/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface> </interface>
</devices> </devices>
</domain> </domain>
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \ /usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
-s 1:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \ -s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
-s 2:0,ahci-hd,/tmp/freebsd.img \ -s 2:0,ahci-hd,/tmp/freebsd.img \
-s 31,lpc -l com1,/dev/nmdm0A bhyve -s 1,lpc -l com1,/dev/nmdm0A bhyve
...@@ -11,10 +11,12 @@ ...@@ -11,10 +11,12 @@
<driver name='file' type='raw'/> <driver name='file' type='raw'/>
<source file='/tmp/freebsd.img'/> <source file='/tmp/freebsd.img'/>
<target dev='hda' bus='sata'/> <target dev='hda' bus='sata'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</disk> </disk>
<interface type='bridge'> <interface type='bridge'>
<model type='virtio'/> <model type='virtio'/>
<source bridge="virbr0"/> <source bridge="virbr0"/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface> </interface>
<serial type='nmdm'> <serial type='nmdm'>
<source master='/dev/nmdm0A' slave='/dev/nmdm0B'/> <source master='/dev/nmdm0A' slave='/dev/nmdm0B'/>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册