2014-02-18 10:08:10 +00:00
|
|
|
/*
|
|
|
|
* bhyve_driver.c: core driver methods for managing bhyve guests
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Roman Bogorodskiy
|
2015-01-15 14:02:44 +00:00
|
|
|
* Copyright (C) 2014-2015 Red Hat, Inc.
|
2014-02-18 10:08:10 +00:00
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
2014-03-15 12:30:01 +00:00
|
|
|
#include <fcntl.h>
|
2014-02-18 10:08:10 +00:00
|
|
|
#include <sys/utsname.h>
|
|
|
|
|
|
|
|
#include "virerror.h"
|
|
|
|
#include "datatypes.h"
|
|
|
|
#include "virbuffer.h"
|
|
|
|
#include "viruuid.h"
|
|
|
|
#include "configmake.h"
|
|
|
|
#include "viralloc.h"
|
|
|
|
#include "network_conf.h"
|
|
|
|
#include "interface_conf.h"
|
|
|
|
#include "domain_audit.h"
|
2014-04-23 11:55:05 +00:00
|
|
|
#include "domain_event.h"
|
2014-02-18 10:08:10 +00:00
|
|
|
#include "snapshot_conf.h"
|
2017-03-07 09:34:47 +00:00
|
|
|
#include "virfdstream.h"
|
2014-02-18 10:08:10 +00:00
|
|
|
#include "storage_conf.h"
|
|
|
|
#include "node_device_conf.h"
|
2015-07-17 09:11:23 +00:00
|
|
|
#include "virdomainobjlist.h"
|
2014-02-18 10:08:10 +00:00
|
|
|
#include "virxml.h"
|
|
|
|
#include "virthread.h"
|
|
|
|
#include "virlog.h"
|
|
|
|
#include "virfile.h"
|
|
|
|
#include "virtypedparam.h"
|
|
|
|
#include "virrandom.h"
|
|
|
|
#include "virstring.h"
|
|
|
|
#include "cpu/cpu.h"
|
|
|
|
#include "viraccessapicheck.h"
|
2016-06-12 07:56:11 +00:00
|
|
|
#include "virhostcpu.h"
|
|
|
|
#include "virhostmem.h"
|
2017-05-08 10:36:43 +00:00
|
|
|
#include "virportallocator.h"
|
2016-07-08 18:53:33 +00:00
|
|
|
#include "conf/domain_capabilities.h"
|
2014-02-18 10:08:10 +00:00
|
|
|
|
2017-03-11 16:19:03 +00:00
|
|
|
#include "bhyve_conf.h"
|
2014-04-12 19:37:53 +00:00
|
|
|
#include "bhyve_device.h"
|
2014-02-18 10:08:10 +00:00
|
|
|
#include "bhyve_driver.h"
|
2014-04-13 09:48:17 +00:00
|
|
|
#include "bhyve_command.h"
|
2016-06-01 07:57:43 +00:00
|
|
|
#include "bhyve_parse_command.h"
|
2014-04-12 19:37:53 +00:00
|
|
|
#include "bhyve_domain.h"
|
2014-02-18 10:08:10 +00:00
|
|
|
#include "bhyve_process.h"
|
2014-04-07 05:06:40 +00:00
|
|
|
#include "bhyve_capabilities.h"
|
2014-02-18 10:08:10 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_BHYVE
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("bhyve.bhyve_driver");
|
|
|
|
|
2014-02-18 10:08:10 +00:00
|
|
|
bhyveConnPtr bhyve_driver = NULL;
|
|
|
|
|
|
|
|
void
|
|
|
|
bhyveDriverLock(bhyveConnPtr driver)
|
|
|
|
{
|
|
|
|
virMutexLock(&driver->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bhyveDriverUnlock(bhyveConnPtr driver)
|
|
|
|
{
|
|
|
|
virMutexUnlock(&driver->lock);
|
|
|
|
}
|
|
|
|
|
2014-03-23 09:16:09 +00:00
|
|
|
static int
|
|
|
|
bhyveAutostartDomain(virDomainObjPtr vm, void *opaque)
|
|
|
|
{
|
|
|
|
const struct bhyveAutostartData *data = opaque;
|
|
|
|
int ret = 0;
|
|
|
|
virObjectLock(vm);
|
|
|
|
if (vm->autostart && !virDomainObjIsActive(vm)) {
|
|
|
|
virResetLastError();
|
|
|
|
ret = virBhyveProcessStart(data->conn, data->driver, vm,
|
|
|
|
VIR_DOMAIN_RUNNING_BOOTED, 0);
|
|
|
|
if (ret < 0) {
|
2016-05-23 18:35:56 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Failed to autostart VM '%s': %s"),
|
|
|
|
vm->def->name, virGetLastErrorMessage());
|
2014-03-23 09:16:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bhyveAutostartDomains(bhyveConnPtr driver)
|
|
|
|
{
|
|
|
|
/* XXX: Figure out a better way todo this. The domain
|
|
|
|
* startup code needs a connection handle in order
|
|
|
|
* to lookup the bridge associated with a virtual
|
|
|
|
* network
|
|
|
|
*/
|
|
|
|
virConnectPtr conn = virConnectOpen("bhyve:///system");
|
|
|
|
/* Ignoring NULL conn which is mostly harmless here */
|
|
|
|
|
|
|
|
struct bhyveAutostartData data = { driver, conn };
|
|
|
|
|
|
|
|
virDomainObjListForEach(driver->domains, bhyveAutostartDomain, &data);
|
|
|
|
|
|
|
|
virObjectUnref(conn);
|
|
|
|
}
|
|
|
|
|
2014-04-07 05:06:40 +00:00
|
|
|
/**
|
|
|
|
* bhyveDriverGetCapabilities:
|
|
|
|
*
|
|
|
|
* Get a reference to the virCapsPtr instance for the
|
|
|
|
* driver.
|
|
|
|
*
|
|
|
|
* The caller must release the reference with virObjetUnref
|
|
|
|
*
|
|
|
|
* Returns: a reference to a virCapsPtr instance or NULL
|
|
|
|
*/
|
2016-02-05 21:36:42 +00:00
|
|
|
virCapsPtr ATTRIBUTE_NONNULL(1)
|
2014-04-08 16:30:23 +00:00
|
|
|
bhyveDriverGetCapabilities(bhyveConnPtr driver)
|
2014-02-18 10:08:10 +00:00
|
|
|
{
|
|
|
|
|
2014-04-07 15:25:49 +00:00
|
|
|
return virObjectRef(driver->caps);
|
2014-02-18 10:08:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
bhyveConnectGetCapabilities(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = conn->privateData;
|
2014-04-07 05:06:40 +00:00
|
|
|
virCapsPtr caps;
|
2014-04-07 15:29:18 +00:00
|
|
|
char *xml = NULL;
|
2014-02-18 10:08:10 +00:00
|
|
|
|
|
|
|
if (virConnectGetCapabilitiesEnsureACL(conn) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2014-04-07 15:29:18 +00:00
|
|
|
if (!(caps = bhyveDriverGetCapabilities(privconn))) {
|
2014-04-07 05:06:40 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Unable to get Capabilities"));
|
2014-04-07 15:29:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-04-07 05:06:40 +00:00
|
|
|
|
2014-06-27 07:55:44 +00:00
|
|
|
if (!(xml = virCapabilitiesFormatXML(caps)))
|
2014-04-07 15:29:18 +00:00
|
|
|
goto cleanup;
|
2014-02-18 10:08:10 +00:00
|
|
|
|
2014-04-07 15:29:18 +00:00
|
|
|
cleanup:
|
|
|
|
virObjectUnref(caps);
|
2014-02-18 10:08:10 +00:00
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainObjPtr
|
|
|
|
bhyveDomObjFromDomain(virDomainPtr domain)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
bhyveConnPtr privconn = domain->conn->privateData;
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
|
2017-10-23 15:00:42 +00:00
|
|
|
vm = virDomainObjListFindByUUIDRef(privconn->domains, domain->uuid);
|
2014-02-18 10:08:10 +00:00
|
|
|
if (!vm) {
|
|
|
|
virUUIDFormat(domain->uuid, uuidstr);
|
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("no domain with matching uuid '%s' (%s)"),
|
|
|
|
uuidstr, domain->name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vm;
|
|
|
|
}
|
|
|
|
|
2018-03-27 16:24:44 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
bhyveConnectURIProbe(char **uri)
|
|
|
|
{
|
|
|
|
if (bhyve_driver == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return VIR_STRDUP(*uri, "bhyve:///system");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-18 10:08:10 +00:00
|
|
|
static virDrvOpenStatus
|
|
|
|
bhyveConnectOpen(virConnectPtr conn,
|
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
2016-06-03 17:01:27 +00:00
|
|
|
virConfPtr conf ATTRIBUTE_UNUSED,
|
2014-02-18 10:08:10 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
|
|
|
|
|
|
|
if (conn->uri == NULL) {
|
2018-03-27 16:24:44 +00:00
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
2014-02-18 10:08:10 +00:00
|
|
|
} else {
|
2015-10-20 16:15:12 +00:00
|
|
|
if (STRNEQ_NULLABLE(conn->uri->path, "/system")) {
|
2014-02-18 10:08:10 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unexpected bhyve URI path '%s', try bhyve:///system"),
|
|
|
|
conn->uri->path);
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bhyve_driver == NULL) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("bhyve state driver is not active"));
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virConnectOpenEnsureACL(conn) < 0)
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
|
|
|
|
conn->privateData = bhyve_driver;
|
|
|
|
|
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bhyveConnectClose(virConnectPtr conn)
|
|
|
|
{
|
2014-03-18 09:31:48 +00:00
|
|
|
bhyveConnPtr privconn = conn->privateData;
|
|
|
|
|
|
|
|
virCloseCallbacksRun(privconn->closeCallbacks, conn, privconn->domains, privconn);
|
2014-02-18 10:08:10 +00:00
|
|
|
conn->privateData = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2014-11-12 21:11:33 +00:00
|
|
|
bhyveConnectGetHostname(virConnectPtr conn)
|
2014-02-18 10:08:10 +00:00
|
|
|
{
|
|
|
|
if (virConnectGetHostnameEnsureACL(conn) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return virGetHostname();
|
|
|
|
}
|
|
|
|
|
2014-04-23 09:24:05 +00:00
|
|
|
static char *
|
|
|
|
bhyveConnectGetSysinfo(virConnectPtr conn, unsigned int flags)
|
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = conn->privateData;
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
|
|
|
if (virConnectGetSysinfoEnsureACL(conn) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!privconn->hostsysinfo) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Host SMBIOS information is not available"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virSysinfoFormat(&buf, privconn->hostsysinfo) < 0)
|
|
|
|
return NULL;
|
2014-06-27 08:40:15 +00:00
|
|
|
if (virBufferCheckError(&buf) < 0)
|
2014-04-23 09:24:05 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return virBufferContentAndReset(&buf);
|
|
|
|
}
|
|
|
|
|
2014-02-18 10:08:10 +00:00
|
|
|
static int
|
2014-11-12 21:11:33 +00:00
|
|
|
bhyveConnectGetVersion(virConnectPtr conn, unsigned long *version)
|
2014-02-18 10:08:10 +00:00
|
|
|
{
|
|
|
|
struct utsname ver;
|
|
|
|
|
|
|
|
if (virConnectGetVersionEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
uname(&ver);
|
|
|
|
|
|
|
|
if (virParseVersionString(ver.release, version, true) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unknown release: %s"), ver.release);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bhyveDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!(vm = bhyveDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainGetInfoEnsureACL(domain->conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-04-21 10:59:58 +00:00
|
|
|
if (virDomainObjIsActive(vm)) {
|
|
|
|
if (virBhyveGetDomainTotalCpuStats(vm, &(info->cpuTime)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
info->cpuTime = 0;
|
|
|
|
}
|
|
|
|
|
2014-02-18 10:08:10 +00:00
|
|
|
info->state = virDomainObjGetState(vm, NULL);
|
2016-06-15 13:34:04 +00:00
|
|
|
info->maxMem = virDomainDefGetMemoryTotal(vm->def);
|
2015-10-22 12:59:03 +00:00
|
|
|
info->nrVirtCpu = virDomainDefGetVcpus(vm->def);
|
2014-02-18 10:08:10 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-02-18 10:08:10 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bhyveDomainGetState(virDomainPtr domain,
|
|
|
|
int *state,
|
|
|
|
int *reason,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (!(vm = bhyveDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainGetStateEnsureACL(domain->conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
*state = virDomainObjGetState(vm, reason);
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-02-18 10:08:10 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-03-23 09:16:09 +00:00
|
|
|
static int
|
|
|
|
bhyveDomainGetAutostart(virDomainPtr domain, int *autostart)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!(vm = bhyveDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainGetAutostartEnsureACL(domain->conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
*autostart = vm->autostart;
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-03-23 09:16:09 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bhyveDomainSetAutostart(virDomainPtr domain, int autostart)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
char *configFile = NULL;
|
|
|
|
char *autostartLink = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!(vm = bhyveDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainSetAutostartEnsureACL(domain->conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!vm->persistent) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("cannot set autostart for transient domain"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
autostart = (autostart != 0);
|
|
|
|
|
|
|
|
if (vm->autostart != autostart) {
|
|
|
|
if ((configFile = virDomainConfigFile(BHYVE_CONFIG_DIR, vm->def->name)) == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
if ((autostartLink = virDomainConfigFile(BHYVE_AUTOSTART_DIR, vm->def->name)) == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (autostart) {
|
|
|
|
if (virFileMakePath(BHYVE_AUTOSTART_DIR) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("cannot create autostart directory %s"),
|
|
|
|
BHYVE_AUTOSTART_DIR);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (symlink(configFile, autostartLink) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Failed to create symlink '%s' to '%s'"),
|
|
|
|
autostartLink, configFile);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (unlink(autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Failed to delete symlink '%s'"),
|
|
|
|
autostartLink);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vm->autostart = autostart;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(configFile);
|
|
|
|
VIR_FREE(autostartLink);
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-03-23 09:16:09 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-28 19:18:43 +00:00
|
|
|
static int
|
|
|
|
bhyveDomainIsActive(virDomainPtr domain)
|
|
|
|
{
|
|
|
|
virDomainObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!(obj = bhyveDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainIsActiveEnsureACL(domain->conn, obj->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = virDomainObjIsActive(obj);
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&obj);
|
2014-02-28 19:18:43 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bhyveDomainIsPersistent(virDomainPtr domain)
|
|
|
|
{
|
|
|
|
virDomainObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!(obj = bhyveDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainIsPersistentEnsureACL(domain->conn, obj->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = obj->persistent;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&obj);
|
2014-02-28 19:18:43 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-20 17:32:42 +00:00
|
|
|
static char *
|
|
|
|
bhyveDomainGetOSType(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
if (!(vm = bhyveDomObjFromDomain(dom)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainGetOSTypeEnsureACL(dom->conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (VIR_STRDUP(ret, virDomainOSTypeToString(vm->def->os.type)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
cleanup:
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2015-10-20 17:32:42 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-18 10:08:10 +00:00
|
|
|
static char *
|
|
|
|
bhyveDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
|
|
|
|
{
|
2016-02-05 02:34:31 +00:00
|
|
|
bhyveConnPtr privconn = domain->conn->privateData;
|
2014-02-18 10:08:10 +00:00
|
|
|
virDomainObjPtr vm;
|
2016-02-03 21:40:35 +00:00
|
|
|
virCapsPtr caps = NULL;
|
2014-02-18 10:08:10 +00:00
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
if (!(vm = bhyveDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainGetXMLDescEnsureACL(domain->conn, vm->def, flags) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-02-03 21:40:35 +00:00
|
|
|
caps = bhyveDriverGetCapabilities(privconn);
|
|
|
|
if (!caps)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = virDomainDefFormat(vm->def, caps,
|
2014-11-18 16:44:00 +00:00
|
|
|
virDomainDefFormatConvertXMLFlags(flags));
|
2014-02-18 10:08:10 +00:00
|
|
|
|
2016-02-03 21:40:35 +00:00
|
|
|
virObjectUnref(caps);
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-02-18 10:08:10 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainPtr
|
2014-11-18 14:19:38 +00:00
|
|
|
bhyveDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
|
2014-02-18 10:08:10 +00:00
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = conn->privateData;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
virDomainDefPtr oldDef = NULL;
|
|
|
|
virDomainObjPtr vm = NULL;
|
2014-04-23 11:55:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2014-04-07 05:06:40 +00:00
|
|
|
virCapsPtr caps = NULL;
|
2014-11-18 17:34:42 +00:00
|
|
|
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
|
2014-04-07 05:06:40 +00:00
|
|
|
|
2014-11-18 17:34:42 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL);
|
|
|
|
|
|
|
|
if (flags & VIR_DOMAIN_DEFINE_VALIDATE)
|
2016-05-24 15:20:20 +00:00
|
|
|
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA;
|
2014-11-18 14:19:38 +00:00
|
|
|
|
2014-04-07 05:06:40 +00:00
|
|
|
caps = bhyveDriverGetCapabilities(privconn);
|
|
|
|
if (!caps)
|
|
|
|
return NULL;
|
2014-02-18 10:08:10 +00:00
|
|
|
|
2014-04-07 05:06:40 +00:00
|
|
|
if ((def = virDomainDefParseString(xml, caps, privconn->xmlopt,
|
2016-09-22 15:14:17 +00:00
|
|
|
NULL, parse_flags)) == NULL)
|
2014-02-18 10:08:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-11-11 09:17:37 +00:00
|
|
|
if (virXMLCheckIllegalChars("name", def->name, "\n") < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-11-18 14:19:38 +00:00
|
|
|
if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0)
|
2014-02-18 10:08:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-04-12 19:37:53 +00:00
|
|
|
if (bhyveDomainAssignAddresses(def, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-02-18 10:08:10 +00:00
|
|
|
if (!(vm = virDomainObjListAdd(privconn->domains, def,
|
|
|
|
privconn->xmlopt,
|
|
|
|
0, &oldDef)))
|
|
|
|
goto cleanup;
|
|
|
|
def = NULL;
|
2014-03-01 06:58:58 +00:00
|
|
|
vm->persistent = 1;
|
2014-02-18 10:08:10 +00:00
|
|
|
|
2016-02-03 21:40:36 +00:00
|
|
|
if (virDomainSaveConfig(BHYVE_CONFIG_DIR, caps,
|
2014-04-21 16:15:26 +00:00
|
|
|
vm->newDef ? vm->newDef : vm->def) < 0) {
|
|
|
|
virDomainObjListRemove(privconn->domains, vm);
|
|
|
|
vm = NULL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-04-23 11:55:05 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(vm,
|
|
|
|
VIR_DOMAIN_EVENT_DEFINED,
|
|
|
|
!oldDef ?
|
|
|
|
VIR_DOMAIN_EVENT_DEFINED_ADDED :
|
|
|
|
VIR_DOMAIN_EVENT_DEFINED_UPDATED);
|
|
|
|
|
2017-03-28 15:08:03 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
|
2014-02-18 10:08:10 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2014-04-07 05:06:40 +00:00
|
|
|
virObjectUnref(caps);
|
2014-02-18 10:08:10 +00:00
|
|
|
virDomainDefFree(def);
|
2014-04-21 16:15:26 +00:00
|
|
|
virDomainDefFree(oldDef);
|
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
2014-04-23 11:55:05 +00:00
|
|
|
if (event)
|
|
|
|
virObjectEventStateQueue(privconn->domainEventState, event);
|
2014-02-18 10:08:10 +00:00
|
|
|
|
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
2014-11-18 14:19:38 +00:00
|
|
|
static virDomainPtr
|
|
|
|
bhyveDomainDefineXML(virConnectPtr conn, const char *xml)
|
|
|
|
{
|
|
|
|
return bhyveDomainDefineXMLFlags(conn, xml, 0);
|
|
|
|
}
|
|
|
|
|
2014-02-28 19:18:43 +00:00
|
|
|
static int
|
|
|
|
bhyveDomainUndefine(virDomainPtr domain)
|
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = domain->conn->privateData;
|
2014-04-23 11:55:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2014-02-28 19:18:43 +00:00
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!(vm = bhyveDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainUndefineEnsureACL(domain->conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!vm->persistent) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
"%s", _("Cannot undefine transient domain"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainDeleteConfig(BHYVE_CONFIG_DIR,
|
|
|
|
BHYVE_AUTOSTART_DIR,
|
|
|
|
vm) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-04-23 11:55:05 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(vm,
|
|
|
|
VIR_DOMAIN_EVENT_UNDEFINED,
|
|
|
|
VIR_DOMAIN_EVENT_UNDEFINED_REMOVED);
|
|
|
|
|
2014-02-28 19:18:43 +00:00
|
|
|
if (virDomainObjIsActive(vm)) {
|
|
|
|
vm->persistent = 0;
|
|
|
|
} else {
|
|
|
|
virDomainObjListRemove(privconn->domains, vm);
|
2017-10-23 15:00:42 +00:00
|
|
|
virObjectLock(vm);
|
2014-02-28 19:18:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-04-23 11:55:05 +00:00
|
|
|
if (event)
|
|
|
|
virObjectEventStateQueue(privconn->domainEventState, event);
|
2014-02-28 19:18:43 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-18 10:08:10 +00:00
|
|
|
static int
|
|
|
|
bhyveConnectListDomains(virConnectPtr conn, int *ids, int maxids)
|
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = conn->privateData;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (virConnectListDomainsEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
n = virDomainObjListGetActiveIDs(privconn->domains, ids, maxids,
|
|
|
|
virConnectListDomainsCheckACL, conn);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bhyveConnectNumOfDomains(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = conn->privateData;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (virConnectNumOfDomainsEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
count = virDomainObjListNumOfDomains(privconn->domains, true,
|
|
|
|
virConnectNumOfDomainsCheckACL, conn);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bhyveConnectListDefinedDomains(virConnectPtr conn, char **const names,
|
|
|
|
int maxnames)
|
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = conn->privateData;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (virConnectListDefinedDomainsEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
memset(names, 0, sizeof(*names) * maxnames);
|
|
|
|
n = virDomainObjListGetInactiveNames(privconn->domains, names,
|
|
|
|
maxnames, virConnectListDefinedDomainsCheckACL, conn);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bhyveConnectNumOfDefinedDomains(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = conn->privateData;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (virConnectNumOfDefinedDomainsEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
count = virDomainObjListNumOfDomains(privconn->domains, false,
|
|
|
|
virConnectNumOfDefinedDomainsCheckACL, conn);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2014-04-13 09:48:17 +00:00
|
|
|
static char *
|
|
|
|
bhyveConnectDomainXMLToNative(virConnectPtr conn,
|
|
|
|
const char *format,
|
|
|
|
const char *xmlData,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
bhyveConnPtr privconn = conn->privateData;
|
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
virCommandPtr cmd = NULL, loadcmd = NULL;
|
|
|
|
virCapsPtr caps = NULL;
|
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
|
|
|
if (virConnectDomainXMLToNativeEnsureACL(conn) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (STRNEQ(format, BHYVE_CONFIG_FORMAT_ARGV)) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("Unsupported config type %s"), format);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(caps = bhyveDriverGetCapabilities(privconn)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(def = virDomainDefParseString(xmlData, caps, privconn->xmlopt,
|
2016-09-22 15:14:17 +00:00
|
|
|
NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE)))
|
2014-04-13 09:48:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-04-12 19:37:53 +00:00
|
|
|
if (bhyveDomainAssignAddresses(def, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-06-30 02:29:15 +00:00
|
|
|
if (def->os.bootloader == NULL &&
|
|
|
|
def->os.loader) {
|
|
|
|
|
|
|
|
if ((def->os.loader->readonly != VIR_TRISTATE_BOOL_YES) ||
|
|
|
|
(def->os.loader->type != VIR_DOMAIN_LOADER_TYPE_PFLASH)) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Only read-only pflash is supported."));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_LPC_BOOTROM) == 0) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Installed bhyve binary does not support "
|
|
|
|
"bootrom"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!(loadcmd = virBhyveProcessBuildLoadCmd(conn, def, "<device.map>",
|
2014-11-08 16:48:30 +00:00
|
|
|
NULL)))
|
2016-06-30 02:29:15 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
virBufferAdd(&buf, virCommandToString(loadcmd), -1);
|
|
|
|
virBufferAddChar(&buf, '\n');
|
|
|
|
}
|
2014-04-13 09:48:17 +00:00
|
|
|
|
2014-08-14 16:15:57 +00:00
|
|
|
if (!(cmd = virBhyveProcessBuildBhyveCmd(conn, def, true)))
|
2014-04-13 09:48:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
virBufferAdd(&buf, virCommandToString(cmd), -1);
|
|
|
|
|
2014-06-27 08:40:15 +00:00
|
|
|
if (virBufferCheckError(&buf) < 0)
|
2014-04-13 09:48:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = virBufferContentAndReset(&buf);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virCommandFree(loadcmd);
|
|
|
|
virCommandFree(cmd);
|
|
|
|
virDomainDefFree(def);
|
|
|
|
virObjectUnref(caps);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-18 10:08:10 +00:00
|
|
|
static int
|
|
|
|
bhyveConnectListAllDomains(virConnectPtr conn,
|
|
|
|
virDomainPtr **domains,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = conn->privateData;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1);
|
|
|
|
|
|
|
|
if (virConnectListAllDomainsEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ret = virDomainObjListExport(privconn->domains, conn, domains,
|
|
|
|
virConnectListAllDomainsCheckACL, flags);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainPtr
|
|
|
|
bhyveDomainLookupByUUID(virConnectPtr conn,
|
|
|
|
const unsigned char *uuid)
|
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
|
2017-10-23 15:00:42 +00:00
|
|
|
vm = virDomainObjListFindByUUIDRef(privconn->domains, uuid);
|
2014-02-18 10:08:10 +00:00
|
|
|
|
|
|
|
if (!vm) {
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
virUUIDFormat(uuid, uuidstr);
|
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("No domain with matching uuid '%s'"), uuidstr);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainLookupByUUIDEnsureACL(conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-03-28 15:08:03 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
|
2014-02-18 10:08:10 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-02-18 10:08:10 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainPtr bhyveDomainLookupByName(virConnectPtr conn,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
|
|
|
|
vm = virDomainObjListFindByName(privconn->domains, name);
|
|
|
|
|
|
|
|
if (!vm) {
|
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("no domain with matching name '%s'"), name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainLookupByNameEnsureACL(conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-03-28 15:08:03 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
|
2014-02-18 10:08:10 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-02-18 10:08:10 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
2014-03-27 07:31:21 +00:00
|
|
|
static virDomainPtr
|
|
|
|
bhyveDomainLookupByID(virConnectPtr conn,
|
|
|
|
int id)
|
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
|
2017-10-23 15:00:42 +00:00
|
|
|
vm = virDomainObjListFindByIDRef(privconn->domains, id);
|
2014-03-27 07:31:21 +00:00
|
|
|
|
|
|
|
if (!vm) {
|
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("No domain with matching ID '%d'"), id);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainLookupByIDEnsureACL(conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-03-28 15:08:03 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
|
2014-03-27 07:31:21 +00:00
|
|
|
|
|
|
|
cleanup:
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-03-27 07:31:21 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
2014-02-18 10:08:10 +00:00
|
|
|
static int
|
2014-03-18 09:31:48 +00:00
|
|
|
bhyveDomainCreateWithFlags(virDomainPtr dom,
|
|
|
|
unsigned int flags)
|
2014-02-18 10:08:10 +00:00
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
2014-04-23 11:55:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2014-03-18 09:31:48 +00:00
|
|
|
unsigned int start_flags = 0;
|
2014-02-18 10:08:10 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
2014-03-18 09:31:48 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, -1);
|
|
|
|
|
|
|
|
if (flags & VIR_DOMAIN_START_AUTODESTROY)
|
|
|
|
start_flags |= VIR_BHYVE_PROCESS_START_AUTODESTROY;
|
|
|
|
|
2014-02-18 10:08:10 +00:00
|
|
|
if (!(vm = bhyveDomObjFromDomain(dom)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-03-18 09:31:48 +00:00
|
|
|
if (virDomainCreateWithFlagsEnsureACL(dom->conn, vm->def) < 0)
|
2014-02-18 10:08:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainObjIsActive(vm)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
"%s", _("Domain is already running"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = virBhyveProcessStart(dom->conn, privconn, vm,
|
2014-03-18 09:31:48 +00:00
|
|
|
VIR_DOMAIN_RUNNING_BOOTED,
|
|
|
|
start_flags);
|
2014-02-18 10:08:10 +00:00
|
|
|
|
2014-04-23 11:55:05 +00:00
|
|
|
if (ret == 0)
|
|
|
|
event = virDomainEventLifecycleNewFromObj(vm,
|
|
|
|
VIR_DOMAIN_EVENT_STARTED,
|
|
|
|
VIR_DOMAIN_EVENT_STARTED_BOOTED);
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-04-23 11:55:05 +00:00
|
|
|
if (event)
|
|
|
|
virObjectEventStateQueue(privconn->domainEventState, event);
|
2014-02-18 10:08:10 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-03-18 09:31:48 +00:00
|
|
|
static int
|
|
|
|
bhyveDomainCreate(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
return bhyveDomainCreateWithFlags(dom, 0);
|
|
|
|
}
|
|
|
|
|
2014-04-10 09:06:38 +00:00
|
|
|
static virDomainPtr
|
|
|
|
bhyveDomainCreateXML(virConnectPtr conn,
|
|
|
|
const char *xml,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = conn->privateData;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
virDomainObjPtr vm = NULL;
|
2014-04-23 11:55:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2014-04-10 09:06:38 +00:00
|
|
|
virCapsPtr caps = NULL;
|
|
|
|
unsigned int start_flags = 0;
|
2014-11-18 17:34:42 +00:00
|
|
|
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
|
2014-04-10 09:06:38 +00:00
|
|
|
|
2014-11-18 17:34:42 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_START_AUTODESTROY |
|
|
|
|
VIR_DOMAIN_START_VALIDATE, NULL);
|
2014-04-10 09:06:38 +00:00
|
|
|
|
2014-11-18 17:34:42 +00:00
|
|
|
if (flags & VIR_DOMAIN_START_VALIDATE)
|
2016-05-24 15:20:20 +00:00
|
|
|
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA;
|
2014-04-10 09:06:38 +00:00
|
|
|
if (flags & VIR_DOMAIN_START_AUTODESTROY)
|
|
|
|
start_flags |= VIR_BHYVE_PROCESS_START_AUTODESTROY;
|
|
|
|
|
|
|
|
caps = bhyveDriverGetCapabilities(privconn);
|
|
|
|
if (!caps)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if ((def = virDomainDefParseString(xml, caps, privconn->xmlopt,
|
2016-09-22 15:14:17 +00:00
|
|
|
NULL, parse_flags)) == NULL)
|
2014-04-10 09:06:38 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainCreateXMLEnsureACL(conn, def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-04-12 19:37:53 +00:00
|
|
|
if (bhyveDomainAssignAddresses(def, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-04-10 09:06:38 +00:00
|
|
|
if (!(vm = virDomainObjListAdd(privconn->domains, def,
|
|
|
|
privconn->xmlopt,
|
2015-09-22 14:57:52 +00:00
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
|
2014-04-10 09:06:38 +00:00
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL)))
|
|
|
|
goto cleanup;
|
|
|
|
def = NULL;
|
|
|
|
|
|
|
|
if (virBhyveProcessStart(conn, privconn, vm,
|
|
|
|
VIR_DOMAIN_RUNNING_BOOTED,
|
|
|
|
start_flags) < 0) {
|
|
|
|
/* If domain is not persistent, remove its data */
|
|
|
|
if (!vm->persistent) {
|
|
|
|
virDomainObjListRemove(privconn->domains, vm);
|
|
|
|
vm = NULL;
|
|
|
|
}
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-04-23 11:55:05 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(vm,
|
|
|
|
VIR_DOMAIN_EVENT_STARTED,
|
|
|
|
VIR_DOMAIN_EVENT_STARTED_BOOTED);
|
|
|
|
|
2017-03-28 15:08:03 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
|
2014-04-10 09:06:38 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virObjectUnref(caps);
|
|
|
|
virDomainDefFree(def);
|
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
2014-04-23 11:55:05 +00:00
|
|
|
if (event)
|
|
|
|
virObjectEventStateQueue(privconn->domainEventState, event);
|
2014-04-10 09:06:38 +00:00
|
|
|
|
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
2014-02-18 10:08:10 +00:00
|
|
|
static int
|
|
|
|
bhyveDomainDestroy(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
2014-04-23 11:55:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2014-02-18 10:08:10 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!(vm = bhyveDomObjFromDomain(dom)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainDestroyEnsureACL(dom->conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-03-15 15:47:15 +00:00
|
|
|
if (!virDomainObjIsActive(vm)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
"%s", _("Domain is not running"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-02-18 10:08:10 +00:00
|
|
|
ret = virBhyveProcessStop(privconn, vm, VIR_DOMAIN_SHUTOFF_DESTROYED);
|
2014-04-23 11:55:05 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(vm,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
|
2014-02-18 10:08:10 +00:00
|
|
|
|
2014-04-09 05:52:11 +00:00
|
|
|
if (!vm->persistent) {
|
|
|
|
virDomainObjListRemove(privconn->domains, vm);
|
2017-10-23 15:00:42 +00:00
|
|
|
virObjectLock(vm);
|
2014-04-09 05:52:11 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-04-23 11:55:05 +00:00
|
|
|
if (event)
|
|
|
|
virObjectEventStateQueue(privconn->domainEventState, event);
|
2014-02-18 10:08:10 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-04 16:41:59 +00:00
|
|
|
static int
|
|
|
|
bhyveDomainShutdown(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!(vm = bhyveDomObjFromDomain(dom)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainShutdownEnsureACL(dom->conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!virDomainObjIsActive(vm)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
"%s", _("Domain is not running"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = virBhyveProcessShutdown(vm);
|
|
|
|
|
|
|
|
cleanup:
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2016-05-04 16:41:59 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-03-15 12:30:01 +00:00
|
|
|
static int
|
|
|
|
bhyveDomainOpenConsole(virDomainPtr dom,
|
|
|
|
const char *dev_name ATTRIBUTE_UNUSED,
|
|
|
|
virStreamPtr st,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainChrDefPtr chr = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (!(vm = bhyveDomObjFromDomain(dom)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainOpenConsoleEnsureACL(dom->conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!virDomainObjIsActive(vm)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
"%s", _("domain is not running"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!vm->def->nserials) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("no console devices available"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
chr = vm->def->serials[0];
|
|
|
|
|
2016-10-21 11:45:54 +00:00
|
|
|
if (virFDStreamOpenPTY(st, chr->source->data.nmdm.slave,
|
2014-03-15 12:30:01 +00:00
|
|
|
0, 0, O_RDWR) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-03-15 12:30:01 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-04-06 06:07:58 +00:00
|
|
|
static int
|
|
|
|
bhyveDomainSetMetadata(virDomainPtr dom,
|
|
|
|
int type,
|
|
|
|
const char *metadata,
|
|
|
|
const char *key,
|
|
|
|
const char *uri,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virCapsPtr caps = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
|
|
|
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
|
|
|
|
|
|
|
if (!(vm = bhyveDomObjFromDomain(dom)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (virDomainSetMetadataEnsureACL(dom->conn, vm->def, flags) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(caps = bhyveDriverGetCapabilities(privconn)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = virDomainObjSetMetadata(vm, type, metadata, key, uri, caps,
|
2014-07-22 15:41:05 +00:00
|
|
|
privconn->xmlopt, BHYVE_STATE_DIR,
|
|
|
|
BHYVE_CONFIG_DIR, flags);
|
2014-04-06 06:07:58 +00:00
|
|
|
|
2016-12-22 14:41:30 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
virObjectEventPtr ev = NULL;
|
|
|
|
ev = virDomainEventMetadataChangeNewFromObj(vm, type, uri);
|
|
|
|
virObjectEventStateQueue(privconn->domainEventState, ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-06 06:07:58 +00:00
|
|
|
cleanup:
|
|
|
|
virObjectUnref(caps);
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-04-06 06:07:58 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
bhyveDomainGetMetadata(virDomainPtr dom,
|
|
|
|
int type,
|
|
|
|
const char *uri,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
if (!(vm = bhyveDomObjFromDomain(dom)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (virDomainGetMetadataEnsureACL(dom->conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-07-01 14:19:58 +00:00
|
|
|
ret = virDomainObjGetMetadata(vm, type, uri, flags);
|
2014-04-06 06:07:58 +00:00
|
|
|
|
|
|
|
cleanup:
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-04-06 06:07:58 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-24 08:23:27 +00:00
|
|
|
static int
|
|
|
|
bhyveNodeGetCPUStats(virConnectPtr conn,
|
|
|
|
int cpuNum,
|
|
|
|
virNodeCPUStatsPtr params,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
if (virNodeGetCPUStatsEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2016-04-13 17:16:16 +00:00
|
|
|
return virHostCPUGetStats(cpuNum, params, nparams, flags);
|
2014-02-24 08:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bhyveNodeGetMemoryStats(virConnectPtr conn,
|
|
|
|
int cellNum,
|
|
|
|
virNodeMemoryStatsPtr params,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
if (virNodeGetMemoryStatsEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2016-04-13 17:16:16 +00:00
|
|
|
return virHostMemGetStats(cellNum, params, nparams, flags);
|
2014-02-24 08:23:27 +00:00
|
|
|
}
|
|
|
|
|
2014-03-16 11:10:51 +00:00
|
|
|
static int
|
|
|
|
bhyveNodeGetInfo(virConnectPtr conn,
|
2017-03-07 09:40:15 +00:00
|
|
|
virNodeInfoPtr nodeinfo)
|
2014-03-16 11:10:51 +00:00
|
|
|
{
|
|
|
|
if (virNodeGetInfoEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2017-03-07 09:40:15 +00:00
|
|
|
return virCapabilitiesGetNodeInfo(nodeinfo);
|
2014-03-16 11:10:51 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 10:08:10 +00:00
|
|
|
static int
|
|
|
|
bhyveStateCleanup(void)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("bhyve state cleanup");
|
|
|
|
|
|
|
|
if (bhyve_driver == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
virObjectUnref(bhyve_driver->domains);
|
|
|
|
virObjectUnref(bhyve_driver->caps);
|
|
|
|
virObjectUnref(bhyve_driver->xmlopt);
|
2016-03-28 12:49:28 +00:00
|
|
|
virSysinfoDefFree(bhyve_driver->hostsysinfo);
|
2014-03-18 09:31:48 +00:00
|
|
|
virObjectUnref(bhyve_driver->closeCallbacks);
|
2016-10-11 07:48:36 +00:00
|
|
|
virObjectUnref(bhyve_driver->domainEventState);
|
2017-03-11 16:19:03 +00:00
|
|
|
virObjectUnref(bhyve_driver->config);
|
2018-02-06 09:09:06 +00:00
|
|
|
virPortAllocatorRangeFree(bhyve_driver->remotePorts);
|
2014-02-18 10:08:10 +00:00
|
|
|
|
|
|
|
virMutexDestroy(&bhyve_driver->lock);
|
|
|
|
VIR_FREE(bhyve_driver);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-03-19 15:53:00 +00:00
|
|
|
bhyveStateInitialize(bool privileged,
|
2014-02-18 10:08:10 +00:00
|
|
|
virStateInhibitCallback callback ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
2015-03-19 15:53:00 +00:00
|
|
|
if (!privileged) {
|
|
|
|
VIR_INFO("Not running privileged, disabling driver");
|
2014-02-18 10:08:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:27:11 +00:00
|
|
|
if (VIR_ALLOC(bhyve_driver) < 0)
|
2014-02-18 10:08:10 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (virMutexInit(&bhyve_driver->lock) < 0) {
|
|
|
|
VIR_FREE(bhyve_driver);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-03-18 09:31:48 +00:00
|
|
|
if (!(bhyve_driver->closeCallbacks = virCloseCallbacksNew()))
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-04-07 05:06:40 +00:00
|
|
|
if (!(bhyve_driver->caps = virBhyveCapsBuild()))
|
2014-02-18 10:08:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-07-19 08:20:35 +00:00
|
|
|
if (virBhyveProbeCaps(&bhyve_driver->bhyvecaps) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-11-08 16:48:35 +00:00
|
|
|
if (virBhyveProbeGrubCaps(&bhyve_driver->grubcaps) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-01-05 12:31:35 +00:00
|
|
|
if (!(bhyve_driver->xmlopt = virBhyveDriverCreateXMLConf(bhyve_driver)))
|
2014-02-18 10:08:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(bhyve_driver->domains = virDomainObjListNew()))
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-04-23 11:55:05 +00:00
|
|
|
if (!(bhyve_driver->domainEventState = virObjectEventStateNew()))
|
|
|
|
goto cleanup;
|
|
|
|
|
2018-02-06 09:09:06 +00:00
|
|
|
if (!(bhyve_driver->remotePorts = virPortAllocatorRangeNew(_("display"),
|
2018-02-06 09:09:09 +00:00
|
|
|
5900, 65535)))
|
2017-05-08 10:36:43 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-04-23 09:24:05 +00:00
|
|
|
bhyve_driver->hostsysinfo = virSysinfoRead();
|
|
|
|
|
2017-03-11 16:19:03 +00:00
|
|
|
if (!(bhyve_driver->config = virBhyveDriverConfigNew()))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virBhyveLoadDriverConfig(bhyve_driver->config, SYSCONFDIR "/libvirt/bhyve.conf") < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-02-18 10:08:10 +00:00
|
|
|
if (virFileMakePath(BHYVE_LOG_DIR) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Failed to mkdir %s"),
|
|
|
|
BHYVE_LOG_DIR);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virFileMakePath(BHYVE_STATE_DIR) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Failed to mkdir %s"),
|
2014-08-12 15:46:18 +00:00
|
|
|
BHYVE_STATE_DIR);
|
2014-02-18 10:08:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-06-29 15:52:35 +00:00
|
|
|
if (virDomainObjListLoadAllConfigs(bhyve_driver->domains,
|
|
|
|
BHYVE_STATE_DIR,
|
2017-11-08 14:17:33 +00:00
|
|
|
NULL, true,
|
2014-06-29 15:52:35 +00:00
|
|
|
bhyve_driver->caps,
|
|
|
|
bhyve_driver->xmlopt,
|
|
|
|
NULL, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-02-18 10:08:10 +00:00
|
|
|
if (virDomainObjListLoadAllConfigs(bhyve_driver->domains,
|
|
|
|
BHYVE_CONFIG_DIR,
|
2017-11-08 14:17:33 +00:00
|
|
|
BHYVE_AUTOSTART_DIR, false,
|
2014-02-18 10:08:10 +00:00
|
|
|
bhyve_driver->caps,
|
|
|
|
bhyve_driver->xmlopt,
|
|
|
|
NULL, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-06-29 15:52:35 +00:00
|
|
|
virBhyveProcessReconnectAll(bhyve_driver);
|
|
|
|
|
2014-02-18 10:08:10 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2014-02-18 10:08:10 +00:00
|
|
|
bhyveStateCleanup();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-07-19 08:20:35 +00:00
|
|
|
unsigned
|
|
|
|
bhyveDriverGetCaps(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
bhyveConnPtr driver = conn->privateData;
|
|
|
|
|
|
|
|
if (driver != NULL)
|
|
|
|
return driver->bhyvecaps;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-08 16:48:35 +00:00
|
|
|
unsigned
|
|
|
|
bhyveDriverGetGrubCaps(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
bhyveConnPtr driver = conn->privateData;
|
|
|
|
|
|
|
|
if (driver != NULL)
|
|
|
|
return driver->grubcaps;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-23 09:16:09 +00:00
|
|
|
static void
|
|
|
|
bhyveStateAutoStart(void)
|
|
|
|
{
|
|
|
|
if (!bhyve_driver)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bhyveAutostartDomains(bhyve_driver);
|
|
|
|
}
|
|
|
|
|
2014-03-20 08:39:23 +00:00
|
|
|
static int
|
2014-11-12 21:11:33 +00:00
|
|
|
bhyveConnectGetMaxVcpus(virConnectPtr conn,
|
2014-03-18 08:19:33 +00:00
|
|
|
const char *type)
|
|
|
|
{
|
2014-03-20 08:39:23 +00:00
|
|
|
if (virConnectGetMaxVcpusEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bhyve supports up to 16 VCPUs, but offers no method to check this
|
|
|
|
* value. Hardcode 16...
|
|
|
|
*/
|
|
|
|
if (!type || STRCASEEQ(type, "bhyve"))
|
|
|
|
return 16;
|
|
|
|
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, _("unknown type '%s'"), type);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long long
|
|
|
|
bhyveNodeGetFreeMemory(virConnectPtr conn)
|
|
|
|
{
|
2014-06-16 12:02:34 +00:00
|
|
|
unsigned long long freeMem;
|
|
|
|
|
2014-03-20 08:39:23 +00:00
|
|
|
if (virNodeGetFreeMemoryEnsureACL(conn) < 0)
|
|
|
|
return 0;
|
|
|
|
|
2016-04-13 17:16:16 +00:00
|
|
|
if (virHostMemGetInfo(NULL, &freeMem) < 0)
|
2014-06-16 12:02:34 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return freeMem;
|
2014-03-20 08:39:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bhyveNodeGetCPUMap(virConnectPtr conn,
|
|
|
|
unsigned char **cpumap,
|
|
|
|
unsigned int *online,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
if (virNodeGetCPUMapEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2016-04-13 17:16:16 +00:00
|
|
|
return virHostCPUGetMap(cpumap, online, flags);
|
2014-03-20 08:39:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bhyveNodeGetMemoryParameters(virConnectPtr conn,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
if (virNodeGetMemoryParametersEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2016-04-13 17:16:16 +00:00
|
|
|
return virHostMemGetParameters(params, nparams, flags);
|
2014-03-20 08:39:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bhyveNodeSetMemoryParameters(virConnectPtr conn,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
if (virNodeSetMemoryParametersEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2016-04-13 17:16:16 +00:00
|
|
|
return virHostMemSetParameters(params, nparams, flags);
|
2014-03-20 08:39:23 +00:00
|
|
|
}
|
2014-02-18 10:08:10 +00:00
|
|
|
|
2014-04-07 05:06:39 +00:00
|
|
|
static char *
|
2014-11-12 21:11:33 +00:00
|
|
|
bhyveConnectBaselineCPU(virConnectPtr conn,
|
2014-04-07 05:06:39 +00:00
|
|
|
const char **xmlCPUs,
|
|
|
|
unsigned int ncpus,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2017-09-13 14:27:15 +00:00
|
|
|
virCPUDefPtr *cpus = NULL;
|
|
|
|
virCPUDefPtr cpu = NULL;
|
|
|
|
char *cpustr = NULL;
|
2014-04-07 05:06:39 +00:00
|
|
|
|
2015-02-05 14:28:09 +00:00
|
|
|
virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES |
|
|
|
|
VIR_CONNECT_BASELINE_CPU_MIGRATABLE, NULL);
|
2014-04-07 05:06:39 +00:00
|
|
|
|
|
|
|
if (virConnectBaselineCPUEnsureACL(conn) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-09-13 14:27:15 +00:00
|
|
|
if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-10-19 09:13:54 +00:00
|
|
|
if (!(cpu = cpuBaseline(cpus, ncpus, NULL,
|
2017-09-13 14:27:15 +00:00
|
|
|
!!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&
|
|
|
|
virCPUExpandFeatures(cpus[0]->arch, cpu) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-06-30 13:47:23 +00:00
|
|
|
cpustr = virCPUDefFormat(cpu, NULL);
|
2014-04-07 05:06:39 +00:00
|
|
|
|
|
|
|
cleanup:
|
2017-09-13 14:27:15 +00:00
|
|
|
virCPUDefListFree(cpus);
|
|
|
|
virCPUDefFree(cpu);
|
|
|
|
|
|
|
|
return cpustr;
|
2014-04-07 05:06:39 +00:00
|
|
|
}
|
|
|
|
|
2014-04-07 05:06:41 +00:00
|
|
|
static int
|
|
|
|
bhyveConnectCompareCPU(virConnectPtr conn,
|
|
|
|
const char *xmlDesc,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
bhyveConnPtr driver = conn->privateData;
|
|
|
|
int ret = VIR_CPU_COMPARE_ERROR;
|
|
|
|
virCapsPtr caps = NULL;
|
2014-05-28 13:12:59 +00:00
|
|
|
bool failIncompatible;
|
2014-04-07 05:06:41 +00:00
|
|
|
|
2014-05-28 13:12:59 +00:00
|
|
|
virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE,
|
|
|
|
VIR_CPU_COMPARE_ERROR);
|
2014-04-07 05:06:41 +00:00
|
|
|
|
|
|
|
if (virConnectCompareCPUEnsureACL(conn) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-06-27 15:04:41 +00:00
|
|
|
failIncompatible = !!(flags & VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE);
|
2014-05-28 13:12:59 +00:00
|
|
|
|
2014-04-07 05:06:41 +00:00
|
|
|
if (!(caps = bhyveDriverGetCapabilities(driver)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!caps->host.cpu ||
|
|
|
|
!caps->host.cpu->model) {
|
2014-06-27 15:04:41 +00:00
|
|
|
if (failIncompatible) {
|
2014-05-28 13:12:59 +00:00
|
|
|
virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s",
|
|
|
|
_("cannot get host CPU capabilities"));
|
|
|
|
} else {
|
|
|
|
VIR_WARN("cannot get host CPU capabilities");
|
|
|
|
ret = VIR_CPU_COMPARE_INCOMPATIBLE;
|
|
|
|
}
|
2014-04-07 05:06:41 +00:00
|
|
|
} else {
|
2016-09-29 05:10:33 +00:00
|
|
|
ret = virCPUCompareXML(caps->host.arch, caps->host.cpu,
|
|
|
|
xmlDesc, failIncompatible);
|
2014-04-07 05:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virObjectUnref(caps);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-04-23 11:55:05 +00:00
|
|
|
static int
|
|
|
|
bhyveConnectDomainEventRegisterAny(virConnectPtr conn,
|
|
|
|
virDomainPtr dom,
|
|
|
|
int eventID,
|
|
|
|
virConnectDomainEventGenericCallback callback,
|
|
|
|
void *opaque,
|
|
|
|
virFreeCallback freecb)
|
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = conn->privateData;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (virConnectDomainEventRegisterAnyEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (virDomainEventStateRegisterID(conn,
|
|
|
|
privconn->domainEventState,
|
|
|
|
dom, eventID,
|
|
|
|
callback, opaque, freecb, &ret) < 0)
|
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bhyveConnectDomainEventDeregisterAny(virConnectPtr conn,
|
|
|
|
int callbackID)
|
|
|
|
{
|
|
|
|
bhyveConnPtr privconn = conn->privateData;
|
|
|
|
|
|
|
|
if (virConnectDomainEventDeregisterAnyEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (virObjectEventStateDeregisterID(conn,
|
|
|
|
privconn->domainEventState,
|
2017-06-14 11:32:15 +00:00
|
|
|
callbackID, true) < 0)
|
2014-04-23 11:55:05 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-15 14:02:44 +00:00
|
|
|
static int
|
|
|
|
bhyveDomainHasManagedSaveImage(virDomainPtr domain, unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (!(vm = bhyveDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainHasManagedSaveImageEnsureACL(domain->conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2017-10-23 15:00:42 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2015-01-15 14:02:44 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-13 14:01:33 +00:00
|
|
|
static const char *
|
|
|
|
bhyveConnectGetType(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
if (virConnectGetTypeEnsureACL(conn) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return "BHYVE";
|
|
|
|
}
|
|
|
|
|
2016-05-13 19:22:57 +00:00
|
|
|
static int bhyveConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-05-17 12:49:21 +00:00
|
|
|
static int
|
|
|
|
bhyveConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
/* Trivially secure, since always inside the daemon */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-05-17 12:49:20 +00:00
|
|
|
static int
|
|
|
|
bhyveConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
/* Not encrypted, but remote driver takes care of that */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-01 07:57:43 +00:00
|
|
|
static char *
|
|
|
|
bhyveConnectDomainXMLFromNative(virConnectPtr conn,
|
|
|
|
const char *nativeFormat,
|
|
|
|
const char *nativeConfig,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
char *xml = NULL;
|
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
bhyveConnPtr privconn = conn->privateData;
|
|
|
|
virCapsPtr capabilities = NULL;
|
|
|
|
unsigned caps = bhyveDriverGetCaps(conn);
|
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
|
|
|
if (virConnectDomainXMLFromNativeEnsureACL(conn) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
capabilities = bhyveDriverGetCapabilities(privconn);
|
|
|
|
if (!capabilities)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (STRNEQ(nativeFormat, BHYVE_CONFIG_FORMAT_ARGV)) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("unsupported config type %s"), nativeFormat);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
def = bhyveParseCommandLineString(nativeConfig, caps, privconn->xmlopt);
|
|
|
|
if (def == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
xml = virDomainDefFormat(def, capabilities, 0);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virObjectUnref(capabilities);
|
|
|
|
virDomainDefFree(def);
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
2016-07-08 18:53:33 +00:00
|
|
|
static char *
|
|
|
|
bhyveConnectGetDomainCapabilities(virConnectPtr conn,
|
|
|
|
const char *emulatorbin,
|
|
|
|
const char *arch_str,
|
|
|
|
const char *machine,
|
|
|
|
const char *virttype_str,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainCapsPtr caps = NULL;
|
|
|
|
char *ret = NULL;
|
|
|
|
int virttype = VIR_DOMAIN_VIRT_BHYVE;
|
|
|
|
int arch = virArchFromHost(); /* virArch */
|
|
|
|
|
|
|
|
virCheckFlags(0, ret);
|
|
|
|
|
|
|
|
if (virConnectGetDomainCapabilitiesEnsureACL(conn) < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (virttype_str &&
|
|
|
|
(virttype = virDomainVirtTypeFromString(virttype_str)) < 0) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("unknown virttype: %s"),
|
|
|
|
virttype_str);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virttype != VIR_DOMAIN_VIRT_BHYVE) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("unknown virttype: %s"),
|
|
|
|
virttype_str);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arch_str && (arch = virArchFromString(arch_str)) == VIR_ARCH_NONE) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("unknown architecture: %s"),
|
|
|
|
arch_str);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ARCH_IS_X86(arch)) {
|
|
|
|
virReportError(VIR_ERR_NO_SUPPORT,
|
|
|
|
_("unsupported architecture: %s"),
|
|
|
|
virArchToString(arch));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (emulatorbin == NULL) {
|
|
|
|
emulatorbin = "/usr/sbin/bhyve";
|
|
|
|
} else if (STRNEQ(emulatorbin, "/usr/sbin/bhyve")) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("unknown emulator binary: %s"),
|
|
|
|
emulatorbin);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-03-11 16:19:03 +00:00
|
|
|
if (!(caps = virBhyveDomainCapsBuild(conn->privateData, emulatorbin,
|
|
|
|
machine, arch, virttype)))
|
2016-07-08 18:53:33 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = virDomainCapsFormat(caps);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virObjectUnref(caps);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-01-20 16:16:26 +00:00
|
|
|
static virHypervisorDriver bhyveHypervisorDriver = {
|
2014-02-18 10:08:10 +00:00
|
|
|
.name = "bhyve",
|
2018-03-27 16:24:44 +00:00
|
|
|
.connectURIProbe = bhyveConnectURIProbe,
|
2014-02-18 10:08:10 +00:00
|
|
|
.connectOpen = bhyveConnectOpen, /* 1.2.2 */
|
|
|
|
.connectClose = bhyveConnectClose, /* 1.2.2 */
|
|
|
|
.connectGetVersion = bhyveConnectGetVersion, /* 1.2.2 */
|
|
|
|
.connectGetHostname = bhyveConnectGetHostname, /* 1.2.2 */
|
2014-04-23 09:24:05 +00:00
|
|
|
.connectGetSysinfo = bhyveConnectGetSysinfo, /* 1.2.5 */
|
2014-02-18 10:08:10 +00:00
|
|
|
.domainGetInfo = bhyveDomainGetInfo, /* 1.2.2 */
|
|
|
|
.domainGetState = bhyveDomainGetState, /* 1.2.2 */
|
|
|
|
.connectGetCapabilities = bhyveConnectGetCapabilities, /* 1.2.2 */
|
|
|
|
.connectListDomains = bhyveConnectListDomains, /* 1.2.2 */
|
|
|
|
.connectNumOfDomains = bhyveConnectNumOfDomains, /* 1.2.2 */
|
|
|
|
.connectListAllDomains = bhyveConnectListAllDomains, /* 1.2.2 */
|
|
|
|
.connectListDefinedDomains = bhyveConnectListDefinedDomains, /* 1.2.2 */
|
|
|
|
.connectNumOfDefinedDomains = bhyveConnectNumOfDefinedDomains, /* 1.2.2 */
|
2014-04-13 09:48:17 +00:00
|
|
|
.connectDomainXMLToNative = bhyveConnectDomainXMLToNative, /* 1.2.5 */
|
2014-02-18 10:08:10 +00:00
|
|
|
.domainCreate = bhyveDomainCreate, /* 1.2.2 */
|
2014-03-18 09:31:48 +00:00
|
|
|
.domainCreateWithFlags = bhyveDomainCreateWithFlags, /* 1.2.3 */
|
2014-04-10 09:06:38 +00:00
|
|
|
.domainCreateXML = bhyveDomainCreateXML, /* 1.2.4 */
|
2014-02-18 10:08:10 +00:00
|
|
|
.domainDestroy = bhyveDomainDestroy, /* 1.2.2 */
|
2016-05-04 16:41:59 +00:00
|
|
|
.domainShutdown = bhyveDomainShutdown, /* 1.3.3 */
|
2014-02-18 10:08:10 +00:00
|
|
|
.domainLookupByUUID = bhyveDomainLookupByUUID, /* 1.2.2 */
|
|
|
|
.domainLookupByName = bhyveDomainLookupByName, /* 1.2.2 */
|
2014-03-27 07:31:21 +00:00
|
|
|
.domainLookupByID = bhyveDomainLookupByID, /* 1.2.3 */
|
2014-02-18 10:08:10 +00:00
|
|
|
.domainDefineXML = bhyveDomainDefineXML, /* 1.2.2 */
|
2014-11-18 14:19:38 +00:00
|
|
|
.domainDefineXMLFlags = bhyveDomainDefineXMLFlags, /* 1.2.12 */
|
2014-02-28 19:18:43 +00:00
|
|
|
.domainUndefine = bhyveDomainUndefine, /* 1.2.2 */
|
2015-10-20 17:32:42 +00:00
|
|
|
.domainGetOSType = bhyveDomainGetOSType, /* 1.2.21 */
|
2014-02-18 10:08:10 +00:00
|
|
|
.domainGetXMLDesc = bhyveDomainGetXMLDesc, /* 1.2.2 */
|
2014-02-28 19:18:43 +00:00
|
|
|
.domainIsActive = bhyveDomainIsActive, /* 1.2.2 */
|
|
|
|
.domainIsPersistent = bhyveDomainIsPersistent, /* 1.2.2 */
|
2014-03-23 09:16:09 +00:00
|
|
|
.domainGetAutostart = bhyveDomainGetAutostart, /* 1.2.4 */
|
|
|
|
.domainSetAutostart = bhyveDomainSetAutostart, /* 1.2.4 */
|
2014-03-15 12:30:01 +00:00
|
|
|
.domainOpenConsole = bhyveDomainOpenConsole, /* 1.2.4 */
|
2014-04-06 06:07:58 +00:00
|
|
|
.domainSetMetadata = bhyveDomainSetMetadata, /* 1.2.4 */
|
|
|
|
.domainGetMetadata = bhyveDomainGetMetadata, /* 1.2.4 */
|
2014-02-24 08:23:27 +00:00
|
|
|
.nodeGetCPUStats = bhyveNodeGetCPUStats, /* 1.2.2 */
|
|
|
|
.nodeGetMemoryStats = bhyveNodeGetMemoryStats, /* 1.2.2 */
|
2014-03-16 11:10:51 +00:00
|
|
|
.nodeGetInfo = bhyveNodeGetInfo, /* 1.2.3 */
|
2014-03-20 08:39:23 +00:00
|
|
|
.connectGetMaxVcpus = bhyveConnectGetMaxVcpus, /* 1.2.3 */
|
|
|
|
.nodeGetFreeMemory = bhyveNodeGetFreeMemory, /* 1.2.3 */
|
|
|
|
.nodeGetCPUMap = bhyveNodeGetCPUMap, /* 1.2.3 */
|
|
|
|
.nodeGetMemoryParameters = bhyveNodeGetMemoryParameters, /* 1.2.3 */
|
|
|
|
.nodeSetMemoryParameters = bhyveNodeSetMemoryParameters, /* 1.2.3 */
|
2014-04-07 05:06:39 +00:00
|
|
|
.connectBaselineCPU = bhyveConnectBaselineCPU, /* 1.2.4 */
|
2014-04-07 05:06:41 +00:00
|
|
|
.connectCompareCPU = bhyveConnectCompareCPU, /* 1.2.4 */
|
2014-04-23 11:55:05 +00:00
|
|
|
.connectDomainEventRegisterAny = bhyveConnectDomainEventRegisterAny, /* 1.2.5 */
|
|
|
|
.connectDomainEventDeregisterAny = bhyveConnectDomainEventDeregisterAny, /* 1.2.5 */
|
2015-01-15 14:02:44 +00:00
|
|
|
.domainHasManagedSaveImage = bhyveDomainHasManagedSaveImage, /* 1.2.13 */
|
2016-05-13 14:01:33 +00:00
|
|
|
.connectGetType = bhyveConnectGetType, /* 1.3.5 */
|
2016-05-13 19:22:57 +00:00
|
|
|
.connectIsAlive = bhyveConnectIsAlive, /* 1.3.5 */
|
2016-05-17 12:49:21 +00:00
|
|
|
.connectIsSecure = bhyveConnectIsSecure, /* 1.3.5 */
|
2016-05-17 12:49:20 +00:00
|
|
|
.connectIsEncrypted = bhyveConnectIsEncrypted, /* 1.3.5 */
|
2016-06-01 07:57:43 +00:00
|
|
|
.connectDomainXMLFromNative = bhyveConnectDomainXMLFromNative, /* 2.1.0 */
|
2016-07-08 18:53:33 +00:00
|
|
|
.connectGetDomainCapabilities = bhyveConnectGetDomainCapabilities, /* 2.1.0 */
|
2014-02-18 10:08:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-01-20 16:16:26 +00:00
|
|
|
static virConnectDriver bhyveConnectDriver = {
|
2018-03-28 09:53:31 +00:00
|
|
|
.localOnly = true,
|
2018-03-27 14:51:45 +00:00
|
|
|
.uriSchemes = (const char *[]){ "bhyve", NULL },
|
2015-01-20 16:16:26 +00:00
|
|
|
.hypervisorDriver = &bhyveHypervisorDriver,
|
|
|
|
};
|
|
|
|
|
2014-02-18 10:08:10 +00:00
|
|
|
static virStateDriver bhyveStateDriver = {
|
|
|
|
.name = "bhyve",
|
|
|
|
.stateInitialize = bhyveStateInitialize,
|
2014-03-23 09:16:09 +00:00
|
|
|
.stateAutoStart = bhyveStateAutoStart,
|
2014-02-18 10:08:10 +00:00
|
|
|
.stateCleanup = bhyveStateCleanup,
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
bhyveRegister(void)
|
|
|
|
{
|
2015-01-20 16:16:26 +00:00
|
|
|
if (virRegisterConnectDriver(&bhyveConnectDriver,
|
|
|
|
true) < 0)
|
2014-03-17 13:35:42 +00:00
|
|
|
return -1;
|
2015-01-20 16:16:26 +00:00
|
|
|
if (virRegisterStateDriver(&bhyveStateDriver) < 0)
|
2014-03-17 13:35:42 +00:00
|
|
|
return -1;
|
2015-01-20 16:16:26 +00:00
|
|
|
return 0;
|
2014-02-18 10:08:10 +00:00
|
|
|
}
|