static int
bhyveConnectClose(virConnectPtr conn)
{
+ bhyveConnPtr privconn = conn->privateData;
+
+ virCloseCallbacksRun(privconn->closeCallbacks, conn, privconn->domains, privconn);
conn->privateData = NULL;
return 0;
}
static int
-bhyveDomainCreate(virDomainPtr dom)
+bhyveDomainCreateWithFlags(virDomainPtr dom,
+ unsigned int flags)
{
bhyveConnPtr privconn = dom->conn->privateData;
virDomainObjPtr vm;
+ unsigned int start_flags = 0;
int ret = -1;
+ virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, -1);
+
+ if (flags & VIR_DOMAIN_START_AUTODESTROY)
+ start_flags |= VIR_BHYVE_PROCESS_START_AUTODESTROY;
+
if (!(vm = bhyveDomObjFromDomain(dom)))
goto cleanup;
- if (virDomainCreateEnsureACL(dom->conn, vm->def) < 0)
+ if (virDomainCreateWithFlagsEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
if (virDomainObjIsActive(vm)) {
}
ret = virBhyveProcessStart(dom->conn, privconn, vm,
- VIR_DOMAIN_RUNNING_BOOTED);
+ VIR_DOMAIN_RUNNING_BOOTED,
+ start_flags);
cleanup:
virObjectUnlock(vm);
return ret;
}
+static int
+bhyveDomainCreate(virDomainPtr dom)
+{
+ return bhyveDomainCreateWithFlags(dom, 0);
+}
+
static int
bhyveDomainDestroy(virDomainPtr dom)
{
virObjectUnref(bhyve_driver->domains);
virObjectUnref(bhyve_driver->caps);
virObjectUnref(bhyve_driver->xmlopt);
+ virObjectUnref(bhyve_driver->closeCallbacks);
virMutexDestroy(&bhyve_driver->lock);
VIR_FREE(bhyve_driver);
return -1;
}
+ if (!(bhyve_driver->closeCallbacks = virCloseCallbacksNew()))
+ goto cleanup;
+
if (!(bhyve_driver->caps = bhyveBuildCapabilities()))
goto cleanup;
.connectListDefinedDomains = bhyveConnectListDefinedDomains, /* 1.2.2 */
.connectNumOfDefinedDomains = bhyveConnectNumOfDefinedDomains, /* 1.2.2 */
.domainCreate = bhyveDomainCreate, /* 1.2.2 */
+ .domainCreateWithFlags = bhyveDomainCreateWithFlags, /* 1.2.3 */
.domainDestroy = bhyveDomainDestroy, /* 1.2.2 */
.domainLookupByUUID = bhyveDomainLookupByUUID, /* 1.2.2 */
.domainLookupByName = bhyveDomainLookupByName, /* 1.2.2 */
VIR_LOG_INIT("bhyve.bhyve_process");
+static virDomainObjPtr
+bhyveProcessAutoDestroy(virDomainObjPtr vm,
+ virConnectPtr conn ATTRIBUTE_UNUSED,
+ void *opaque)
+{
+ bhyveConnPtr driver = opaque;
+
+ virBhyveProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED);
+
+ if (!vm->persistent) {
+ virDomainObjListRemove(driver->domains, vm);
+ vm = NULL;
+ }
+
+ return vm;
+}
+
int
virBhyveProcessStart(virConnectPtr conn,
bhyveConnPtr driver,
virDomainObjPtr vm,
- virDomainRunningReason reason)
+ virDomainRunningReason reason,
+ unsigned int flags)
{
char *logfile = NULL;
int logfd = -1;
/* Now we can start the domain */
VIR_DEBUG("Starting domain '%s'", vm->def->name);
- ret = virCommandRun(cmd, NULL);
-
- if (ret == 0) {
- if (virPidFileReadPath(privconn->pidfile, &vm->pid) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Domain %s didn't show up"), vm->def->name);
- goto cleanup;
- }
+ if (virCommandRun(cmd, NULL) < 0)
+ goto cleanup;
- vm->def->id = vm->pid;
- virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason);
- } else {
+ if (virPidFileReadPath(privconn->pidfile, &vm->pid) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Domain %s didn't show up"), vm->def->name);
goto cleanup;
}
+ if (flags & VIR_BHYVE_PROCESS_START_AUTODESTROY &&
+ virCloseCallbacksSet(driver->closeCallbacks, vm,
+ conn, bhyveProcessAutoDestroy) < 0)
+ goto cleanup;
+
+ vm->def->id = vm->pid;
+ virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason);
+
+ ret = 0;
+
cleanup:
if (ret < 0) {
virCommandPtr destroy_cmd;
ret = 0;
+ virCloseCallbacksUnset(driver->closeCallbacks, vm,
+ bhyveProcessAutoDestroy);
+
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, reason);
vm->pid = -1;
vm->def->id = -1;
int virBhyveProcessStart(virConnectPtr conn,
bhyveConnPtr driver,
virDomainObjPtr vm,
- virDomainRunningReason reason);
+ virDomainRunningReason reason,
+ unsigned int flags);
int virBhyveProcessStop(bhyveConnPtr driver,
virDomainObjPtr vm,
virDomainShutoffReason reason);
+typedef enum {
+ VIR_BHYVE_PROCESS_START_AUTODESTROY = 1 << 0,
+} bhyveProcessStartFlags;
+
#endif /* __BHYVE_PROCESS_H__ */
# include "domain_conf.h"
# include "configmake.h"
# include "virthread.h"
+# include "virclosecallbacks.h"
# define BHYVE_AUTOSTART_DIR SYSCONFDIR "/libvirt/bhyve/autostart"
# define BHYVE_CONFIG_DIR SYSCONFDIR "/libvirt/bhyve"
virCapsPtr caps;
virDomainXMLOptionPtr xmlopt;
char *pidfile;
+
+ virCloseCallbacksPtr closeCallbacks;
};
typedef struct _bhyveConn bhyveConn;