mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
Make internal domain events struct definitions private
The virtual box driver was directly accesing the domain events structs instead of using the APIs provided. To prevent this kind of abuse, make the struct definitions private, forcing use of the internal APIs. This requires adding one extra internal API. * src/conf/domain_event.h, src/conf/domain_event.c: Move virDomainEventCallback and virDomainEvent structs into the source file instead of header * src/vbox/vbox_tmpl.c: Use official APIs for dispatching domain events instead of accessing structs directly.
This commit is contained in:
parent
4445723811
commit
ea7dc33786
@ -35,6 +35,21 @@
|
||||
virReportErrorHelper(conn, VIR_FROM_THIS, code, __FILE__, \
|
||||
__FUNCTION__, __LINE__, __VA_ARGS__)
|
||||
|
||||
struct _virDomainEventCallback {
|
||||
virConnectPtr conn;
|
||||
virConnectDomainEventCallback cb;
|
||||
void *opaque;
|
||||
virFreeCallback freecb;
|
||||
int deleted;
|
||||
};
|
||||
|
||||
struct _virDomainEvent {
|
||||
int id;
|
||||
char *name;
|
||||
unsigned char uuid[VIR_UUID_BUFLEN];
|
||||
int type;
|
||||
int detail;
|
||||
};
|
||||
|
||||
/**
|
||||
* virDomainEventCallbackListFree:
|
||||
@ -243,6 +258,13 @@ virDomainEventCallbackListAdd(virConnectPtr conn,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int virDomainEventCallbackListCount(virDomainEventCallbackListPtr cbList)
|
||||
{
|
||||
return cbList->count;
|
||||
}
|
||||
|
||||
|
||||
void virDomainEventFree(virDomainEventPtr event)
|
||||
{
|
||||
if (!event)
|
||||
|
@ -27,13 +27,6 @@
|
||||
|
||||
# include "domain_conf.h"
|
||||
|
||||
struct _virDomainEventCallback {
|
||||
virConnectPtr conn;
|
||||
virConnectDomainEventCallback cb;
|
||||
void *opaque;
|
||||
virFreeCallback freecb;
|
||||
int deleted;
|
||||
};
|
||||
typedef struct _virDomainEventCallback virDomainEventCallback;
|
||||
typedef virDomainEventCallback *virDomainEventCallbackPtr;
|
||||
|
||||
@ -69,17 +62,12 @@ int virDomainEventCallbackListMarkDelete(virConnectPtr conn,
|
||||
|
||||
int virDomainEventCallbackListPurgeMarked(virDomainEventCallbackListPtr cbList);
|
||||
|
||||
int virDomainEventCallbackListCount(virDomainEventCallbackListPtr cbList);
|
||||
|
||||
/**
|
||||
* Dispatching domain events that come in while
|
||||
* in a call / response rpc
|
||||
*/
|
||||
struct _virDomainEvent {
|
||||
int id;
|
||||
char *name;
|
||||
unsigned char uuid[VIR_UUID_BUFLEN];
|
||||
int type;
|
||||
int detail;
|
||||
};
|
||||
typedef struct _virDomainEvent virDomainEvent;
|
||||
typedef virDomainEvent *virDomainEventPtr;
|
||||
|
||||
|
@ -5021,7 +5021,7 @@ static nsresult vboxCallbackOnMachineStateChange (IVirtualBoxCallback *pThis,
|
||||
|
||||
dom = vboxDomainLookupByUUID(g_pVBoxGlobalData->conn, uuid);
|
||||
if (dom) {
|
||||
int i = 0;
|
||||
virDomainEventPtr ev;
|
||||
|
||||
if (state == MachineState_Starting) {
|
||||
event = VIR_DOMAIN_EVENT_STARTED;
|
||||
@ -5052,14 +5052,14 @@ static nsresult vboxCallbackOnMachineStateChange (IVirtualBoxCallback *pThis,
|
||||
detail = VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN;
|
||||
}
|
||||
|
||||
for (i = 0; i < g_pVBoxGlobalData->domainEventCallbacks->count; i++) {
|
||||
if (g_pVBoxGlobalData->domainEventCallbacks->callbacks[i]->cb) {
|
||||
g_pVBoxGlobalData->domainEventCallbacks->callbacks[i]->cb(g_pVBoxGlobalData->conn,
|
||||
dom,
|
||||
event,
|
||||
detail,
|
||||
NULL);
|
||||
}
|
||||
ev = virDomainEventNewFromDom(dom, event, detail);
|
||||
|
||||
if (ev) {
|
||||
virDomainEventDispatch(ev,
|
||||
g_pVBoxGlobalData->domainEventCallbacks,
|
||||
virDomainEventDispatchDefaultFunc,
|
||||
NULL);
|
||||
virDomainEventFree(ev);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5142,7 +5142,7 @@ static nsresult vboxCallbackOnMachineRegistered (IVirtualBoxCallback *pThis,
|
||||
|
||||
dom = vboxDomainLookupByUUID(g_pVBoxGlobalData->conn, uuid);
|
||||
if (dom) {
|
||||
int i = 0;
|
||||
virDomainEventPtr ev;
|
||||
|
||||
/* CURRENT LIMITATION: we never get the VIR_DOMAIN_EVENT_UNDEFINED
|
||||
* event becuase the when the machine is de-registered the call
|
||||
@ -5158,14 +5158,14 @@ static nsresult vboxCallbackOnMachineRegistered (IVirtualBoxCallback *pThis,
|
||||
detail = VIR_DOMAIN_EVENT_UNDEFINED_REMOVED;
|
||||
}
|
||||
|
||||
for (i = 0; i < g_pVBoxGlobalData->domainEventCallbacks->count; i++) {
|
||||
if (g_pVBoxGlobalData->domainEventCallbacks->callbacks[i]->cb) {
|
||||
g_pVBoxGlobalData->domainEventCallbacks->callbacks[i]->cb(g_pVBoxGlobalData->conn,
|
||||
dom,
|
||||
event,
|
||||
detail,
|
||||
NULL);
|
||||
}
|
||||
ev = virDomainEventNewFromDom(dom, event, detail);
|
||||
|
||||
if (ev) {
|
||||
virDomainEventDispatch(ev,
|
||||
g_pVBoxGlobalData->domainEventCallbacks,
|
||||
virDomainEventDispatchDefaultFunc,
|
||||
NULL);
|
||||
virDomainEventFree(ev);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5412,28 +5412,17 @@ static int vboxDomainEventDeregister (virConnectPtr conn,
|
||||
ret = virDomainEventCallbackListRemove(conn, data->domainEventCallbacks,
|
||||
callback);
|
||||
|
||||
if(data->vboxCallback) {
|
||||
if (data->vboxCallback) {
|
||||
/* check count here of how many times register was called
|
||||
* and only on the last de-register do the un-register call
|
||||
*/
|
||||
if (data->domainEventCallbacks && (data->domainEventCallbacks->count <= 0)) {
|
||||
int i = 0;
|
||||
|
||||
if (data->domainEventCallbacks && virDomainEventCallbackListCount(data->domainEventCallbacks) == 0) {
|
||||
data->vboxObj->vtbl->UnregisterCallback(data->vboxObj, data->vboxCallback);
|
||||
VBOX_RELEASE(data->vboxCallback);
|
||||
|
||||
/* Remove the Event file handle on which we are listening as well */
|
||||
virEventRemoveHandle(data->fdWatch);
|
||||
data->fdWatch = -1;
|
||||
|
||||
/* iterate and free all the opaque objects using the
|
||||
* freecb callback provided in vboxDomainEventRegister()
|
||||
*/
|
||||
for (i = 0; i < data->domainEventCallbacks->count; i++) {
|
||||
if (data->domainEventCallbacks->callbacks[i]->freecb) {
|
||||
data->domainEventCallbacks->callbacks[i]->freecb(data->domainEventCallbacks->callbacks[i]->opaque);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user