[PATCH] bhyve: domain events support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Support events for these functions:

 - domainDefineXML
 - domainUndefine
 - domainCreate{WithFlags,XML}
 - domainDestroy
---
 src/bhyve/bhyve_driver.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++-
 src/bhyve/bhyve_utils.h  |  3 ++
 2 files changed, 90 insertions(+), 1 deletion(-)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 6d681fd..41fd115 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -36,6 +36,7 @@
 #include "network_conf.h"
 #include "interface_conf.h"
 #include "domain_audit.h"
+#include "domain_event.h"
 #include "domain_conf.h"
 #include "snapshot_conf.h"
 #include "fdstream.h"
@@ -451,6 +452,7 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml)
     virDomainDefPtr def = NULL;
     virDomainDefPtr oldDef = NULL;
     virDomainObjPtr vm = NULL;
+    virObjectEventPtr event = NULL;
     virCapsPtr caps = NULL;
 
     caps = bhyveDriverGetCapabilities(privconn);
@@ -479,6 +481,12 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml)
         goto cleanup;
     }
 
+    event = virDomainEventLifecycleNewFromObj(vm,
+                                              VIR_DOMAIN_EVENT_DEFINED,
+                                              !oldDef ?
+                                              VIR_DOMAIN_EVENT_DEFINED_ADDED :
+                                              VIR_DOMAIN_EVENT_DEFINED_UPDATED);
+
     dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
     if (dom)
         dom->id = vm->def->id;
@@ -489,6 +497,8 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml)
     virDomainDefFree(oldDef);
     if (vm)
         virObjectUnlock(vm);
+    if (event)
+        virObjectEventStateQueue(privconn->domainEventState, event);
 
     return dom;
 }
@@ -497,6 +507,7 @@ static int
 bhyveDomainUndefine(virDomainPtr domain)
 {
     bhyveConnPtr privconn = domain->conn->privateData;
+    virObjectEventPtr event = NULL;
     virDomainObjPtr vm;
     int ret = -1;
 
@@ -517,6 +528,10 @@ bhyveDomainUndefine(virDomainPtr domain)
                               vm) < 0)
         goto cleanup;
 
+    event = virDomainEventLifecycleNewFromObj(vm,
+                                              VIR_DOMAIN_EVENT_UNDEFINED,
+                                              VIR_DOMAIN_EVENT_UNDEFINED_REMOVED);
+
     if (virDomainObjIsActive(vm)) {
         vm->persistent = 0;
     } else {
@@ -527,7 +542,10 @@ bhyveDomainUndefine(virDomainPtr domain)
     ret = 0;
 
  cleanup:
-    virObjectUnlock(vm);
+    if (vm)
+        virObjectUnlock(vm);
+    if (event)
+        virObjectEventStateQueue(privconn->domainEventState, event);
     return ret;
 }
 
