]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
bhyve: monitor: do not override domain's privateData
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Wed, 4 Nov 2015 15:08:00 +0000 (18:08 +0300)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Tue, 17 Nov 2015 09:44:26 +0000 (12:44 +0300)
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
src/bhyve/bhyve_monitor.c
src/bhyve/bhyve_process.c

index b8ef22a444bf5c08ab273c0aebe97971746bb897..0a60392166367bee377ac209c2471a544e579538 100644 (file)
 # 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;
index 131672014a1e715d64bdc4912c44b2d12486b2dc..37c9e791467e2b314a32a606a9ff1f6887a0a866 100644 (file)
@@ -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",
index 284641a808fe502ccfbe2eebbde1cbb2d6f11e46..42255d21bddb62d4ccfeccd2c31ac3a6ae58a1b9 100644 (file)
@@ -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);
          }
     }