mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
event-test: support node device lifecycle event APIs
This commit is contained in:
parent
546fa3ef67
commit
f803f5ff34
@ -355,6 +355,20 @@ storagePoolEventToString(int event)
|
|||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
nodeDeviceEventToString(int event)
|
||||||
|
{
|
||||||
|
switch ((virNodeDeviceEventLifecycleType) event) {
|
||||||
|
case VIR_NODE_DEVICE_EVENT_CREATED:
|
||||||
|
return "Created";
|
||||||
|
case VIR_NODE_DEVICE_EVENT_DELETED:
|
||||||
|
return "Deleted";
|
||||||
|
case VIR_NODE_DEVICE_EVENT_LAST:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
myDomainEventCallback1(virConnectPtr conn ATTRIBUTE_UNUSED,
|
myDomainEventCallback1(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
@ -688,6 +702,21 @@ myStoragePoolEventRefreshCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
myNodeDeviceEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
|
virNodeDevicePtr dev,
|
||||||
|
int event,
|
||||||
|
int detail,
|
||||||
|
void *opaque ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
printf("%s EVENT: Node device %s %s %d\n", __func__,
|
||||||
|
virNodeDeviceGetName(dev),
|
||||||
|
nodeDeviceEventToString(event),
|
||||||
|
detail);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
eventTypedParamsPrint(virTypedParameterPtr params,
|
eventTypedParamsPrint(virTypedParameterPtr params,
|
||||||
int nparams)
|
int nparams)
|
||||||
@ -948,9 +977,24 @@ struct storagePoolEventData storagePoolEvents[] = {
|
|||||||
STORAGE_POOL_EVENT(VIR_STORAGE_POOL_EVENT_ID_REFRESH, myStoragePoolEventRefreshCallback),
|
STORAGE_POOL_EVENT(VIR_STORAGE_POOL_EVENT_ID_REFRESH, myStoragePoolEventRefreshCallback),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct nodeDeviceEventData {
|
||||||
|
int event;
|
||||||
|
int id;
|
||||||
|
virConnectNodeDeviceEventGenericCallback cb;
|
||||||
|
const char *name;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define NODE_DEVICE_EVENT(event, callback) \
|
||||||
|
{event, -1, VIR_NODE_DEVICE_EVENT_CALLBACK(callback), #event}
|
||||||
|
|
||||||
|
struct nodeDeviceEventData nodeDeviceEvents[] = {
|
||||||
|
NODE_DEVICE_EVENT(VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE, myNodeDeviceEventCallback),
|
||||||
|
};
|
||||||
|
|
||||||
/* make sure that the events are kept in sync */
|
/* make sure that the events are kept in sync */
|
||||||
verify(ARRAY_CARDINALITY(domainEvents) == VIR_DOMAIN_EVENT_ID_LAST);
|
verify(ARRAY_CARDINALITY(domainEvents) == VIR_DOMAIN_EVENT_ID_LAST);
|
||||||
verify(ARRAY_CARDINALITY(storagePoolEvents) == VIR_STORAGE_POOL_EVENT_ID_LAST);
|
verify(ARRAY_CARDINALITY(storagePoolEvents) == VIR_STORAGE_POOL_EVENT_ID_LAST);
|
||||||
|
verify(ARRAY_CARDINALITY(nodeDeviceEvents) == VIR_NODE_DEVICE_EVENT_ID_LAST);
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
@ -1042,6 +1086,22 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* register common node device callbacks */
|
||||||
|
for (i = 0; i < ARRAY_CARDINALITY(nodeDeviceEvents); i++) {
|
||||||
|
struct nodeDeviceEventData *event = nodeDeviceEvents + i;
|
||||||
|
|
||||||
|
event->id = virConnectNodeDeviceEventRegisterAny(dconn, NULL,
|
||||||
|
event->event,
|
||||||
|
event->cb,
|
||||||
|
strdup(event->name),
|
||||||
|
myFreeFunc);
|
||||||
|
|
||||||
|
if (event->id < 0) {
|
||||||
|
fprintf(stderr, "Failed to register event '%s'\n", event->name);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((callback1ret == -1) ||
|
if ((callback1ret == -1) ||
|
||||||
(callback16ret == -1))
|
(callback16ret == -1))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1077,6 +1137,14 @@ main(int argc, char **argv)
|
|||||||
virConnectStoragePoolEventDeregisterAny(dconn, storagePoolEvents[i].id);
|
virConnectStoragePoolEventDeregisterAny(dconn, storagePoolEvents[i].id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
printf("Deregistering node device event callbacks\n");
|
||||||
|
for (i = 0; i < ARRAY_CARDINALITY(nodeDeviceEvents); i++) {
|
||||||
|
if (nodeDeviceEvents[i].id > 0)
|
||||||
|
virConnectNodeDeviceEventDeregisterAny(dconn, nodeDeviceEvents[i].id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
virConnectUnregisterCloseCallback(dconn, connectClose);
|
virConnectUnregisterCloseCallback(dconn, connectClose);
|
||||||
ret = EXIT_SUCCESS;
|
ret = EXIT_SUCCESS;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user