提交 f2357ba0 编写于 作者: R Ryan Moeller 提交者: Daniel P. Berrangé

bhyve: add reboot support

Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
Signed-off-by: NRyan Moeller <ryan@iXsystems.com>
上级 51451662
...@@ -1013,6 +1013,35 @@ bhyveDomainShutdown(virDomainPtr dom) ...@@ -1013,6 +1013,35 @@ bhyveDomainShutdown(virDomainPtr dom)
return bhyveDomainShutdownFlags(dom, 0); return bhyveDomainShutdownFlags(dom, 0);
} }
static int
bhyveDomainReboot(virDomainPtr dom, unsigned int flags)
{
virConnectPtr conn = dom->conn;
virDomainObjPtr vm;
bhyveDomainObjPrivatePtr priv;
int ret = -1;
virCheckFlags(VIR_DOMAIN_REBOOT_ACPI_POWER_BTN, -1);
if (!(vm = bhyveDomObjFromDomain(dom)))
goto cleanup;
if (virDomainRebootEnsureACL(conn, vm->def, flags) < 0)
goto cleanup;
if (virDomainObjCheckActive(vm) < 0)
goto cleanup;
priv = vm->privateData;
bhyveMonitorSetReboot(priv->mon);
ret = virBhyveProcessShutdown(vm);
cleanup:
virDomainObjEndAPI(&vm);
return ret;
}
static int static int
bhyveDomainOpenConsole(virDomainPtr dom, bhyveDomainOpenConsole(virDomainPtr dom,
const char *dev_name G_GNUC_UNUSED, const char *dev_name G_GNUC_UNUSED,
...@@ -1657,6 +1686,7 @@ static virHypervisorDriver bhyveHypervisorDriver = { ...@@ -1657,6 +1686,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
.domainDestroyFlags = bhyveDomainDestroyFlags, /* 5.6.0 */ .domainDestroyFlags = bhyveDomainDestroyFlags, /* 5.6.0 */
.domainShutdown = bhyveDomainShutdown, /* 1.3.3 */ .domainShutdown = bhyveDomainShutdown, /* 1.3.3 */
.domainShutdownFlags = bhyveDomainShutdownFlags, /* 5.6.0 */ .domainShutdownFlags = bhyveDomainShutdownFlags, /* 5.6.0 */
.domainReboot = bhyveDomainReboot, /* TBD */
.domainLookupByUUID = bhyveDomainLookupByUUID, /* 1.2.2 */ .domainLookupByUUID = bhyveDomainLookupByUUID, /* 1.2.2 */
.domainLookupByName = bhyveDomainLookupByName, /* 1.2.2 */ .domainLookupByName = bhyveDomainLookupByName, /* 1.2.2 */
.domainLookupByID = bhyveDomainLookupByID, /* 1.2.3 */ .domainLookupByID = bhyveDomainLookupByID, /* 1.2.3 */
......
...@@ -41,10 +41,11 @@ VIR_LOG_INIT("bhyve.bhyve_monitor"); ...@@ -41,10 +41,11 @@ VIR_LOG_INIT("bhyve.bhyve_monitor");
struct _bhyveMonitor { struct _bhyveMonitor {
virObject parent; virObject parent;
int kq;
int watch;
bhyveConnPtr driver; bhyveConnPtr driver;
virDomainObjPtr vm; virDomainObjPtr vm;
int kq;
int watch;
bool reboot;
}; };
static virClassPtr bhyveMonitorClass; static virClassPtr bhyveMonitorClass;
...@@ -100,6 +101,12 @@ bhyveMonitorUnregister(bhyveMonitorPtr mon) ...@@ -100,6 +101,12 @@ bhyveMonitorUnregister(bhyveMonitorPtr mon)
mon->watch = -1; mon->watch = -1;
} }
void
bhyveMonitorSetReboot(bhyveMonitorPtr mon)
{
mon->reboot = true;
}
static void static void
bhyveMonitorIO(int watch, int kq, int events G_GNUC_UNUSED, void *opaque) bhyveMonitorIO(int watch, int kq, int events G_GNUC_UNUSED, void *opaque)
{ {
...@@ -148,11 +155,10 @@ bhyveMonitorIO(int watch, int kq, int events G_GNUC_UNUSED, void *opaque) ...@@ -148,11 +155,10 @@ bhyveMonitorIO(int watch, int kq, int events G_GNUC_UNUSED, void *opaque)
name, WTERMSIG(status)); name, WTERMSIG(status));
virBhyveProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_CRASHED); virBhyveProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_CRASHED);
} else if (WIFEXITED(status)) { } else if (WIFEXITED(status)) {
if (WEXITSTATUS(status) == 0) { if (WEXITSTATUS(status) == 0 || mon->reboot) {
/* 0 - reboot */ /* 0 - reboot */
/* TODO: Implementing reboot is a little more complicated. */ VIR_INFO("Guest %s rebooted; restarting domain.", name);
VIR_INFO("Guest %s rebooted; destroying domain.", name); virBhyveProcessRestart(driver, vm);
virBhyveProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
} else if (WEXITSTATUS(status) < 3) { } else if (WEXITSTATUS(status) < 3) {
/* 1 - shutdown, 2 - halt, 3 - triple fault. others - error */ /* 1 - shutdown, 2 - halt, 3 - triple fault. others - error */
VIR_INFO("Guest %s shut itself down; destroying domain.", name); VIR_INFO("Guest %s shut itself down; destroying domain.", name);
...@@ -179,6 +185,7 @@ bhyveMonitorOpenImpl(virDomainObjPtr vm, bhyveConnPtr driver) ...@@ -179,6 +185,7 @@ bhyveMonitorOpenImpl(virDomainObjPtr vm, bhyveConnPtr driver)
return NULL; return NULL;
mon->driver = driver; mon->driver = driver;
mon->reboot = false;
virObjectRef(vm); virObjectRef(vm);
mon->vm = vm; mon->vm = vm;
......
...@@ -29,3 +29,5 @@ typedef bhyveMonitor *bhyveMonitorPtr; ...@@ -29,3 +29,5 @@ typedef bhyveMonitor *bhyveMonitorPtr;
bhyveMonitorPtr bhyveMonitorOpen(virDomainObjPtr vm, bhyveConnPtr driver); bhyveMonitorPtr bhyveMonitorOpen(virDomainObjPtr vm, bhyveConnPtr driver);
void bhyveMonitorClose(bhyveMonitorPtr mon); void bhyveMonitorClose(bhyveMonitorPtr mon);
void bhyveMonitorSetReboot(bhyveMonitorPtr mon);
...@@ -110,11 +110,10 @@ bhyveProcessStopHook(virDomainObjPtr vm, virHookBhyveOpType op) ...@@ -110,11 +110,10 @@ bhyveProcessStopHook(virDomainObjPtr vm, virHookBhyveOpType op)
VIR_HOOK_SUBOP_END, NULL, NULL, NULL); VIR_HOOK_SUBOP_END, NULL, NULL, NULL);
} }
int static int
virBhyveProcessStart(virConnectPtr conn, virBhyveProcessStartImpl(bhyveConnPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
virDomainRunningReason reason, virDomainRunningReason reason)
unsigned int flags)
{ {
char *devmap_file = NULL; char *devmap_file = NULL;
char *devicemap = NULL; char *devicemap = NULL;
...@@ -122,7 +121,6 @@ virBhyveProcessStart(virConnectPtr conn, ...@@ -122,7 +121,6 @@ virBhyveProcessStart(virConnectPtr conn,
int logfd = -1; int logfd = -1;
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
virCommandPtr load_cmd = NULL; virCommandPtr load_cmd = NULL;
bhyveConnPtr driver = conn->privateData;
bhyveDomainObjPrivatePtr priv = vm->privateData; bhyveDomainObjPrivatePtr priv = vm->privateData;
int ret = -1, rc; int ret = -1, rc;
...@@ -154,10 +152,6 @@ virBhyveProcessStart(virConnectPtr conn, ...@@ -154,10 +152,6 @@ virBhyveProcessStart(virConnectPtr conn,
if (bhyveDomainAssignAddresses(vm->def, NULL) < 0) if (bhyveDomainAssignAddresses(vm->def, NULL) < 0)
goto cleanup; goto cleanup;
/* Run an early hook to setup missing devices. */
if (bhyveProcessStartHook(vm, VIR_HOOK_BHYVE_OP_PREPARE) < 0)
goto cleanup;
/* Call bhyve to start the VM */ /* Call bhyve to start the VM */
if (!(cmd = virBhyveProcessBuildBhyveCmd(driver, vm->def, false))) if (!(cmd = virBhyveProcessBuildBhyveCmd(driver, vm->def, false)))
goto cleanup; goto cleanup;
...@@ -213,11 +207,6 @@ virBhyveProcessStart(virConnectPtr conn, ...@@ -213,11 +207,6 @@ virBhyveProcessStart(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
if (flags & VIR_BHYVE_PROCESS_START_AUTODESTROY &&
virCloseCallbacksSet(driver->closeCallbacks, vm,
conn, bhyveProcessAutoDestroy) < 0)
goto cleanup;
vm->def->id = vm->pid; vm->def->id = vm->pid;
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason); virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason);
priv->mon = bhyveMonitorOpen(vm, driver); priv->mon = bhyveMonitorOpen(vm, driver);
...@@ -262,6 +251,26 @@ virBhyveProcessStart(virConnectPtr conn, ...@@ -262,6 +251,26 @@ virBhyveProcessStart(virConnectPtr conn,
return ret; return ret;
} }
int
virBhyveProcessStart(virConnectPtr conn,
virDomainObjPtr vm,
virDomainRunningReason reason,
unsigned int flags)
{
bhyveConnPtr driver = conn->privateData;
/* Run an early hook to setup missing devices. */
if (bhyveProcessStartHook(vm, VIR_HOOK_BHYVE_OP_PREPARE) < 0)
return -1;
if (flags & VIR_BHYVE_PROCESS_START_AUTODESTROY &&
virCloseCallbacksSet(driver->closeCallbacks, vm,
conn, bhyveProcessAutoDestroy) < 0)
return -1;
return virBhyveProcessStartImpl(driver, vm, reason);
}
int int
virBhyveProcessStop(bhyveConnPtr driver, virBhyveProcessStop(bhyveConnPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
...@@ -349,6 +358,19 @@ virBhyveProcessShutdown(virDomainObjPtr vm) ...@@ -349,6 +358,19 @@ virBhyveProcessShutdown(virDomainObjPtr vm)
return 0; return 0;
} }
int
virBhyveProcessRestart(bhyveConnPtr driver,
virDomainObjPtr vm)
{
if (virBhyveProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN) < 0)
return -1;
if (virBhyveProcessStartImpl(driver, vm, VIR_DOMAIN_RUNNING_BOOTED) < 0)
return -1;
return 0;
}
int int
virBhyveGetDomainTotalCpuStats(virDomainObjPtr vm, virBhyveGetDomainTotalCpuStats(virDomainObjPtr vm,
unsigned long long *cpustats) unsigned long long *cpustats)
......
...@@ -32,6 +32,9 @@ int virBhyveProcessStop(bhyveConnPtr driver, ...@@ -32,6 +32,9 @@ int virBhyveProcessStop(bhyveConnPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
virDomainShutoffReason reason); virDomainShutoffReason reason);
int virBhyveProcessRestart(bhyveConnPtr driver,
virDomainObjPtr vm);
int virBhyveProcessShutdown(virDomainObjPtr vm); int virBhyveProcessShutdown(virDomainObjPtr vm);
int virBhyveGetDomainTotalCpuStats(virDomainObjPtr vm, int virBhyveGetDomainTotalCpuStats(virDomainObjPtr vm,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册