Current monitor code overrides domain object's privateData, e.g. in virBhyveProcessStart(): vm->privateData = bhyveMonitorOpen(vm, driver); where bhyveMonitorPtr() returns bhyveMonitorPtr. This is not right thing to do, so make bhyveMonitorPtr a part of the bhyveDomainObjPrivate struct and change related code accordingly. --- src/bhyve/bhyve_domain.h | 4 ++++ src/bhyve/bhyve_monitor.c | 36 +++++++++++++++++++----------------- src/bhyve/bhyve_process.c | 11 +++++++---- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/bhyve/bhyve_domain.h b/src/bhyve/bhyve_domain.h index b8ef22a..0a60392 100644 --- a/src/bhyve/bhyve_domain.h +++ b/src/bhyve/bhyve_domain.h @@ -26,11 +26,15 @@ # include "domain_addr.h" # include "domain_conf.h" +# include "bhyve_monitor.h" + typedef struct _bhyveDomainObjPrivate bhyveDomainObjPrivate; typedef bhyveDomainObjPrivate *bhyveDomainObjPrivatePtr; struct _bhyveDomainObjPrivate { virDomainPCIAddressSetPtr pciaddrs; bool persistentAddrs; + + bhyveMonitorPtr mon; }; extern virDomainXMLPrivateDataCallbacks virBhyveDriverPrivateDataCallbacks; diff --git a/src/bhyve/bhyve_monitor.c b/src/bhyve/bhyve_monitor.c index 1316720..37c9e79 100644 --- a/src/bhyve/bhyve_monitor.c +++ b/src/bhyve/bhyve_monitor.c @@ -27,6 +27,7 @@ #include <sys/time.h> #include <sys/wait.h> +#include "bhyve_domain.h" #include "bhyve_monitor.h" #include "bhyve_process.h" #include "viralloc.h" @@ -41,7 +42,6 @@ VIR_LOG_INIT("bhyve.bhyve_monitor"); struct _bhyveMonitor { int kq; int watch; - virDomainObjPtr vm; bhyveConnPtr driver; }; @@ -49,7 +49,9 @@ static void 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; @@ -75,10 +77,10 @@ bhyveMonitorIO(int watch, int kq, int events ATTRIBUTE_UNUSED, void *opaque) } 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; } @@ -86,28 +88,28 @@ bhyveMonitorIO(int watch, int kq, int events ATTRIBUTE_UNUSED, void *opaque) 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); } } @@ -117,24 +119,24 @@ bhyveMonitorIO(int watch, int kq, int events ATTRIBUTE_UNUSED, void *opaque) 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(); @@ -157,7 +159,7 @@ bhyveMonitorOpen(virDomainObjPtr vm, bhyveConnPtr driver) VIR_EVENT_HANDLE_ERROR | VIR_EVENT_HANDLE_HANGUP, bhyveMonitorIO, - mon, + vm, bhyveMonitorRelease); if (mon->watch < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index 284641a..42255d2 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -113,6 +113,7 @@ virBhyveProcessStart(virConnectPtr conn, 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", @@ -210,7 +211,7 @@ virBhyveProcessStart(virConnectPtr conn, 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, @@ -257,6 +258,7 @@ virBhyveProcessStop(bhyveConnPtr driver, { int ret = -1; virCommandPtr cmd = NULL; + bhyveDomainObjPrivatePtr priv = vm->privateData; if (!virDomainObjIsActive(vm)) { VIR_DEBUG("VM '%s' not active", vm->def->name); @@ -270,8 +272,8 @@ virBhyveProcessStop(bhyveConnPtr driver, 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) @@ -358,6 +360,7 @@ virBhyveProcessReconnect(virDomainObjPtr vm, int nprocs; char **proc_argv; char *expected_proctitle = NULL; + bhyveDomainObjPrivatePtr priv = vm->privateData; int ret = -1; if (!virDomainObjIsActive(vm)) @@ -379,7 +382,7 @@ virBhyveProcessReconnect(virDomainObjPtr 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); } } -- 2.6.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list