--- src/conf/domain_event.c | 105 ++++++++++++++++++++++++++++++------------------ src/conf/domain_event.h | 20 ++++----- 2 files changed, 75 insertions(+), 50 deletions(-) diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index 5d56fe5..8497b9a 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -86,6 +86,8 @@ static virClassPtr virDomainEventWatchdogClass; static virClassPtr virDomainEventIOErrorClass; static virClassPtr virDomainEventGraphicsClass; static virClassPtr virDomainEventBlockJobClass; +static virClassPtr virDomainEventDiskChangeClass; + static void virObjectEventDispose(void *obj); static void virDomainEventDispose(void *obj); static void virDomainEventLifecycleDispose(void *obj); @@ -94,6 +96,7 @@ static void virDomainEventWatchdogDispose(void *obj); static void virDomainEventIOErrorDispose(void *obj); static void virDomainEventGraphicsDispose(void *obj); static void virDomainEventBlockJobDispose(void *obj); +static void virDomainEventDiskChangeDispose(void *obj); struct _virObjectEvent { virObject parent; @@ -107,12 +110,6 @@ struct _virDomainEvent { union { struct { - char *oldSrcPath; - char *newSrcPath; - char *devAlias; - int reason; - } diskChange; - struct { char *devAlias; int reason; } trayChange; @@ -184,6 +181,18 @@ struct _virDomainEventGraphics { typedef struct _virDomainEventGraphics virDomainEventGraphics; typedef virDomainEventGraphics *virDomainEventGraphicsPtr; +struct _virDomainEventDiskChange { + virDomainEvent parent; + + char *oldSrcPath; + char *newSrcPath; + char *devAlias; + int reason; +}; +typedef struct _virDomainEventDiskChange virDomainEventDiskChange; +typedef virDomainEventDiskChange *virDomainEventDiskChangePtr; + + static int virObjectEventOnceInit(void) { if (!(virObjectEventClass = virClassNew(virClassForObject(), @@ -232,6 +241,12 @@ static int virObjectEventOnceInit(void) sizeof(virDomainEventBlockJob), virDomainEventBlockJobDispose))) return -1; + if (!(virDomainEventDiskChangeClass = virClassNew( + virDomainEventClass, + "virDomainEventDiskChange", + sizeof(virDomainEventDiskChange), + virDomainEventDiskChangeDispose))) + return -1; return 0; } @@ -267,11 +282,6 @@ static void virDomainEventDispose(void *obj) switch (virObjectEventGetEventID(event)) { - case VIR_DOMAIN_EVENT_ID_DISK_CHANGE: - VIR_FREE(event->data.diskChange.oldSrcPath); - VIR_FREE(event->data.diskChange.newSrcPath); - VIR_FREE(event->data.diskChange.devAlias); - break; case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE: VIR_FREE(event->data.trayChange.devAlias); break; @@ -345,6 +355,16 @@ static void virDomainEventBlockJobDispose(void *obj) VIR_FREE(event->path); } +static void virDomainEventDiskChangeDispose(void *obj) +{ + virDomainEventDiskChangePtr event = obj; + VIR_DEBUG("obj=%p", event); + + VIR_FREE(event->oldSrcPath); + VIR_FREE(event->newSrcPath); + VIR_FREE(event->devAlias); +} + /** * virObjectEventCallbackListFree: * @list: event callback list head @@ -1241,33 +1261,33 @@ virDomainEventPtr virDomainEventControlErrorNewFromObj(virDomainObjPtr obj) return ev; } -static virDomainEventPtr -virDomainEventDiskChangeNew(int id, const char *name, - unsigned char *uuid, - const char *oldSrcPath, - const char *newSrcPath, - const char *devAlias, int reason) +static +void *virDomainEventDiskChangeNew(int id, const char *name, + unsigned char *uuid, + const char *oldSrcPath, + const char *newSrcPath, + const char *devAlias, int reason) { - virDomainEventPtr ev; + virDomainEventDiskChangePtr ev; if (virObjectEventInitialize() < 0) return NULL; - if (!(ev = virDomainEventNew(virDomainEventClass, + if (!(ev = virDomainEventNew(virDomainEventDiskChangeClass, VIR_DOMAIN_EVENT_ID_DISK_CHANGE, id, name, uuid))) return NULL; - if (VIR_STRDUP(ev->data.diskChange.devAlias, devAlias) < 0) + if (VIR_STRDUP(ev->devAlias, devAlias) < 0) goto error; - if (VIR_STRDUP(ev->data.diskChange.oldSrcPath, oldSrcPath) < 0) + if (VIR_STRDUP(ev->oldSrcPath, oldSrcPath) < 0) goto error; - if (VIR_STRDUP(ev->data.diskChange.newSrcPath, newSrcPath) < 0) + if (VIR_STRDUP(ev->newSrcPath, newSrcPath) < 0) goto error; - ev->data.diskChange.reason = reason; + ev->reason = reason; return ev; @@ -1276,22 +1296,22 @@ error: return NULL; } -virDomainEventPtr virDomainEventDiskChangeNewFromObj(virDomainObjPtr obj, - const char *oldSrcPath, - const char *newSrcPath, - const char *devAlias, - int reason) +void *virDomainEventDiskChangeNewFromObj(virDomainObjPtr obj, + const char *oldSrcPath, + const char *newSrcPath, + const char *devAlias, + int reason) { return virDomainEventDiskChangeNew(obj->def->id, obj->def->name, obj->def->uuid, oldSrcPath, newSrcPath, devAlias, reason); } -virDomainEventPtr virDomainEventDiskChangeNewFromDom(virDomainPtr dom, - const char *oldSrcPath, - const char *newSrcPath, - const char *devAlias, - int reason) +void *virDomainEventDiskChangeNewFromDom(virDomainPtr dom, + const char *oldSrcPath, + const char *newSrcPath, + const char *devAlias, + int reason) { return virDomainEventDiskChangeNew(dom->id, dom->name, dom->uuid, oldSrcPath, newSrcPath, @@ -1663,13 +1683,18 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn, } case VIR_DOMAIN_EVENT_ID_DISK_CHANGE: - ((virConnectDomainEventDiskChangeCallback)cb)(conn, dom, - event->data.diskChange.oldSrcPath, - event->data.diskChange.newSrcPath, - event->data.diskChange.devAlias, - event->data.diskChange.reason, - cbopaque); - goto cleanup; + { + virDomainEventDiskChangePtr diskChangeEvent; + + diskChangeEvent = (virDomainEventDiskChangePtr)event; + ((virConnectDomainEventDiskChangeCallback)cb)(conn, dom, + diskChangeEvent->oldSrcPath, + diskChangeEvent->newSrcPath, + diskChangeEvent->devAlias, + diskChangeEvent->reason, + cbopaque); + goto cleanup; + } case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE: ((virConnectDomainEventTrayChangeCallback)cb)(conn, dom, diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h index 1aa1455..965af57 100644 --- a/src/conf/domain_event.h +++ b/src/conf/domain_event.h @@ -118,16 +118,16 @@ void *virDomainEventBlockJobNewFromDom(virDomainPtr dom, int type, int status); -virDomainEventPtr virDomainEventDiskChangeNewFromObj(virDomainObjPtr obj, - const char *oldSrcPath, - const char *newSrcPath, - const char *devAlias, - int reason); -virDomainEventPtr virDomainEventDiskChangeNewFromDom(virDomainPtr dom, - const char *oldSrcPath, - const char *newSrcPath, - const char *devAlias, - int reason); +void *virDomainEventDiskChangeNewFromObj(virDomainObjPtr obj, + const char *oldSrcPath, + const char *newSrcPath, + const char *devAlias, + int reason); +void *virDomainEventDiskChangeNewFromDom(virDomainPtr dom, + const char *oldSrcPath, + const char *newSrcPath, + const char *devAlias, + int reason); virDomainEventPtr virDomainEventTrayChangeNewFromObj(virDomainObjPtr obj, const char *devAlias, int reason); -- 1.8.4.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list