On 02/08/14 01:26, Roman Bogorodskiy wrote:
--- a/configure.ac
+++ b/configure.ac
@@ -2704,6 +2710,7 @@ AC_MSG_NOTICE([ PHYP: $with_phyp])
AC_MSG_NOTICE([ ESX: $with_esx])
AC_MSG_NOTICE([ Hyper-V: $with_hyperv])
AC_MSG_NOTICE([Parallels: $with_parallels])
+LIBIVRT_DRIVER_RESULT_BHYVE
AC_MSG_NOTICE([ Test: $with_test])
AC_MSG_NOTICE([ Remote: $with_remote])
AC_MSG_NOTICE([ Network: $with_network])
--- /dev/null
+++ b/m4/virt-driver-bhyve.m4
+AC_DEFUN([LIBIVRT_DRIVER_RESULT_BHYVE],[
+ AC_MSG_NOTICE([ Bhyve: $with_bhyve])
+])
This should be LIBVIRT_ instead of LIBIVRT_
I've also attached a patch to enable autostarting domains.
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 2518c8a..2ae3c50 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -68,6 +68,43 @@ bhyveDriverUnlock(bhyveConnPtr driver)
virMutexUnlock(&driver->lock);
}
+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);
+ if (ret < 0) {
+ virErrorPtr err = virGetLastError();
+ VIR_ERROR(_("Failed to autostart VM '%s': %s"),
+ vm->def->name, err ? err->message : _("unknown error"));
+ }
+ }
+ 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);
+}
+
static virCapsPtr
bhyveBuildCapabilities(void)
{
@@ -451,6 +488,104 @@ cleanup:
}
static int
+bhyveDomainGetAutostart(virDomainPtr dom, int *autostart)
+{
+ bhyveConnPtr privconn = dom->conn->privateData;
+ virDomainObjPtr vm;
+ int ret = -1;
+
+ vm = virDomainObjListFindByUUID(privconn->domains, dom->uuid);
+ if (!vm) {
+ virReportError(VIR_ERR_NO_DOMAIN, "%s",
+ _("no domain with matching uuid"));
+ goto cleanup;
+ }
+
+ *autostart = vm->autostart;
+ ret = 0;
+
+cleanup:
+ if (vm)
+ virObjectUnlock(vm);
+ return ret;
+}
+
+static int
+bhyveDomainSetAutostart(virDomainPtr dom, int autostart)
+{
+ bhyveConnPtr privconn = dom->conn->privateData;
+ virDomainObjPtr vm;
+ char *configFile = NULL;
+ char *autostartLink = NULL;
+ int ret = -1;
+
+ vm = virDomainObjListFindByUUID(privconn->domains, dom->uuid);
+ if (!vm) {
+ virReportError(VIR_ERR_NO_DOMAIN, "%s",
+ _("no domain with matching uuid"));
+ 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);
+ if (vm)
+ virObjectUnlock(vm);
+ return ret;
+}
+
+static void
+bhyveStateAutoStart(void)
+{
+ if (!bhyve_driver)
+ return;
+
+ bhyveAutostartDomains(bhyve_driver);
+}
+
+static int
bhyveStateCleanup(void)
{
VIR_INFO("bhyve state cleanup");
@@ -512,7 +647,7 @@ bhyveStateInitialize(bool priveleged ATTRIBUTE_UNUSED,
if (virDomainObjListLoadAllConfigs(bhyve_driver->domains,
BHYVE_CONFIG_DIR,
- NULL, 0,
+ BHYVE_AUTOSTART_DIR, 0,
bhyve_driver->caps,
bhyve_driver->xmlopt,
1 << VIR_DOMAIN_VIRT_BHYVE,
@@ -548,12 +683,15 @@ static virDriver bhyveDriver = {
.domainLookupByName = bhyveDomainLookupByName, /* 0.1.0 */
.domainDefineXML = bhyveDomainDefineXML, /* 0.1.0 */
.domainGetXMLDesc = bhyveDomainGetXMLDesc, /* 0.1.0 */
+ .domainGetAutostart = bhyveDomainGetAutostart, /* 0.1.0 */
+ .domainSetAutostart = bhyveDomainSetAutostart, /* 0.1.0 */
};
static virStateDriver bhyveStateDriver = {
.name = "bhyve",
.stateInitialize = bhyveStateInitialize,
+ .stateAutoStart = bhyveStateAutoStart,
.stateCleanup = bhyveStateCleanup,
};
diff --git a/src/bhyve/bhyve_utils.h b/src/bhyve/bhyve_utils.h
index ed503cd..86aec0a 100644
--- a/src/bhyve/bhyve_utils.h
+++ b/src/bhyve/bhyve_utils.h
@@ -28,6 +28,7 @@
# include "virthread.h"
# define BHYVE_CONFIG_DIR (SYSCONFDIR "/libvirt/bhyve")
+# define BHYVE_AUTOSTART_DIR (SYSCONFDIR "/libvirt/bhyve/autostart")
# define BHYVE_STATE_DIR (LOCALSTATEDIR "/run/libvirt/bhyve")
# define BHYVE_LOG_DIR (LOCALSTATEDIR "/log/libvirt/bhyve")
@@ -42,6 +43,11 @@ struct _bhyveConn {
typedef struct _bhyveConn bhyveConn;
typedef struct _bhyveConn *bhyveConnPtr;
+struct bhyveAutostartData {
+ bhyveConnPtr driver;
+ virConnectPtr conn;
+};
+
void bhyveDriverLock(bhyveConnPtr driver);
void bhyveDriverUnlock(bhyveConnPtr driver);
--
libvir-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libvir-list