#include <sys/time.h>
#include <sys/wait.h>
+#include "bhyve_domain.h"
#include "bhyve_monitor.h"
#include "bhyve_process.h"
#include "viralloc.h"
struct _bhyveMonitor {
int kq;
int watch;
- virDomainObjPtr vm;
bhyveConnPtr driver;
};
bhyveMonitorIO(int watch, int kq, int events ATTRIBUTE_UNUSED, void *opaque)
{
const struct timespec zerowait = { 0, 0 };
- bhyveMonitorPtr mon = opaque;
+ virDomainObjPtr vm = opaque;
+ bhyveDomainObjPrivatePtr priv = vm->privateData;
+ bhyveMonitorPtr mon = priv->mon;
struct kevent kev;
int rc, status;
}
if (kev.filter == EVFILT_PROC && (kev.fflags & NOTE_EXIT) != 0) {
- if ((pid_t)kev.ident != mon->vm->pid) {
+ if ((pid_t)kev.ident != vm->pid) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("event from unexpected proc %ju!=%ju"),
- (uintmax_t)mon->vm->pid, (uintmax_t)kev.ident);
+ (uintmax_t)vm->pid, (uintmax_t)kev.ident);
return;
}
if (WIFSIGNALED(status) && WCOREDUMP(status)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Guest %s got signal %d and crashed"),
- mon->vm->def->name,
+ vm->def->name,
WTERMSIG(status));
- virBhyveProcessStop(mon->driver, mon->vm,
+ virBhyveProcessStop(mon->driver, vm,
VIR_DOMAIN_SHUTOFF_CRASHED);
} else if (WIFEXITED(status)) {
if (WEXITSTATUS(status) == 0) {
/* 0 - reboot */
/* TODO: Implementing reboot is a little more complicated. */
VIR_INFO("Guest %s rebooted; destroying domain.",
- mon->vm->def->name);
- virBhyveProcessStop(mon->driver, mon->vm,
+ vm->def->name);
+ virBhyveProcessStop(mon->driver, vm,
VIR_DOMAIN_SHUTOFF_SHUTDOWN);
} else if (WEXITSTATUS(status) < 3) {
/* 1 - shutdown, 2 - halt, 3 - triple fault. others - error */
VIR_INFO("Guest %s shut itself down; destroying domain.",
- mon->vm->def->name);
- virBhyveProcessStop(mon->driver, mon->vm,
+ vm->def->name);
+ virBhyveProcessStop(mon->driver, vm,
VIR_DOMAIN_SHUTOFF_SHUTDOWN);
} else {
VIR_INFO("Guest %s had an error and exited with status %d; destroying domain.",
- mon->vm->def->name, WEXITSTATUS(status));
- virBhyveProcessStop(mon->driver, mon->vm,
+ vm->def->name, WEXITSTATUS(status));
+ virBhyveProcessStop(mon->driver, vm,
VIR_DOMAIN_SHUTOFF_UNKNOWN);
}
}
static void
bhyveMonitorRelease(void *opaque)
{
- bhyveMonitorPtr mon = opaque;
+ virDomainObjPtr vm = opaque;
+ bhyveDomainObjPrivatePtr priv = vm->privateData;
+ bhyveMonitorPtr mon = priv->mon;
VIR_FORCE_CLOSE(mon->kq);
- virObjectUnref(mon->vm);
VIR_FREE(mon);
}
bhyveMonitorPtr
bhyveMonitorOpen(virDomainObjPtr vm, bhyveConnPtr driver)
{
- bhyveMonitorPtr mon;
+ bhyveMonitorPtr mon = NULL;
struct kevent kev;
int rc;
if (VIR_ALLOC(mon) < 0)
return NULL;
- mon->vm = virObjectRef(vm);
mon->driver = driver;
mon->kq = kqueue();
VIR_EVENT_HANDLE_ERROR |
VIR_EVENT_HANDLE_HANGUP,
bhyveMonitorIO,
- mon,
+ vm,
bhyveMonitorRelease);
if (mon->watch < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
virCommandPtr cmd = NULL;
virCommandPtr load_cmd = NULL;
bhyveConnPtr privconn = conn->privateData;
+ bhyveDomainObjPrivatePtr priv = vm->privateData;
int ret = -1, rc;
if (virAsprintf(&logfile, "%s/%s.log",
vm->def->id = vm->pid;
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason);
- vm->privateData = bhyveMonitorOpen(vm, driver);
+ priv->mon = bhyveMonitorOpen(vm, driver);
if (virDomainSaveStatus(driver->xmlopt,
BHYVE_STATE_DIR,
{
int ret = -1;
virCommandPtr cmd = NULL;
+ bhyveDomainObjPrivatePtr priv = vm->privateData;
if (!virDomainObjIsActive(vm)) {
VIR_DEBUG("VM '%s' not active", vm->def->name);
return -1;
}
- if (vm->privateData != NULL)
- bhyveMonitorClose((bhyveMonitorPtr)vm->privateData);
+ if ((priv != NULL) && (priv->mon != NULL))
+ bhyveMonitorClose(priv->mon);
/* First, try to kill 'bhyve' process */
if (virProcessKillPainfully(vm->pid, true) != 0)
int nprocs;
char **proc_argv;
char *expected_proctitle = NULL;
+ bhyveDomainObjPrivatePtr priv = vm->privateData;
int ret = -1;
if (!virDomainObjIsActive(vm))
if (proc_argv && proc_argv[0]) {
if (STREQ(expected_proctitle, proc_argv[0])) {
ret = 0;
- vm->privateData = bhyveMonitorOpen(vm, data->driver);
+ priv->mon = bhyveMonitorOpen(vm, data->driver);
}
}