@@ -703,6 +721,7 @@ bhyveDomainCreateWithFlags(virDomainPtr dom,
 {
     bhyveConnPtr privconn = dom->conn->privateData;
     virDomainObjPtr vm;
+    virObjectEventPtr event = NULL;
     unsigned int start_flags = 0;
     int ret = -1;
 
@@ -727,8 +746,16 @@ bhyveDomainCreateWithFlags(virDomainPtr dom,
                                VIR_DOMAIN_RUNNING_BOOTED,
                                start_flags);
 
+    if (ret == 0) {
+        event = virDomainEventLifecycleNewFromObj(vm,
+                                                  VIR_DOMAIN_EVENT_STARTED,
+                                                  VIR_DOMAIN_EVENT_STARTED_BOOTED);
+    }
+
  cleanup:
     virObjectUnlock(vm);
+    if (event)
+        virObjectEventStateQueue(privconn->domainEventState, event);
     return ret;
 }
 
@@ -747,6 +774,7 @@ bhyveDomainCreateXML(virConnectPtr conn,
     virDomainPtr dom = NULL;
     virDomainDefPtr def = NULL;
     virDomainObjPtr vm = NULL;
+    virObjectEventPtr event = NULL;
     virCapsPtr caps = NULL;
     unsigned int start_flags = 0;
 
@@ -784,6 +812,10 @@ bhyveDomainCreateXML(virConnectPtr conn,
         goto cleanup;
     }
 
+    event = virDomainEventLifecycleNewFromObj(vm,
+                                              VIR_DOMAIN_EVENT_STARTED,
+                                              VIR_DOMAIN_EVENT_STARTED_BOOTED);
+
     dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
     if (dom)
         dom->id = vm->def->id;
@@ -793,6 +825,8 @@ bhyveDomainCreateXML(virConnectPtr conn,
     virDomainDefFree(def);
     if (vm)
         virObjectUnlock(vm);
+    if (event)
+        virObjectEventStateQueue(privconn->domainEventState, event);
 
     return dom;
 }
@@ -802,6 +836,7 @@ bhyveDomainDestroy(virDomainPtr dom)
 {
     bhyveConnPtr privconn = dom->conn->privateData;
     virDomainObjPtr vm;
+    virObjectEventPtr event = NULL;
     int ret = -1;
 
     if (!(vm = bhyveDomObjFromDomain(dom)))
@@ -817,6 +852,9 @@ bhyveDomainDestroy(virDomainPtr dom)
     }
 
     ret = virBhyveProcessStop(privconn, vm, VIR_DOMAIN_SHUTOFF_DESTROYED);
+    event = virDomainEventLifecycleNewFromObj(vm,
+                                              VIR_DOMAIN_EVENT_STOPPED,
+                                              VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
 
     if (!vm->persistent) {
         virDomainObjListRemove(privconn->domains, vm);
@@ -826,6 +864,8 @@ bhyveDomainDestroy(virDomainPtr dom)
  cleanup:
     if (vm)
         virObjectUnlock(vm);
+    if (event)
+        virObjectEventStateQueue(privconn->domainEventState, event);
     return ret;
 }
 
@@ -983,6 +1023,7 @@ bhyveStateCleanup(void)
     virObjectUnref(bhyve_driver->caps);
     virObjectUnref(bhyve_driver->xmlopt);
     virObjectUnref(bhyve_driver->closeCallbacks);
+    virObjectEventStateFree(bhyve_driver->domainEventState);
 
     virMutexDestroy(&bhyve_driver->lock);
     VIR_FREE(bhyve_driver);
@@ -1021,6 +1062,9 @@ bhyveStateInitialize(bool priveleged ATTRIBUTE_UNUSED,
     if (!(bhyve_driver->domains = virDomainObjListNew()))
         goto cleanup;
 
+    if (!(bhyve_driver->domainEventState = virObjectEventStateNew()))
+        goto cleanup;
+
     if (virFileMakePath(BHYVE_LOG_DIR) < 0) {
         virReportSystemError(errno,
                              _("Failed to mkdir %s"),
@@ -1172,6 +1216,46 @@ bhyveConnectCompareCPU(virConnectPtr conn,
     return ret;
 }
 
+static int
+bhyveConnectDomainEventRegisterAny(virConnectPtr conn,
+                                   virDomainPtr dom,
+                                   int eventID,
+                                   virConnectDomainEventGenericCallback callback,
+                                   void *opaque,
+                                   virFreeCallback freecb)
+{
+    bhyveConnPtr privconn = conn->privateData;
+    int ret;
+
+    if (virConnectDomainEventRegisterAnyEnsureACL(conn) < 0)
+        return -1;
+
+    if (virDomainEventStateRegisterID(conn,
+                                      privconn->domainEventState,
+                                      dom, eventID,
+                                      callback, opaque, freecb, &ret) < 0)
+        ret = -1;
+
+    return ret;
+}
+
+static int
+bhyveConnectDomainEventDeregisterAny(virConnectPtr conn,
+                                     int callbackID)
+{
+    bhyveConnPtr privconn = conn->privateData;
+
+    if (virConnectDomainEventDeregisterAnyEnsureACL(conn) < 0)
+        return -1;
+
+    if (virObjectEventStateDeregisterID(conn,
+                                        privconn->domainEventState,
+                                        callbackID) < 0)
+        return -1;
+
+    return 0;
+}
+
 static virDriver bhyveDriver = {
     .no = VIR_DRV_BHYVE,
     .name = "bhyve",
@@ -1214,6 +1298,8 @@ static virDriver bhyveDriver = {
     .nodeSetMemoryParameters = bhyveNodeSetMemoryParameters, /* 1.2.3 */
     .connectBaselineCPU = bhyveConnectBaselineCPU, /* 1.2.4 */
     .connectCompareCPU = bhyveConnectCompareCPU, /* 1.2.4 */
+    .connectDomainEventRegisterAny = bhyveConnectDomainEventRegisterAny, /* 1.2.4 */
+    .connectDomainEventDeregisterAny = bhyveConnectDomainEventDeregisterAny, /* 1.2.4 */
 };
 
 
diff --git a/src/bhyve/bhyve_utils.h b/src/bhyve/bhyve_utils.h
index 94f31b0..c3ef37a 100644
--- a/src/bhyve/bhyve_utils.h
+++ b/src/bhyve/bhyve_utils.h
@@ -23,6 +23,7 @@
 # define __BHYVE_UTILS_H__
 
 # include "driver.h"
+# include "domain_event.h"
 # include "domain_conf.h"
 # include "configmake.h"
 # include "virthread.h"
@@ -40,6 +41,8 @@ struct _bhyveConn {
     virDomainXMLOptionPtr xmlopt;
     char *pidfile;
 
+    virObjectEventStatePtr domainEventState;
+
     virCloseCallbacksPtr closeCallbacks;
 };
 
-- 
1.9.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]