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

bhyve: add domainCreateWithFlags support

The only supported flag for now is 'autodestroy'. In order to
support 'autodestroy', add support for close callbacks.
上级 24aa0d18
......@@ -178,6 +178,9 @@ bhyveConnectOpen(virConnectPtr conn,
static int
bhyveConnectClose(virConnectPtr conn)
{
bhyveConnPtr privconn = conn->privateData;
virCloseCallbacksRun(privconn->closeCallbacks, conn, privconn->domains, privconn);
conn->privateData = NULL;
return 0;
......@@ -530,16 +533,23 @@ cleanup:
}
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)) {
......@@ -549,13 +559,20 @@ bhyveDomainCreate(virDomainPtr dom)
}
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)
{
......@@ -629,6 +646,7 @@ bhyveStateCleanup(void)
virObjectUnref(bhyve_driver->domains);
virObjectUnref(bhyve_driver->caps);
virObjectUnref(bhyve_driver->xmlopt);
virObjectUnref(bhyve_driver->closeCallbacks);
virMutexDestroy(&bhyve_driver->lock);
VIR_FREE(bhyve_driver);
......@@ -655,6 +673,9 @@ bhyveStateInitialize(bool priveleged ATTRIBUTE_UNUSED,
return -1;
}
if (!(bhyve_driver->closeCallbacks = virCloseCallbacksNew()))
goto cleanup;
if (!(bhyve_driver->caps = bhyveBuildCapabilities()))
goto cleanup;
......@@ -773,6 +794,7 @@ static virDriver bhyveDriver = {
.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 */
......
......@@ -46,11 +46,29 @@
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;
......@@ -121,21 +139,25 @@ virBhyveProcessStart(virConnectPtr conn,
/* 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;
......@@ -203,6 +225,9 @@ virBhyveProcessStop(bhyveConnPtr driver,
ret = 0;
virCloseCallbacksUnset(driver->closeCallbacks, vm,
bhyveProcessAutoDestroy);
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, reason);
vm->pid = -1;
vm->def->id = -1;
......
......@@ -27,10 +27,15 @@
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__ */
......@@ -26,6 +26,7 @@
# 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"
......@@ -38,6 +39,8 @@ struct _bhyveConn {
virCapsPtr caps;
virDomainXMLOptionPtr xmlopt;
char *pidfile;
virCloseCallbacksPtr closeCallbacks;
};
typedef struct _bhyveConn bhyveConn;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册