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
bhyveDomainOpenConsole(virDomainPtr dom,
const char *dev_name G_GNUC_UNUSED,
.domainDestroyFlags = bhyveDomainDestroyFlags, /* 5.6.0 */
.domainShutdown = bhyveDomainShutdown, /* 1.3.3 */
.domainShutdownFlags = bhyveDomainShutdownFlags, /* 5.6.0 */
+ .domainReboot = bhyveDomainReboot, /* TBD */
.domainLookupByUUID = bhyveDomainLookupByUUID, /* 1.2.2 */
.domainLookupByName = bhyveDomainLookupByName, /* 1.2.2 */
.domainLookupByID = bhyveDomainLookupByID, /* 1.2.3 */
struct _bhyveMonitor {
virObject parent;
- int kq;
- int watch;
bhyveConnPtr driver;
virDomainObjPtr vm;
+ int kq;
+ int watch;
+ bool reboot;
};
static virClassPtr bhyveMonitorClass;
mon->watch = -1;
}
+void
+bhyveMonitorSetReboot(bhyveMonitorPtr mon)
+{
+ mon->reboot = true;
+}
+
static void
bhyveMonitorIO(int watch, int kq, int events G_GNUC_UNUSED, void *opaque)
{
name, WTERMSIG(status));
virBhyveProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_CRASHED);
} else if (WIFEXITED(status)) {
- if (WEXITSTATUS(status) == 0) {
+ if (WEXITSTATUS(status) == 0 || mon->reboot) {
/* 0 - reboot */
- /* TODO: Implementing reboot is a little more complicated. */
- VIR_INFO("Guest %s rebooted; destroying domain.", name);
- virBhyveProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
+ VIR_INFO("Guest %s rebooted; restarting domain.", name);
+ virBhyveProcessRestart(driver, vm);
} else if (WEXITSTATUS(status) < 3) {
/* 1 - shutdown, 2 - halt, 3 - triple fault. others - error */
VIR_INFO("Guest %s shut itself down; destroying domain.", name);
return NULL;
mon->driver = driver;
+ mon->reboot = false;
virObjectRef(vm);
mon->vm = vm;
bhyveMonitorPtr bhyveMonitorOpen(virDomainObjPtr vm, bhyveConnPtr driver);
void bhyveMonitorClose(bhyveMonitorPtr mon);
+
+void bhyveMonitorSetReboot(bhyveMonitorPtr mon);
VIR_HOOK_SUBOP_END, NULL, NULL, NULL);
}
-int
-virBhyveProcessStart(virConnectPtr conn,
- virDomainObjPtr vm,
- virDomainRunningReason reason,
- unsigned int flags)
+static int
+virBhyveProcessStartImpl(bhyveConnPtr driver,
+ virDomainObjPtr vm,
+ virDomainRunningReason reason)
{
char *devmap_file = NULL;
char *devicemap = NULL;
int logfd = -1;
virCommandPtr cmd = NULL;
virCommandPtr load_cmd = NULL;
- bhyveConnPtr driver = conn->privateData;
bhyveDomainObjPrivatePtr priv = vm->privateData;
int ret = -1, rc;
if (bhyveDomainAssignAddresses(vm->def, NULL) < 0)
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 */
if (!(cmd = virBhyveProcessBuildBhyveCmd(driver, vm->def, false)))
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;
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason);
priv->mon = bhyveMonitorOpen(vm, driver);
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
virBhyveProcessStop(bhyveConnPtr driver,
virDomainObjPtr vm,
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
virBhyveGetDomainTotalCpuStats(virDomainObjPtr vm,
unsigned long long *cpustats)
virDomainObjPtr vm,
virDomainShutoffReason reason);
+int virBhyveProcessRestart(bhyveConnPtr driver,
+ virDomainObjPtr vm);
+
int virBhyveProcessShutdown(virDomainObjPtr vm);
int virBhyveGetDomainTotalCpuStats(virDomainObjPtr vm,