提交 ea7dc337 编写于 作者: D Daniel P. Berrange

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.
上级 44457238
...@@ -35,6 +35,21 @@ ...@@ -35,6 +35,21 @@
virReportErrorHelper(conn, VIR_FROM_THIS, code, __FILE__, \ virReportErrorHelper(conn, VIR_FROM_THIS, code, __FILE__, \
__FUNCTION__, __LINE__, __VA_ARGS__) __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: * virDomainEventCallbackListFree:
...@@ -243,6 +258,13 @@ virDomainEventCallbackListAdd(virConnectPtr conn, ...@@ -243,6 +258,13 @@ virDomainEventCallbackListAdd(virConnectPtr conn,
return 0; return 0;
} }
int virDomainEventCallbackListCount(virDomainEventCallbackListPtr cbList)
{
return cbList->count;
}
void virDomainEventFree(virDomainEventPtr event) void virDomainEventFree(virDomainEventPtr event)
{ {
if (!event) if (!event)
......
...@@ -27,13 +27,6 @@ ...@@ -27,13 +27,6 @@
# include "domain_conf.h" # include "domain_conf.h"
struct _virDomainEventCallback {
virConnectPtr conn;
virConnectDomainEventCallback cb;
void *opaque;
virFreeCallback freecb;
int deleted;
};
typedef struct _virDomainEventCallback virDomainEventCallback; typedef struct _virDomainEventCallback virDomainEventCallback;
typedef virDomainEventCallback *virDomainEventCallbackPtr; typedef virDomainEventCallback *virDomainEventCallbackPtr;
...@@ -69,17 +62,12 @@ int virDomainEventCallbackListMarkDelete(virConnectPtr conn, ...@@ -69,17 +62,12 @@ int virDomainEventCallbackListMarkDelete(virConnectPtr conn,
int virDomainEventCallbackListPurgeMarked(virDomainEventCallbackListPtr cbList); int virDomainEventCallbackListPurgeMarked(virDomainEventCallbackListPtr cbList);
int virDomainEventCallbackListCount(virDomainEventCallbackListPtr cbList);
/** /**
* Dispatching domain events that come in while * Dispatching domain events that come in while
* in a call / response rpc * 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 struct _virDomainEvent virDomainEvent;
typedef virDomainEvent *virDomainEventPtr; typedef virDomainEvent *virDomainEventPtr;
......
...@@ -5021,7 +5021,7 @@ static nsresult vboxCallbackOnMachineStateChange (IVirtualBoxCallback *pThis, ...@@ -5021,7 +5021,7 @@ static nsresult vboxCallbackOnMachineStateChange (IVirtualBoxCallback *pThis,
dom = vboxDomainLookupByUUID(g_pVBoxGlobalData->conn, uuid); dom = vboxDomainLookupByUUID(g_pVBoxGlobalData->conn, uuid);
if (dom) { if (dom) {
int i = 0; virDomainEventPtr ev;
if (state == MachineState_Starting) { if (state == MachineState_Starting) {
event = VIR_DOMAIN_EVENT_STARTED; event = VIR_DOMAIN_EVENT_STARTED;
...@@ -5052,14 +5052,14 @@ static nsresult vboxCallbackOnMachineStateChange (IVirtualBoxCallback *pThis, ...@@ -5052,14 +5052,14 @@ static nsresult vboxCallbackOnMachineStateChange (IVirtualBoxCallback *pThis,
detail = VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN; detail = VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN;
} }
for (i = 0; i < g_pVBoxGlobalData->domainEventCallbacks->count; i++) { ev = virDomainEventNewFromDom(dom, event, detail);
if (g_pVBoxGlobalData->domainEventCallbacks->callbacks[i]->cb) {
g_pVBoxGlobalData->domainEventCallbacks->callbacks[i]->cb(g_pVBoxGlobalData->conn, if (ev) {
dom, virDomainEventDispatch(ev,
event, g_pVBoxGlobalData->domainEventCallbacks,
detail, virDomainEventDispatchDefaultFunc,
NULL); NULL);
} virDomainEventFree(ev);
} }
} }
} }
...@@ -5142,7 +5142,7 @@ static nsresult vboxCallbackOnMachineRegistered (IVirtualBoxCallback *pThis, ...@@ -5142,7 +5142,7 @@ static nsresult vboxCallbackOnMachineRegistered (IVirtualBoxCallback *pThis,
dom = vboxDomainLookupByUUID(g_pVBoxGlobalData->conn, uuid); dom = vboxDomainLookupByUUID(g_pVBoxGlobalData->conn, uuid);
if (dom) { if (dom) {
int i = 0; virDomainEventPtr ev;
/* CURRENT LIMITATION: we never get the VIR_DOMAIN_EVENT_UNDEFINED /* CURRENT LIMITATION: we never get the VIR_DOMAIN_EVENT_UNDEFINED
* event becuase the when the machine is de-registered the call * event becuase the when the machine is de-registered the call
...@@ -5158,14 +5158,14 @@ static nsresult vboxCallbackOnMachineRegistered (IVirtualBoxCallback *pThis, ...@@ -5158,14 +5158,14 @@ static nsresult vboxCallbackOnMachineRegistered (IVirtualBoxCallback *pThis,
detail = VIR_DOMAIN_EVENT_UNDEFINED_REMOVED; detail = VIR_DOMAIN_EVENT_UNDEFINED_REMOVED;
} }
for (i = 0; i < g_pVBoxGlobalData->domainEventCallbacks->count; i++) { ev = virDomainEventNewFromDom(dom, event, detail);
if (g_pVBoxGlobalData->domainEventCallbacks->callbacks[i]->cb) {
g_pVBoxGlobalData->domainEventCallbacks->callbacks[i]->cb(g_pVBoxGlobalData->conn, if (ev) {
dom, virDomainEventDispatch(ev,
event, g_pVBoxGlobalData->domainEventCallbacks,
detail, virDomainEventDispatchDefaultFunc,
NULL); NULL);
} virDomainEventFree(ev);
} }
} }
} }
...@@ -5412,28 +5412,17 @@ static int vboxDomainEventDeregister (virConnectPtr conn, ...@@ -5412,28 +5412,17 @@ static int vboxDomainEventDeregister (virConnectPtr conn,
ret = virDomainEventCallbackListRemove(conn, data->domainEventCallbacks, ret = virDomainEventCallbackListRemove(conn, data->domainEventCallbacks,
callback); callback);
if(data->vboxCallback) { if (data->vboxCallback) {
/* check count here of how many times register was called /* check count here of how many times register was called
* and only on the last de-register do the un-register call * and only on the last de-register do the un-register call
*/ */
if (data->domainEventCallbacks && (data->domainEventCallbacks->count <= 0)) { if (data->domainEventCallbacks && virDomainEventCallbackListCount(data->domainEventCallbacks) == 0) {
int i = 0;
data->vboxObj->vtbl->UnregisterCallback(data->vboxObj, data->vboxCallback); data->vboxObj->vtbl->UnregisterCallback(data->vboxObj, data->vboxCallback);
VBOX_RELEASE(data->vboxCallback); VBOX_RELEASE(data->vboxCallback);
/* Remove the Event file handle on which we are listening as well */ /* Remove the Event file handle on which we are listening as well */
virEventRemoveHandle(data->fdWatch); virEventRemoveHandle(data->fdWatch);
data->fdWatch = -1; 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);
}
}
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册