mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 15:15:25 +00:00
bhyve: domain events support
Support events for these functions: - domainDefineXML - domainUndefine - domainCreate{WithFlags,XML} - domainDestroy
This commit is contained in:
parent
b0312d9fbd
commit
5c13c3202f
@ -36,6 +36,7 @@
|
|||||||
#include "network_conf.h"
|
#include "network_conf.h"
|
||||||
#include "interface_conf.h"
|
#include "interface_conf.h"
|
||||||
#include "domain_audit.h"
|
#include "domain_audit.h"
|
||||||
|
#include "domain_event.h"
|
||||||
#include "domain_conf.h"
|
#include "domain_conf.h"
|
||||||
#include "snapshot_conf.h"
|
#include "snapshot_conf.h"
|
||||||
#include "fdstream.h"
|
#include "fdstream.h"
|
||||||
@ -486,6 +487,7 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml)
|
|||||||
virDomainDefPtr def = NULL;
|
virDomainDefPtr def = NULL;
|
||||||
virDomainDefPtr oldDef = NULL;
|
virDomainDefPtr oldDef = NULL;
|
||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
|
virObjectEventPtr event = NULL;
|
||||||
virCapsPtr caps = NULL;
|
virCapsPtr caps = NULL;
|
||||||
|
|
||||||
caps = bhyveDriverGetCapabilities(privconn);
|
caps = bhyveDriverGetCapabilities(privconn);
|
||||||
@ -514,6 +516,12 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml)
|
|||||||
goto cleanup;
|
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);
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
||||||
if (dom)
|
if (dom)
|
||||||
dom->id = vm->def->id;
|
dom->id = vm->def->id;
|
||||||
@ -524,6 +532,8 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml)
|
|||||||
virDomainDefFree(oldDef);
|
virDomainDefFree(oldDef);
|
||||||
if (vm)
|
if (vm)
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
|
if (event)
|
||||||
|
virObjectEventStateQueue(privconn->domainEventState, event);
|
||||||
|
|
||||||
return dom;
|
return dom;
|
||||||
}
|
}
|
||||||
@ -532,6 +542,7 @@ static int
|
|||||||
bhyveDomainUndefine(virDomainPtr domain)
|
bhyveDomainUndefine(virDomainPtr domain)
|
||||||
{
|
{
|
||||||
bhyveConnPtr privconn = domain->conn->privateData;
|
bhyveConnPtr privconn = domain->conn->privateData;
|
||||||
|
virObjectEventPtr event = NULL;
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
@ -552,6 +563,10 @@ bhyveDomainUndefine(virDomainPtr domain)
|
|||||||
vm) < 0)
|
vm) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
event = virDomainEventLifecycleNewFromObj(vm,
|
||||||
|
VIR_DOMAIN_EVENT_UNDEFINED,
|
||||||
|
VIR_DOMAIN_EVENT_UNDEFINED_REMOVED);
|
||||||
|
|
||||||
if (virDomainObjIsActive(vm)) {
|
if (virDomainObjIsActive(vm)) {
|
||||||
vm->persistent = 0;
|
vm->persistent = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -562,7 +577,10 @@ bhyveDomainUndefine(virDomainPtr domain)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virObjectUnlock(vm);
|
if (vm)
|
||||||
|
virObjectUnlock(vm);
|
||||||
|
if (event)
|
||||||
|
virObjectEventStateQueue(privconn->domainEventState, event);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -795,6 +813,7 @@ bhyveDomainCreateWithFlags(virDomainPtr dom,
|
|||||||
{
|
{
|
||||||
bhyveConnPtr privconn = dom->conn->privateData;
|
bhyveConnPtr privconn = dom->conn->privateData;
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
|
virObjectEventPtr event = NULL;
|
||||||
unsigned int start_flags = 0;
|
unsigned int start_flags = 0;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
@ -819,8 +838,15 @@ bhyveDomainCreateWithFlags(virDomainPtr dom,
|
|||||||
VIR_DOMAIN_RUNNING_BOOTED,
|
VIR_DOMAIN_RUNNING_BOOTED,
|
||||||
start_flags);
|
start_flags);
|
||||||
|
|
||||||
|
if (ret == 0)
|
||||||
|
event = virDomainEventLifecycleNewFromObj(vm,
|
||||||
|
VIR_DOMAIN_EVENT_STARTED,
|
||||||
|
VIR_DOMAIN_EVENT_STARTED_BOOTED);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
|
if (event)
|
||||||
|
virObjectEventStateQueue(privconn->domainEventState, event);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -839,6 +865,7 @@ bhyveDomainCreateXML(virConnectPtr conn,
|
|||||||
virDomainPtr dom = NULL;
|
virDomainPtr dom = NULL;
|
||||||
virDomainDefPtr def = NULL;
|
virDomainDefPtr def = NULL;
|
||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
|
virObjectEventPtr event = NULL;
|
||||||
virCapsPtr caps = NULL;
|
virCapsPtr caps = NULL;
|
||||||
unsigned int start_flags = 0;
|
unsigned int start_flags = 0;
|
||||||
|
|
||||||
@ -876,6 +903,10 @@ bhyveDomainCreateXML(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event = virDomainEventLifecycleNewFromObj(vm,
|
||||||
|
VIR_DOMAIN_EVENT_STARTED,
|
||||||
|
VIR_DOMAIN_EVENT_STARTED_BOOTED);
|
||||||
|
|
||||||
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
||||||
if (dom)
|
if (dom)
|
||||||
dom->id = vm->def->id;
|
dom->id = vm->def->id;
|
||||||
@ -885,6 +916,8 @@ bhyveDomainCreateXML(virConnectPtr conn,
|
|||||||
virDomainDefFree(def);
|
virDomainDefFree(def);
|
||||||
if (vm)
|
if (vm)
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
|
if (event)
|
||||||
|
virObjectEventStateQueue(privconn->domainEventState, event);
|
||||||
|
|
||||||
return dom;
|
return dom;
|
||||||
}
|
}
|
||||||
@ -894,6 +927,7 @@ bhyveDomainDestroy(virDomainPtr dom)
|
|||||||
{
|
{
|
||||||
bhyveConnPtr privconn = dom->conn->privateData;
|
bhyveConnPtr privconn = dom->conn->privateData;
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
|
virObjectEventPtr event = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!(vm = bhyveDomObjFromDomain(dom)))
|
if (!(vm = bhyveDomObjFromDomain(dom)))
|
||||||
@ -909,6 +943,9 @@ bhyveDomainDestroy(virDomainPtr dom)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret = virBhyveProcessStop(privconn, vm, VIR_DOMAIN_SHUTOFF_DESTROYED);
|
ret = virBhyveProcessStop(privconn, vm, VIR_DOMAIN_SHUTOFF_DESTROYED);
|
||||||
|
event = virDomainEventLifecycleNewFromObj(vm,
|
||||||
|
VIR_DOMAIN_EVENT_STOPPED,
|
||||||
|
VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
|
||||||
|
|
||||||
if (!vm->persistent) {
|
if (!vm->persistent) {
|
||||||
virDomainObjListRemove(privconn->domains, vm);
|
virDomainObjListRemove(privconn->domains, vm);
|
||||||
@ -918,6 +955,8 @@ bhyveDomainDestroy(virDomainPtr dom)
|
|||||||
cleanup:
|
cleanup:
|
||||||
if (vm)
|
if (vm)
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
|
if (event)
|
||||||
|
virObjectEventStateQueue(privconn->domainEventState, event);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1076,6 +1115,7 @@ bhyveStateCleanup(void)
|
|||||||
virObjectUnref(bhyve_driver->xmlopt);
|
virObjectUnref(bhyve_driver->xmlopt);
|
||||||
virObjectUnref(bhyve_driver->hostsysinfo);
|
virObjectUnref(bhyve_driver->hostsysinfo);
|
||||||
virObjectUnref(bhyve_driver->closeCallbacks);
|
virObjectUnref(bhyve_driver->closeCallbacks);
|
||||||
|
virObjectEventStateFree(bhyve_driver->domainEventState);
|
||||||
|
|
||||||
virMutexDestroy(&bhyve_driver->lock);
|
virMutexDestroy(&bhyve_driver->lock);
|
||||||
VIR_FREE(bhyve_driver);
|
VIR_FREE(bhyve_driver);
|
||||||
@ -1114,6 +1154,9 @@ bhyveStateInitialize(bool priveleged ATTRIBUTE_UNUSED,
|
|||||||
if (!(bhyve_driver->domains = virDomainObjListNew()))
|
if (!(bhyve_driver->domains = virDomainObjListNew()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!(bhyve_driver->domainEventState = virObjectEventStateNew()))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
bhyve_driver->hostsysinfo = virSysinfoRead();
|
bhyve_driver->hostsysinfo = virSysinfoRead();
|
||||||
|
|
||||||
if (virFileMakePath(BHYVE_LOG_DIR) < 0) {
|
if (virFileMakePath(BHYVE_LOG_DIR) < 0) {
|
||||||
@ -1267,6 +1310,46 @@ bhyveConnectCompareCPU(virConnectPtr conn,
|
|||||||
return ret;
|
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 = {
|
static virDriver bhyveDriver = {
|
||||||
.no = VIR_DRV_BHYVE,
|
.no = VIR_DRV_BHYVE,
|
||||||
.name = "bhyve",
|
.name = "bhyve",
|
||||||
@ -1311,6 +1394,8 @@ static virDriver bhyveDriver = {
|
|||||||
.nodeSetMemoryParameters = bhyveNodeSetMemoryParameters, /* 1.2.3 */
|
.nodeSetMemoryParameters = bhyveNodeSetMemoryParameters, /* 1.2.3 */
|
||||||
.connectBaselineCPU = bhyveConnectBaselineCPU, /* 1.2.4 */
|
.connectBaselineCPU = bhyveConnectBaselineCPU, /* 1.2.4 */
|
||||||
.connectCompareCPU = bhyveConnectCompareCPU, /* 1.2.4 */
|
.connectCompareCPU = bhyveConnectCompareCPU, /* 1.2.4 */
|
||||||
|
.connectDomainEventRegisterAny = bhyveConnectDomainEventRegisterAny, /* 1.2.5 */
|
||||||
|
.connectDomainEventDeregisterAny = bhyveConnectDomainEventDeregisterAny, /* 1.2.5 */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
# define __BHYVE_UTILS_H__
|
# define __BHYVE_UTILS_H__
|
||||||
|
|
||||||
# include "driver.h"
|
# include "driver.h"
|
||||||
|
# include "domain_event.h"
|
||||||
# include "domain_conf.h"
|
# include "domain_conf.h"
|
||||||
# include "configmake.h"
|
# include "configmake.h"
|
||||||
# include "virthread.h"
|
# include "virthread.h"
|
||||||
@ -41,6 +42,8 @@ struct _bhyveConn {
|
|||||||
char *pidfile;
|
char *pidfile;
|
||||||
virSysinfoDefPtr hostsysinfo;
|
virSysinfoDefPtr hostsysinfo;
|
||||||
|
|
||||||
|
virObjectEventStatePtr domainEventState;
|
||||||
|
|
||||||
virCloseCallbacksPtr closeCallbacks;
|
virCloseCallbacksPtr closeCallbacks;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user