2008-10-23 13:18:18 +00:00
|
|
|
#include <config.h>
|
2008-10-24 13:10:30 +00:00
|
|
|
|
2008-10-23 13:18:18 +00:00
|
|
|
#include <stdio.h>
|
2008-11-19 15:25:24 +00:00
|
|
|
#include <stdlib.h>
|
2008-10-23 13:18:18 +00:00
|
|
|
#include <string.h>
|
2008-11-19 15:25:24 +00:00
|
|
|
#include <signal.h>
|
2012-07-13 09:05:17 +00:00
|
|
|
#include <inttypes.h>
|
2008-10-24 13:10:30 +00:00
|
|
|
|
2016-04-14 15:41:19 +00:00
|
|
|
#include <verify.h>
|
|
|
|
|
2016-04-14 13:11:49 +00:00
|
|
|
#define VIR_ENUM_SENTINELS
|
|
|
|
|
2011-03-23 14:30:30 +00:00
|
|
|
#include <libvirt/libvirt.h>
|
|
|
|
#include <libvirt/virterror.h>
|
2008-10-23 13:18:18 +00:00
|
|
|
|
2016-04-14 14:57:02 +00:00
|
|
|
#define ARRAY_CARDINALITY(Array) (sizeof(Array) / sizeof(*(Array)))
|
2014-08-22 12:59:28 +00:00
|
|
|
#define STREQ(a, b) (strcmp(a, b) == 0)
|
2008-10-23 13:18:18 +00:00
|
|
|
|
2011-03-23 14:30:30 +00:00
|
|
|
#ifndef ATTRIBUTE_UNUSED
|
|
|
|
# define ATTRIBUTE_UNUSED __attribute__((__unused__))
|
|
|
|
#endif
|
2008-10-23 13:18:18 +00:00
|
|
|
|
2012-07-19 14:59:59 +00:00
|
|
|
int run = 1;
|
|
|
|
|
2008-10-23 13:18:18 +00:00
|
|
|
/* Callback functions */
|
2016-04-13 13:45:52 +00:00
|
|
|
static void
|
|
|
|
connectClose(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
int reason,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
2012-07-19 14:59:59 +00:00
|
|
|
{
|
2016-04-14 07:04:52 +00:00
|
|
|
run = 0;
|
|
|
|
|
|
|
|
switch ((virConnectCloseReason) reason) {
|
2012-07-19 14:59:59 +00:00
|
|
|
case VIR_CONNECT_CLOSE_REASON_ERROR:
|
|
|
|
fprintf(stderr, "Connection closed due to I/O error\n");
|
2016-04-14 07:04:52 +00:00
|
|
|
return;
|
|
|
|
|
2012-07-19 14:59:59 +00:00
|
|
|
case VIR_CONNECT_CLOSE_REASON_EOF:
|
|
|
|
fprintf(stderr, "Connection closed due to end of file\n");
|
2016-04-14 07:04:52 +00:00
|
|
|
return;
|
|
|
|
|
2012-07-19 14:59:59 +00:00
|
|
|
case VIR_CONNECT_CLOSE_REASON_KEEPALIVE:
|
|
|
|
fprintf(stderr, "Connection closed due to keepalive timeout\n");
|
2016-04-14 07:04:52 +00:00
|
|
|
return;
|
|
|
|
|
2012-07-19 14:59:59 +00:00
|
|
|
case VIR_CONNECT_CLOSE_REASON_CLIENT:
|
|
|
|
fprintf(stderr, "Connection closed due to client request\n");
|
2016-04-14 07:04:52 +00:00
|
|
|
return;
|
2016-04-14 13:11:49 +00:00
|
|
|
|
|
|
|
case VIR_CONNECT_CLOSE_REASON_LAST:
|
|
|
|
break;
|
2012-07-19 14:59:59 +00:00
|
|
|
};
|
2016-04-14 07:04:52 +00:00
|
|
|
|
|
|
|
fprintf(stderr, "Connection closed due to unknown reason\n");
|
2012-07-19 14:59:59 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
|
|
|
static const char *
|
|
|
|
eventToString(int event)
|
|
|
|
{
|
2011-12-05 12:59:13 +00:00
|
|
|
switch ((virDomainEventType) event) {
|
2008-11-17 16:43:00 +00:00
|
|
|
case VIR_DOMAIN_EVENT_DEFINED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Defined";
|
|
|
|
|
2008-11-17 16:43:00 +00:00
|
|
|
case VIR_DOMAIN_EVENT_UNDEFINED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Undefined";
|
|
|
|
|
2008-10-23 13:18:18 +00:00
|
|
|
case VIR_DOMAIN_EVENT_STARTED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Started";
|
|
|
|
|
2008-10-23 13:18:18 +00:00
|
|
|
case VIR_DOMAIN_EVENT_SUSPENDED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Suspended";
|
|
|
|
|
2008-10-23 13:18:18 +00:00
|
|
|
case VIR_DOMAIN_EVENT_RESUMED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Resumed";
|
|
|
|
|
2008-10-23 13:18:18 +00:00
|
|
|
case VIR_DOMAIN_EVENT_STOPPED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Stopped";
|
|
|
|
|
2011-12-05 12:59:13 +00:00
|
|
|
case VIR_DOMAIN_EVENT_SHUTDOWN:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Shutdown";
|
|
|
|
|
2012-09-06 15:00:43 +00:00
|
|
|
case VIR_DOMAIN_EVENT_PMSUSPENDED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "PMSuspended";
|
|
|
|
|
2013-06-07 10:23:31 +00:00
|
|
|
case VIR_DOMAIN_EVENT_CRASHED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Crashed";
|
2016-04-14 13:11:49 +00:00
|
|
|
|
|
|
|
case VIR_DOMAIN_EVENT_LAST:
|
|
|
|
break;
|
2008-11-17 16:43:00 +00:00
|
|
|
}
|
2016-04-14 12:51:40 +00:00
|
|
|
|
|
|
|
return "unknown";
|
2008-11-17 16:43:00 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
|
|
|
static const char *
|
|
|
|
eventDetailToString(int event,
|
|
|
|
int detail)
|
|
|
|
{
|
2011-12-05 12:59:13 +00:00
|
|
|
switch ((virDomainEventType) event) {
|
2008-11-17 16:43:00 +00:00
|
|
|
case VIR_DOMAIN_EVENT_DEFINED:
|
2016-04-14 12:44:07 +00:00
|
|
|
switch ((virDomainEventDefinedDetailType) detail) {
|
|
|
|
case VIR_DOMAIN_EVENT_DEFINED_ADDED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Added";
|
|
|
|
|
2016-04-14 12:44:07 +00:00
|
|
|
case VIR_DOMAIN_EVENT_DEFINED_UPDATED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Updated";
|
|
|
|
|
2016-04-14 12:44:07 +00:00
|
|
|
case VIR_DOMAIN_EVENT_DEFINED_RENAMED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Renamed";
|
|
|
|
|
2016-04-14 12:44:07 +00:00
|
|
|
case VIR_DOMAIN_EVENT_DEFINED_FROM_SNAPSHOT:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Snapshot";
|
2016-04-14 13:11:49 +00:00
|
|
|
|
|
|
|
case VIR_DOMAIN_EVENT_DEFINED_LAST:
|
|
|
|
break;
|
2016-04-14 12:44:07 +00:00
|
|
|
}
|
2008-11-17 16:43:00 +00:00
|
|
|
break;
|
2016-04-14 12:51:40 +00:00
|
|
|
|
2008-11-17 16:43:00 +00:00
|
|
|
case VIR_DOMAIN_EVENT_UNDEFINED:
|
2016-04-14 12:44:07 +00:00
|
|
|
switch ((virDomainEventUndefinedDetailType) detail) {
|
|
|
|
case VIR_DOMAIN_EVENT_UNDEFINED_REMOVED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Removed";
|
|
|
|
|
2016-04-14 12:44:07 +00:00
|
|
|
case VIR_DOMAIN_EVENT_UNDEFINED_RENAMED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Renamed";
|
2016-04-14 13:11:49 +00:00
|
|
|
|
|
|
|
case VIR_DOMAIN_EVENT_UNDEFINED_LAST:
|
|
|
|
break;
|
2016-04-14 12:44:07 +00:00
|
|
|
}
|
2008-10-23 13:18:18 +00:00
|
|
|
break;
|
2016-04-14 12:51:40 +00:00
|
|
|
|
2008-11-17 16:43:00 +00:00
|
|
|
case VIR_DOMAIN_EVENT_STARTED:
|
2011-12-05 12:59:13 +00:00
|
|
|
switch ((virDomainEventStartedDetailType) detail) {
|
2008-11-17 16:43:00 +00:00
|
|
|
case VIR_DOMAIN_EVENT_STARTED_BOOTED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Booted";
|
|
|
|
|
2008-11-17 16:43:00 +00:00
|
|
|
case VIR_DOMAIN_EVENT_STARTED_MIGRATED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Migrated";
|
|
|
|
|
2008-11-17 16:43:00 +00:00
|
|
|
case VIR_DOMAIN_EVENT_STARTED_RESTORED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Restored";
|
|
|
|
|
2011-08-05 22:05:50 +00:00
|
|
|
case VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Snapshot";
|
|
|
|
|
2012-03-14 15:26:55 +00:00
|
|
|
case VIR_DOMAIN_EVENT_STARTED_WAKEUP:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Event wakeup";
|
2016-04-14 13:11:49 +00:00
|
|
|
|
|
|
|
case VIR_DOMAIN_EVENT_STARTED_LAST:
|
|
|
|
break;
|
2008-11-17 16:43:00 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-04-14 12:51:40 +00:00
|
|
|
|
2008-11-17 16:43:00 +00:00
|
|
|
case VIR_DOMAIN_EVENT_SUSPENDED:
|
2011-12-05 12:59:13 +00:00
|
|
|
switch ((virDomainEventSuspendedDetailType) detail) {
|
2011-08-05 22:05:50 +00:00
|
|
|
case VIR_DOMAIN_EVENT_SUSPENDED_PAUSED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Paused";
|
|
|
|
|
2011-08-05 22:05:50 +00:00
|
|
|
case VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Migrated";
|
|
|
|
|
2011-08-05 22:05:50 +00:00
|
|
|
case VIR_DOMAIN_EVENT_SUSPENDED_IOERROR:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "I/O Error";
|
|
|
|
|
2011-08-05 22:05:50 +00:00
|
|
|
case VIR_DOMAIN_EVENT_SUSPENDED_WATCHDOG:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Watchdog";
|
|
|
|
|
2011-08-05 22:05:50 +00:00
|
|
|
case VIR_DOMAIN_EVENT_SUSPENDED_RESTORED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Restored";
|
|
|
|
|
2011-08-05 22:05:50 +00:00
|
|
|
case VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Snapshot";
|
|
|
|
|
2012-11-06 17:39:18 +00:00
|
|
|
case VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "API error";
|
|
|
|
|
2016-01-05 11:08:37 +00:00
|
|
|
case VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Post-copy";
|
|
|
|
|
2016-01-05 11:08:37 +00:00
|
|
|
case VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY_FAILED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Post-copy Error";
|
2016-04-14 13:11:49 +00:00
|
|
|
|
|
|
|
case VIR_DOMAIN_EVENT_SUSPENDED_LAST:
|
|
|
|
break;
|
2011-08-05 22:05:50 +00:00
|
|
|
}
|
2008-11-17 16:43:00 +00:00
|
|
|
break;
|
2016-04-14 12:51:40 +00:00
|
|
|
|
2008-11-17 16:43:00 +00:00
|
|
|
case VIR_DOMAIN_EVENT_RESUMED:
|
2011-12-05 12:59:13 +00:00
|
|
|
switch ((virDomainEventResumedDetailType) detail) {
|
2011-08-05 22:05:50 +00:00
|
|
|
case VIR_DOMAIN_EVENT_RESUMED_UNPAUSED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Unpaused";
|
|
|
|
|
2011-08-05 22:05:50 +00:00
|
|
|
case VIR_DOMAIN_EVENT_RESUMED_MIGRATED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Migrated";
|
|
|
|
|
2011-08-05 22:05:50 +00:00
|
|
|
case VIR_DOMAIN_EVENT_RESUMED_FROM_SNAPSHOT:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Snapshot";
|
|
|
|
|
2016-01-05 11:08:37 +00:00
|
|
|
case VIR_DOMAIN_EVENT_RESUMED_POSTCOPY:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Post-copy";
|
2016-04-14 13:11:49 +00:00
|
|
|
|
|
|
|
case VIR_DOMAIN_EVENT_RESUMED_LAST:
|
|
|
|
break;
|
2011-08-05 22:05:50 +00:00
|
|
|
}
|
2008-11-17 16:43:00 +00:00
|
|
|
break;
|
2016-04-14 12:51:40 +00:00
|
|
|
|
2008-11-17 16:43:00 +00:00
|
|
|
case VIR_DOMAIN_EVENT_STOPPED:
|
2011-12-05 12:59:13 +00:00
|
|
|
switch ((virDomainEventStoppedDetailType) detail) {
|
2008-11-17 16:43:00 +00:00
|
|
|
case VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Shutdown";
|
|
|
|
|
2008-11-17 16:43:00 +00:00
|
|
|
case VIR_DOMAIN_EVENT_STOPPED_DESTROYED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Destroyed";
|
|
|
|
|
2008-11-17 16:43:00 +00:00
|
|
|
case VIR_DOMAIN_EVENT_STOPPED_CRASHED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Crashed";
|
|
|
|
|
2008-11-17 16:43:00 +00:00
|
|
|
case VIR_DOMAIN_EVENT_STOPPED_MIGRATED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Migrated";
|
|
|
|
|
2008-11-17 16:43:00 +00:00
|
|
|
case VIR_DOMAIN_EVENT_STOPPED_SAVED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Saved";
|
|
|
|
|
2008-11-17 16:43:00 +00:00
|
|
|
case VIR_DOMAIN_EVENT_STOPPED_FAILED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Failed";
|
|
|
|
|
2011-08-05 22:05:50 +00:00
|
|
|
case VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Snapshot";
|
2016-04-14 13:11:49 +00:00
|
|
|
|
|
|
|
case VIR_DOMAIN_EVENT_STOPPED_LAST:
|
|
|
|
break;
|
2008-11-17 16:43:00 +00:00
|
|
|
}
|
2008-10-23 13:18:18 +00:00
|
|
|
break;
|
2016-04-14 12:51:40 +00:00
|
|
|
|
2011-12-05 12:59:13 +00:00
|
|
|
case VIR_DOMAIN_EVENT_SHUTDOWN:
|
|
|
|
switch ((virDomainEventShutdownDetailType) detail) {
|
|
|
|
case VIR_DOMAIN_EVENT_SHUTDOWN_FINISHED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Finished";
|
|
|
|
|
2016-04-14 13:11:49 +00:00
|
|
|
case VIR_DOMAIN_EVENT_SHUTDOWN_LAST:
|
|
|
|
break;
|
2011-12-05 12:59:13 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-04-14 12:51:40 +00:00
|
|
|
|
2012-09-06 15:00:43 +00:00
|
|
|
case VIR_DOMAIN_EVENT_PMSUSPENDED:
|
|
|
|
switch ((virDomainEventPMSuspendedDetailType) detail) {
|
|
|
|
case VIR_DOMAIN_EVENT_PMSUSPENDED_MEMORY:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Memory";
|
|
|
|
|
2012-10-12 19:13:39 +00:00
|
|
|
case VIR_DOMAIN_EVENT_PMSUSPENDED_DISK:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Disk";
|
2016-04-14 13:11:49 +00:00
|
|
|
|
|
|
|
case VIR_DOMAIN_EVENT_PMSUSPENDED_LAST:
|
|
|
|
break;
|
2012-09-06 15:00:43 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-04-14 12:51:40 +00:00
|
|
|
|
2013-06-07 10:23:31 +00:00
|
|
|
case VIR_DOMAIN_EVENT_CRASHED:
|
|
|
|
switch ((virDomainEventCrashedDetailType) detail) {
|
|
|
|
case VIR_DOMAIN_EVENT_CRASHED_PANICKED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Panicked";
|
2016-04-14 13:11:49 +00:00
|
|
|
|
|
|
|
case VIR_DOMAIN_EVENT_CRASHED_LAST:
|
|
|
|
break;
|
2013-06-07 10:23:31 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-04-14 13:11:49 +00:00
|
|
|
|
|
|
|
case VIR_DOMAIN_EVENT_LAST:
|
|
|
|
break;
|
2008-10-23 13:18:18 +00:00
|
|
|
}
|
2016-04-14 12:51:40 +00:00
|
|
|
|
|
|
|
return "unknown";
|
2008-10-23 13:18:18 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
2013-12-11 14:23:24 +00:00
|
|
|
static const char *
|
|
|
|
networkEventToString(int event)
|
|
|
|
{
|
|
|
|
switch ((virNetworkEventLifecycleType) event) {
|
|
|
|
case VIR_NETWORK_EVENT_DEFINED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Defined";
|
|
|
|
|
2013-12-11 14:23:24 +00:00
|
|
|
case VIR_NETWORK_EVENT_UNDEFINED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Undefined";
|
|
|
|
|
2013-12-11 14:23:24 +00:00
|
|
|
case VIR_NETWORK_EVENT_STARTED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Started";
|
|
|
|
|
2013-12-11 14:23:24 +00:00
|
|
|
case VIR_NETWORK_EVENT_STOPPED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Stopped";
|
|
|
|
|
2016-04-14 13:11:49 +00:00
|
|
|
case VIR_NETWORK_EVENT_LAST:
|
|
|
|
break;
|
2013-12-11 14:23:24 +00:00
|
|
|
}
|
2016-04-14 12:51:40 +00:00
|
|
|
|
|
|
|
return "unknown";
|
2013-12-11 14:23:24 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
2014-11-19 09:27:55 +00:00
|
|
|
static const char *
|
|
|
|
guestAgentLifecycleEventStateToString(int event)
|
|
|
|
{
|
|
|
|
switch ((virConnectDomainEventAgentLifecycleState) event) {
|
|
|
|
case VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_DISCONNECTED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Disconnected";
|
2014-11-19 09:27:55 +00:00
|
|
|
|
|
|
|
case VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_CONNECTED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Connected";
|
2016-04-14 13:11:49 +00:00
|
|
|
|
|
|
|
case VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_LAST:
|
|
|
|
break;
|
2014-11-19 09:27:55 +00:00
|
|
|
}
|
|
|
|
|
2016-04-14 12:51:40 +00:00
|
|
|
return "unknown";
|
2014-11-19 09:27:55 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
2014-11-19 09:27:55 +00:00
|
|
|
static const char *
|
|
|
|
guestAgentLifecycleEventReasonToString(int event)
|
|
|
|
{
|
|
|
|
switch ((virConnectDomainEventAgentLifecycleReason) event) {
|
|
|
|
case VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_UNKNOWN:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Unknown";
|
2014-11-19 09:27:55 +00:00
|
|
|
|
|
|
|
case VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Domain started";
|
2014-11-19 09:27:55 +00:00
|
|
|
|
|
|
|
case VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL:
|
2016-04-14 12:51:40 +00:00
|
|
|
return "Channel event";
|
2016-04-14 13:11:49 +00:00
|
|
|
|
|
|
|
case VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_LAST:
|
|
|
|
break;
|
2014-11-19 09:27:55 +00:00
|
|
|
}
|
|
|
|
|
2016-04-14 12:51:40 +00:00
|
|
|
return "unknown";
|
2014-11-19 09:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
static int
|
|
|
|
myDomainEventCallback1(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
int event,
|
|
|
|
int detail,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
2008-10-23 13:18:18 +00:00
|
|
|
{
|
2008-12-18 12:25:11 +00:00
|
|
|
printf("%s EVENT: Domain %s(%d) %s %s\n", __func__, virDomainGetName(dom),
|
2008-11-17 16:43:00 +00:00
|
|
|
virDomainGetID(dom), eventToString(event),
|
|
|
|
eventDetailToString(event, detail));
|
2008-10-23 13:18:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
myDomainEventCallback2(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
int event,
|
|
|
|
int detail,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
2008-10-23 13:18:18 +00:00
|
|
|
{
|
2008-12-18 12:25:11 +00:00
|
|
|
printf("%s EVENT: Domain %s(%d) %s %s\n", __func__, virDomainGetName(dom),
|
2008-11-17 16:43:00 +00:00
|
|
|
virDomainGetID(dom), eventToString(event),
|
|
|
|
eventDetailToString(event, detail));
|
2008-10-23 13:18:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
myDomainEventRebootCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
2010-03-18 15:25:38 +00:00
|
|
|
{
|
|
|
|
printf("%s EVENT: Domain %s(%d) rebooted\n", __func__, virDomainGetName(dom),
|
|
|
|
virDomainGetID(dom));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
myDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
long long offset,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
2010-03-18 18:28:15 +00:00
|
|
|
{
|
2013-07-29 18:53:36 +00:00
|
|
|
printf("%s EVENT: Domain %s(%d) rtc change %" PRIdMAX "\n",
|
|
|
|
__func__, virDomainGetName(dom), virDomainGetID(dom),
|
|
|
|
(intmax_t)offset);
|
2010-03-18 18:28:15 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
myDomainEventBalloonChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
unsigned long long actual,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
2012-07-13 09:05:17 +00:00
|
|
|
{
|
|
|
|
printf("%s EVENT: Domain %s(%d) balloon change %" PRIuMAX "KB\n",
|
|
|
|
__func__, virDomainGetName(dom), virDomainGetID(dom), (uintmax_t)actual);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
myDomainEventWatchdogCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
int action,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
Add support for an explicit watchdog event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_WATCHDOG
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_WATCHDOG_NONE = 0,
VIR_DOMAIN_EVENT_WATCHDOG_PAUSE,
VIR_DOMAIN_EVENT_WATCHDOG_RESET,
VIR_DOMAIN_EVENT_WATCHDOG_POWEROFF,
VIR_DOMAIN_EVENT_WATCHDOG_SHUTDOWN,
VIR_DOMAIN_EVENT_WATCHDOG_DEBUG,
} virDomainEventWatchdogAction;
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventWatchdogCallback)(virConnectPtr conn,
virDomainPtr dom,
int action,
void *opaque);
* daemon/remote.c: Dispatch watchdog events to client
* examples/domain-events/events-c/event-test.c: Watch for
watchdog events
* include/libvirt/libvirt.h.in: Define new watchdg event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle watchdog events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for watchdogs and emit a libvirt watchdog event
* src/remote/remote_driver.c: Receive and dispatch watchdog
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
watchdog events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for WATCHDOG event
from QEMU monitor
2010-03-18 19:07:48 +00:00
|
|
|
{
|
2016-04-13 13:45:52 +00:00
|
|
|
printf("%s EVENT: Domain %s(%d) watchdog action=%d\n", __func__,
|
|
|
|
virDomainGetName(dom), virDomainGetID(dom), action);
|
Add support for an explicit watchdog event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_WATCHDOG
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_WATCHDOG_NONE = 0,
VIR_DOMAIN_EVENT_WATCHDOG_PAUSE,
VIR_DOMAIN_EVENT_WATCHDOG_RESET,
VIR_DOMAIN_EVENT_WATCHDOG_POWEROFF,
VIR_DOMAIN_EVENT_WATCHDOG_SHUTDOWN,
VIR_DOMAIN_EVENT_WATCHDOG_DEBUG,
} virDomainEventWatchdogAction;
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventWatchdogCallback)(virConnectPtr conn,
virDomainPtr dom,
int action,
void *opaque);
* daemon/remote.c: Dispatch watchdog events to client
* examples/domain-events/events-c/event-test.c: Watch for
watchdog events
* include/libvirt/libvirt.h.in: Define new watchdg event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle watchdog events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for watchdogs and emit a libvirt watchdog event
* src/remote/remote_driver.c: Receive and dispatch watchdog
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
watchdog events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for WATCHDOG event
from QEMU monitor
2010-03-18 19:07:48 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
myDomainEventIOErrorCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
const char *srcPath,
|
|
|
|
const char *devAlias,
|
|
|
|
int action,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
Add support for an explicit IO error event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_IO_ERROR
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_IO_ERROR_NONE = 0,
VIR_DOMAIN_EVENT_IO_ERROR_PAUSE,
VIR_DOMAIN_EVENT_IO_ERROR_REPORT,
} virDomainEventIOErrorAction;
In addition it has the source path of the disk that had the
error and its unique device alias. It does not include the
target device name (/dev/sda), since this would preclude
triggering IO errors from other file backed devices (eg
serial ports connected to a file)
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventIOErrorCallback)(virConnectPtr conn,
virDomainPtr dom,
const char *srcPath,
const char *devAlias,
int action,
void *opaque);
This is currently wired up to the QEMU block IO error events
* daemon/remote.c: Dispatch IO error events to client
* examples/domain-events/events-c/event-test.c: Watch for
IO error events
* include/libvirt/libvirt.h.in: Define new IO error event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle IO error events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for block IO errors and emit a libvirt IO error event
* src/remote/remote_driver.c: Receive and dispatch IO error
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
IO error events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for BLOCK_IO_ERROR event
from QEMU monitor
2010-03-18 19:37:44 +00:00
|
|
|
{
|
2016-04-13 13:45:52 +00:00
|
|
|
printf("%s EVENT: Domain %s(%d) io error path=%s alias=%s action=%d\n",
|
|
|
|
__func__, virDomainGetName(dom), virDomainGetID(dom),
|
|
|
|
srcPath, devAlias, action);
|
Add support for an explicit IO error event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_IO_ERROR
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_IO_ERROR_NONE = 0,
VIR_DOMAIN_EVENT_IO_ERROR_PAUSE,
VIR_DOMAIN_EVENT_IO_ERROR_REPORT,
} virDomainEventIOErrorAction;
In addition it has the source path of the disk that had the
error and its unique device alias. It does not include the
target device name (/dev/sda), since this would preclude
triggering IO errors from other file backed devices (eg
serial ports connected to a file)
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventIOErrorCallback)(virConnectPtr conn,
virDomainPtr dom,
const char *srcPath,
const char *devAlias,
int action,
void *opaque);
This is currently wired up to the QEMU block IO error events
* daemon/remote.c: Dispatch IO error events to client
* examples/domain-events/events-c/event-test.c: Watch for
IO error events
* include/libvirt/libvirt.h.in: Define new IO error event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle IO error events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for block IO errors and emit a libvirt IO error event
* src/remote/remote_driver.c: Receive and dispatch IO error
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
IO error events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for BLOCK_IO_ERROR event
from QEMU monitor
2010-03-18 19:37:44 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
2016-04-14 15:48:13 +00:00
|
|
|
static int
|
|
|
|
myDomainEventIOErrorReasonCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
const char *srcPath,
|
|
|
|
const char *devAlias,
|
|
|
|
int action,
|
|
|
|
const char *reason,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
printf("%s EVENT: Domain %s(%d) io error (reason) path=%s alias=%s "
|
|
|
|
"action=%d reason=%s\n",
|
|
|
|
__func__, virDomainGetName(dom), virDomainGetID(dom),
|
|
|
|
srcPath, devAlias, action, reason);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-14 08:49:59 +00:00
|
|
|
static const char *
|
|
|
|
graphicsPhaseToStr(int phase)
|
|
|
|
{
|
|
|
|
switch ((virDomainEventGraphicsPhase) phase) {
|
|
|
|
case VIR_DOMAIN_EVENT_GRAPHICS_CONNECT:
|
|
|
|
return "connected";
|
|
|
|
|
|
|
|
case VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE:
|
|
|
|
return "initialized";
|
|
|
|
|
|
|
|
case VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT:
|
|
|
|
return "disconnected";
|
2016-04-14 13:11:49 +00:00
|
|
|
|
|
|
|
case VIR_DOMAIN_EVENT_GRAPHICS_LAST:
|
|
|
|
break;
|
2016-04-14 08:49:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
static int
|
|
|
|
myDomainEventGraphicsCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
int phase,
|
|
|
|
virDomainEventGraphicsAddressPtr local,
|
|
|
|
virDomainEventGraphicsAddressPtr remote,
|
|
|
|
const char *authScheme,
|
|
|
|
virDomainEventGraphicsSubjectPtr subject,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
Add domain events for graphics network clients
This introduces a new event type
VIR_DOMAIN_EVENT_ID_GRAPHICS
The same event can be emitted in 3 scenarios
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_CONNECT = 0,
VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE,
VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT,
} virDomainEventGraphicsPhase;
Connect/disconnect are triggered at socket accept/close.
The initialize phase is immediately after the protocol
setup and authentication has completed. ie when the
client is authorized and about to start interacting with
the graphical desktop
This event comes with *a lot* of potential information
- IP address, port & address family of client
- IP address, port & address family of server
- Authentication scheme (arbitrary string)
- Authenticated subject identity. A subject may have
multiple identities with some authentication schemes.
For example, vencrypt+sasl results in a x509dname
and saslUsername identities.
This results in a very complicated callback :-(
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6,
} virDomainEventGraphicsAddressType;
struct _virDomainEventGraphicsAddress {
int family;
const char *node;
const char *service;
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
struct _virDomainEventGraphicsSubject {
int nidentity;
struct {
const char *type;
const char *name;
} *identities;
};
typedef struct _virDomainEventGraphicsSubject virDomainEventGraphicsSubject;
typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
virDomainPtr dom,
int phase,
virDomainEventGraphicsAddressPtr local,
virDomainEventGraphicsAddressPtr remote,
const char *authScheme,
virDomainEventGraphicsSubjectPtr subject,
void *opaque);
The wire protocol is similarly complex
struct remote_domain_event_graphics_address {
int family;
remote_nonnull_string node;
remote_nonnull_string service;
};
const REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX = 20;
struct remote_domain_event_graphics_identity {
remote_nonnull_string type;
remote_nonnull_string name;
};
struct remote_domain_event_graphics_msg {
remote_nonnull_domain dom;
int phase;
remote_domain_event_graphics_address local;
remote_domain_event_graphics_address remote;
remote_nonnull_string authScheme;
remote_domain_event_graphics_identity subject<REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX>;
};
This is currently implemented in QEMU for the VNC graphics
protocol, but designed to be usable with SPICE graphics in
the future too.
* daemon/remote.c: Dispatch graphics events to client
* examples/domain-events/events-c/event-test.c: Watch for
graphics events
* include/libvirt/libvirt.h.in: Define new graphics event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle graphics events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for VNC events and emit a libvirt graphics event
* src/remote/remote_driver.c: Receive and dispatch graphics
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
graphics events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for VNC_CONNECTED,
VNC_INITIALIZED & VNC_DISCONNETED events from QEMU monitor
2010-03-19 13:27:45 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in examples/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
Add domain events for graphics network clients
This introduces a new event type
VIR_DOMAIN_EVENT_ID_GRAPHICS
The same event can be emitted in 3 scenarios
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_CONNECT = 0,
VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE,
VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT,
} virDomainEventGraphicsPhase;
Connect/disconnect are triggered at socket accept/close.
The initialize phase is immediately after the protocol
setup and authentication has completed. ie when the
client is authorized and about to start interacting with
the graphical desktop
This event comes with *a lot* of potential information
- IP address, port & address family of client
- IP address, port & address family of server
- Authentication scheme (arbitrary string)
- Authenticated subject identity. A subject may have
multiple identities with some authentication schemes.
For example, vencrypt+sasl results in a x509dname
and saslUsername identities.
This results in a very complicated callback :-(
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6,
} virDomainEventGraphicsAddressType;
struct _virDomainEventGraphicsAddress {
int family;
const char *node;
const char *service;
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
struct _virDomainEventGraphicsSubject {
int nidentity;
struct {
const char *type;
const char *name;
} *identities;
};
typedef struct _virDomainEventGraphicsSubject virDomainEventGraphicsSubject;
typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
virDomainPtr dom,
int phase,
virDomainEventGraphicsAddressPtr local,
virDomainEventGraphicsAddressPtr remote,
const char *authScheme,
virDomainEventGraphicsSubjectPtr subject,
void *opaque);
The wire protocol is similarly complex
struct remote_domain_event_graphics_address {
int family;
remote_nonnull_string node;
remote_nonnull_string service;
};
const REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX = 20;
struct remote_domain_event_graphics_identity {
remote_nonnull_string type;
remote_nonnull_string name;
};
struct remote_domain_event_graphics_msg {
remote_nonnull_domain dom;
int phase;
remote_domain_event_graphics_address local;
remote_domain_event_graphics_address remote;
remote_nonnull_string authScheme;
remote_domain_event_graphics_identity subject<REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX>;
};
This is currently implemented in QEMU for the VNC graphics
protocol, but designed to be usable with SPICE graphics in
the future too.
* daemon/remote.c: Dispatch graphics events to client
* examples/domain-events/events-c/event-test.c: Watch for
graphics events
* include/libvirt/libvirt.h.in: Define new graphics event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle graphics events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for VNC events and emit a libvirt graphics event
* src/remote/remote_driver.c: Receive and dispatch graphics
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
graphics events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for VNC_CONNECTED,
VNC_INITIALIZED & VNC_DISCONNETED events from QEMU monitor
2010-03-19 13:27:45 +00:00
|
|
|
printf("%s EVENT: Domain %s(%d) graphics ", __func__, virDomainGetName(dom),
|
|
|
|
virDomainGetID(dom));
|
|
|
|
|
2016-04-14 08:49:59 +00:00
|
|
|
printf("%s ", graphicsPhaseToStr(phase));
|
Add domain events for graphics network clients
This introduces a new event type
VIR_DOMAIN_EVENT_ID_GRAPHICS
The same event can be emitted in 3 scenarios
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_CONNECT = 0,
VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE,
VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT,
} virDomainEventGraphicsPhase;
Connect/disconnect are triggered at socket accept/close.
The initialize phase is immediately after the protocol
setup and authentication has completed. ie when the
client is authorized and about to start interacting with
the graphical desktop
This event comes with *a lot* of potential information
- IP address, port & address family of client
- IP address, port & address family of server
- Authentication scheme (arbitrary string)
- Authenticated subject identity. A subject may have
multiple identities with some authentication schemes.
For example, vencrypt+sasl results in a x509dname
and saslUsername identities.
This results in a very complicated callback :-(
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6,
} virDomainEventGraphicsAddressType;
struct _virDomainEventGraphicsAddress {
int family;
const char *node;
const char *service;
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
struct _virDomainEventGraphicsSubject {
int nidentity;
struct {
const char *type;
const char *name;
} *identities;
};
typedef struct _virDomainEventGraphicsSubject virDomainEventGraphicsSubject;
typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
virDomainPtr dom,
int phase,
virDomainEventGraphicsAddressPtr local,
virDomainEventGraphicsAddressPtr remote,
const char *authScheme,
virDomainEventGraphicsSubjectPtr subject,
void *opaque);
The wire protocol is similarly complex
struct remote_domain_event_graphics_address {
int family;
remote_nonnull_string node;
remote_nonnull_string service;
};
const REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX = 20;
struct remote_domain_event_graphics_identity {
remote_nonnull_string type;
remote_nonnull_string name;
};
struct remote_domain_event_graphics_msg {
remote_nonnull_domain dom;
int phase;
remote_domain_event_graphics_address local;
remote_domain_event_graphics_address remote;
remote_nonnull_string authScheme;
remote_domain_event_graphics_identity subject<REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX>;
};
This is currently implemented in QEMU for the VNC graphics
protocol, but designed to be usable with SPICE graphics in
the future too.
* daemon/remote.c: Dispatch graphics events to client
* examples/domain-events/events-c/event-test.c: Watch for
graphics events
* include/libvirt/libvirt.h.in: Define new graphics event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle graphics events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for VNC events and emit a libvirt graphics event
* src/remote/remote_driver.c: Receive and dispatch graphics
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
graphics events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for VNC_CONNECTED,
VNC_INITIALIZED & VNC_DISCONNETED events from QEMU monitor
2010-03-19 13:27:45 +00:00
|
|
|
|
|
|
|
printf("local: family=%d node=%s service=%s ",
|
|
|
|
local->family, local->node, local->service);
|
|
|
|
printf("remote: family=%d node=%s service=%s ",
|
|
|
|
remote->family, remote->node, remote->service);
|
|
|
|
|
|
|
|
printf("auth: %s ", authScheme);
|
2013-05-21 08:04:26 +00:00
|
|
|
for (i = 0; i < subject->nidentity; i++) {
|
Add domain events for graphics network clients
This introduces a new event type
VIR_DOMAIN_EVENT_ID_GRAPHICS
The same event can be emitted in 3 scenarios
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_CONNECT = 0,
VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE,
VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT,
} virDomainEventGraphicsPhase;
Connect/disconnect are triggered at socket accept/close.
The initialize phase is immediately after the protocol
setup and authentication has completed. ie when the
client is authorized and about to start interacting with
the graphical desktop
This event comes with *a lot* of potential information
- IP address, port & address family of client
- IP address, port & address family of server
- Authentication scheme (arbitrary string)
- Authenticated subject identity. A subject may have
multiple identities with some authentication schemes.
For example, vencrypt+sasl results in a x509dname
and saslUsername identities.
This results in a very complicated callback :-(
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6,
} virDomainEventGraphicsAddressType;
struct _virDomainEventGraphicsAddress {
int family;
const char *node;
const char *service;
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
struct _virDomainEventGraphicsSubject {
int nidentity;
struct {
const char *type;
const char *name;
} *identities;
};
typedef struct _virDomainEventGraphicsSubject virDomainEventGraphicsSubject;
typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
virDomainPtr dom,
int phase,
virDomainEventGraphicsAddressPtr local,
virDomainEventGraphicsAddressPtr remote,
const char *authScheme,
virDomainEventGraphicsSubjectPtr subject,
void *opaque);
The wire protocol is similarly complex
struct remote_domain_event_graphics_address {
int family;
remote_nonnull_string node;
remote_nonnull_string service;
};
const REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX = 20;
struct remote_domain_event_graphics_identity {
remote_nonnull_string type;
remote_nonnull_string name;
};
struct remote_domain_event_graphics_msg {
remote_nonnull_domain dom;
int phase;
remote_domain_event_graphics_address local;
remote_domain_event_graphics_address remote;
remote_nonnull_string authScheme;
remote_domain_event_graphics_identity subject<REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX>;
};
This is currently implemented in QEMU for the VNC graphics
protocol, but designed to be usable with SPICE graphics in
the future too.
* daemon/remote.c: Dispatch graphics events to client
* examples/domain-events/events-c/event-test.c: Watch for
graphics events
* include/libvirt/libvirt.h.in: Define new graphics event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle graphics events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for VNC events and emit a libvirt graphics event
* src/remote/remote_driver.c: Receive and dispatch graphics
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
graphics events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for VNC_CONNECTED,
VNC_INITIALIZED & VNC_DISCONNETED events from QEMU monitor
2010-03-19 13:27:45 +00:00
|
|
|
printf(" identity: %s=%s",
|
|
|
|
subject->identities[i].type,
|
|
|
|
subject->identities[i].name);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
myDomainEventControlErrorCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
2011-05-29 12:21:53 +00:00
|
|
|
{
|
2016-04-13 13:45:52 +00:00
|
|
|
printf("%s EVENT: Domain %s(%d) control error\n", __func__,
|
|
|
|
virDomainGetName(dom), virDomainGetID(dom));
|
2011-05-29 12:21:53 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 15:38:16 +00:00
|
|
|
static const char *
|
|
|
|
diskChangeReasonToStr(int reason)
|
|
|
|
{
|
|
|
|
switch ((virConnectDomainEventDiskChangeReason) reason) {
|
|
|
|
case VIR_DOMAIN_EVENT_DISK_CHANGE_MISSING_ON_START:
|
|
|
|
return "disk empty due to startupPolicy";
|
|
|
|
|
|
|
|
case VIR_DOMAIN_EVENT_DISK_DROP_MISSING_ON_START:
|
|
|
|
return "disk dropped due to startupPolicy";
|
2016-04-14 13:11:49 +00:00
|
|
|
|
|
|
|
case VIR_DOMAIN_EVENT_DISK_CHANGE_LAST:
|
|
|
|
break;
|
2016-04-13 15:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
2011-05-29 12:21:53 +00:00
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
static int
|
|
|
|
myDomainEventDiskChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
const char *oldSrcPath,
|
|
|
|
const char *newSrcPath,
|
|
|
|
const char *devAlias,
|
|
|
|
int reason,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
2011-10-18 14:15:42 +00:00
|
|
|
{
|
2016-04-13 13:45:52 +00:00
|
|
|
printf("%s EVENT: Domain %s(%d) disk change oldSrcPath: %s newSrcPath: %s "
|
|
|
|
"devAlias: %s reason: %s\n",
|
2011-10-18 14:15:42 +00:00
|
|
|
__func__, virDomainGetName(dom), virDomainGetID(dom),
|
2016-04-13 15:38:16 +00:00
|
|
|
oldSrcPath, newSrcPath, devAlias, diskChangeReasonToStr(reason));
|
2011-10-18 14:15:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 15:38:16 +00:00
|
|
|
static const char *
|
|
|
|
trayChangeReasonToStr(int reason)
|
|
|
|
{
|
|
|
|
switch ((virDomainEventTrayChangeReason) reason) {
|
|
|
|
case VIR_DOMAIN_EVENT_TRAY_CHANGE_OPEN:
|
|
|
|
return "open";
|
|
|
|
|
|
|
|
case VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE:
|
|
|
|
return "close";
|
2016-04-14 13:11:49 +00:00
|
|
|
|
|
|
|
case VIR_DOMAIN_EVENT_TRAY_CHANGE_LAST:
|
|
|
|
break;
|
2016-04-13 15:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return "unknown";
|
2012-03-23 13:44:50 +00:00
|
|
|
};
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
myDomainEventTrayChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
const char *devAlias,
|
|
|
|
int reason,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
2012-03-23 13:44:50 +00:00
|
|
|
{
|
2016-04-13 13:45:52 +00:00
|
|
|
printf("%s EVENT: Domain %s(%d) removable disk's tray change devAlias: %s "
|
|
|
|
"reason: %s\n",
|
2012-03-23 13:44:50 +00:00
|
|
|
__func__, virDomainGetName(dom), virDomainGetID(dom),
|
2016-04-13 15:38:16 +00:00
|
|
|
devAlias, trayChangeReasonToStr(reason));
|
2012-03-23 13:44:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-10-18 14:15:42 +00:00
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
myDomainEventPMWakeupCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
int reason ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
2012-03-23 14:43:14 +00:00
|
|
|
{
|
2012-09-06 14:56:08 +00:00
|
|
|
printf("%s EVENT: Domain %s(%d) system pmwakeup\n",
|
2012-03-23 14:43:14 +00:00
|
|
|
__func__, virDomainGetName(dom), virDomainGetID(dom));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
myDomainEventPMSuspendCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
int reason ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
2012-03-23 14:50:36 +00:00
|
|
|
{
|
2012-09-06 14:56:08 +00:00
|
|
|
printf("%s EVENT: Domain %s(%d) system pmsuspend\n",
|
2012-03-23 14:50:36 +00:00
|
|
|
__func__, virDomainGetName(dom), virDomainGetID(dom));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
myDomainEventPMSuspendDiskCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
int reason ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
2012-10-12 19:13:39 +00:00
|
|
|
{
|
|
|
|
printf("%s EVENT: Domain %s(%d) system pmsuspend-disk\n",
|
|
|
|
__func__, virDomainGetName(dom), virDomainGetID(dom));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
2013-06-19 13:28:00 +00:00
|
|
|
static int
|
|
|
|
myDomainEventDeviceRemovedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
const char *devAlias,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
printf("%s EVENT: Domain %s(%d) device removed: %s\n",
|
|
|
|
__func__, virDomainGetName(dom), virDomainGetID(dom), devAlias);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
myNetworkEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virNetworkPtr dom,
|
|
|
|
int event,
|
|
|
|
int detail,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
2013-12-11 14:23:24 +00:00
|
|
|
{
|
|
|
|
printf("%s EVENT: Network %s %s %d\n", __func__, virNetworkGetName(dom),
|
|
|
|
networkEventToString(event), detail);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-14 15:31:52 +00:00
|
|
|
static void
|
|
|
|
eventTypedParamsPrint(virTypedParameterPtr params,
|
|
|
|
int nparams)
|
2014-08-26 21:47:44 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < nparams; i++) {
|
|
|
|
switch (params[i].type) {
|
|
|
|
case VIR_TYPED_PARAM_INT:
|
|
|
|
printf("\t%s: %d\n", params[i].field, params[i].value.i);
|
|
|
|
break;
|
|
|
|
case VIR_TYPED_PARAM_UINT:
|
|
|
|
printf("\t%s: %u\n", params[i].field, params[i].value.ui);
|
|
|
|
break;
|
|
|
|
case VIR_TYPED_PARAM_LLONG:
|
2014-09-25 13:03:46 +00:00
|
|
|
printf("\t%s: %" PRId64 "\n", params[i].field,
|
|
|
|
(int64_t) params[i].value.l);
|
2014-08-26 21:47:44 +00:00
|
|
|
break;
|
|
|
|
case VIR_TYPED_PARAM_ULLONG:
|
2014-09-25 13:03:46 +00:00
|
|
|
printf("\t%s: %" PRIu64 "\n", params[i].field,
|
|
|
|
(uint64_t) params[i].value.ul);
|
2014-08-26 21:47:44 +00:00
|
|
|
break;
|
|
|
|
case VIR_TYPED_PARAM_DOUBLE:
|
|
|
|
printf("\t%s: %g\n", params[i].field, params[i].value.d);
|
|
|
|
break;
|
|
|
|
case VIR_TYPED_PARAM_BOOLEAN:
|
|
|
|
printf("\t%s: %d\n", params[i].field, params[i].value.b);
|
|
|
|
break;
|
|
|
|
case VIR_TYPED_PARAM_STRING:
|
|
|
|
printf("\t%s: %s\n", params[i].field, params[i].value.s);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("\t%s: unknown type\n", params[i].field);
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
myDomainEventTunableCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
printf("%s EVENT: Domain %s(%d) tunable updated:\n",
|
|
|
|
__func__, virDomainGetName(dom), virDomainGetID(dom));
|
|
|
|
|
|
|
|
eventTypedParamsPrint(params, nparams);
|
2014-08-26 21:47:44 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-12-11 14:23:24 +00:00
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
2014-11-19 09:27:55 +00:00
|
|
|
static int
|
|
|
|
myDomainEventAgentLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
int state,
|
|
|
|
int reason,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
printf("%s EVENT: Domain %s(%d) guest agent state changed: %s reason: %s\n",
|
|
|
|
__func__, virDomainGetName(dom), virDomainGetID(dom),
|
|
|
|
guestAgentLifecycleEventStateToString(state),
|
|
|
|
guestAgentLifecycleEventReasonToString(reason));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
2015-04-14 12:56:09 +00:00
|
|
|
static int
|
|
|
|
myDomainEventDeviceAddedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
const char *devAlias,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
printf("%s EVENT: Domain %s(%d) device added: %s\n",
|
|
|
|
__func__, virDomainGetName(dom), virDomainGetID(dom), devAlias);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
|
2016-04-14 15:16:35 +00:00
|
|
|
static const char *
|
|
|
|
blockJobTypeToStr(int type)
|
|
|
|
{
|
|
|
|
switch ((virDomainBlockJobType) type) {
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN:
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_TYPE_LAST:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_TYPE_PULL:
|
|
|
|
return "block pull";
|
|
|
|
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_TYPE_COPY:
|
|
|
|
return "block copy";
|
|
|
|
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT:
|
|
|
|
return "block commit";
|
|
|
|
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT:
|
|
|
|
return "active layer block commit";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
blockJobStatusToStr(int status)
|
|
|
|
{
|
|
|
|
switch ((virConnectDomainEventBlockJobStatus) status) {
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_COMPLETED:
|
|
|
|
return "completed";
|
|
|
|
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_FAILED:
|
|
|
|
return "failed";
|
|
|
|
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_CANCELED:
|
|
|
|
return "cancelled";
|
|
|
|
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_READY:
|
|
|
|
return "ready";
|
|
|
|
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_LAST:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
myDomainEventBlockJobCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
const char *disk,
|
|
|
|
int type,
|
|
|
|
int status,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
const char *eventName = opaque;
|
|
|
|
|
|
|
|
printf("%s EVENT: Domain %s(%d) block job callback '%s' disk '%s', "
|
|
|
|
"type '%s' status '%s'",
|
|
|
|
__func__, virDomainGetName(dom), virDomainGetID(dom), eventName,
|
|
|
|
disk, blockJobTypeToStr(type), blockJobStatusToStr(status));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-14 15:26:53 +00:00
|
|
|
static int
|
|
|
|
myDomainEventMigrationIterationCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
int iteration,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
printf("%s EVENT: Domain %s(%d) migration iteration '%d'\n",
|
|
|
|
__func__, virDomainGetName(dom), virDomainGetID(dom), iteration);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-14 15:31:52 +00:00
|
|
|
static int
|
|
|
|
myDomainEventJobCompletedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
printf("%s EVENT: Domain %s(%d) job completed:\n",
|
|
|
|
__func__, virDomainGetName(dom), virDomainGetID(dom));
|
|
|
|
|
|
|
|
eventTypedParamsPrint(params, nparams);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-14 15:34:50 +00:00
|
|
|
static int
|
|
|
|
myDomainEventDeviceRemovalFailedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
const char *devAlias,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
printf("%s EVENT: Domain %s(%d) device removal failed: %s\n",
|
|
|
|
__func__, virDomainGetName(dom), virDomainGetID(dom), devAlias);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
static void
|
|
|
|
myFreeFunc(void *opaque)
|
2008-11-19 15:25:24 +00:00
|
|
|
{
|
|
|
|
char *str = opaque;
|
2008-12-18 12:25:11 +00:00
|
|
|
printf("%s: Freeing [%s]\n", __func__, str);
|
2008-11-19 15:25:24 +00:00
|
|
|
free(str);
|
|
|
|
}
|
|
|
|
|
2008-10-23 13:18:18 +00:00
|
|
|
|
|
|
|
/* main test functions */
|
2016-04-13 13:45:52 +00:00
|
|
|
static void
|
|
|
|
stop(int sig)
|
2008-11-19 15:25:24 +00:00
|
|
|
{
|
|
|
|
printf("Exiting on signal %d\n", sig);
|
|
|
|
run = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-14 14:57:02 +00:00
|
|
|
struct domainEventData {
|
|
|
|
int event;
|
|
|
|
int id;
|
|
|
|
virConnectDomainEventGenericCallback cb;
|
|
|
|
const char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define DOMAIN_EVENT(event, callback) \
|
|
|
|
{event, -1, VIR_DOMAIN_EVENT_CALLBACK(callback), #event}
|
|
|
|
|
|
|
|
struct domainEventData domainEvents[] = {
|
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_LIFECYCLE, myDomainEventCallback2),
|
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_REBOOT, myDomainEventRebootCallback),
|
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_RTC_CHANGE, myDomainEventRTCChangeCallback),
|
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_WATCHDOG, myDomainEventWatchdogCallback),
|
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_IO_ERROR, myDomainEventIOErrorCallback),
|
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_GRAPHICS, myDomainEventGraphicsCallback),
|
2016-04-14 15:48:13 +00:00
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON, myDomainEventIOErrorReasonCallback),
|
2016-04-14 14:57:02 +00:00
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_CONTROL_ERROR, myDomainEventControlErrorCallback),
|
2016-04-14 15:16:35 +00:00
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_BLOCK_JOB, myDomainEventBlockJobCallback),
|
2016-04-14 14:57:02 +00:00
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_DISK_CHANGE, myDomainEventDiskChangeCallback),
|
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_TRAY_CHANGE, myDomainEventTrayChangeCallback),
|
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_PMWAKEUP, myDomainEventPMWakeupCallback),
|
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_PMSUSPEND, myDomainEventPMSuspendCallback),
|
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE, myDomainEventBalloonChangeCallback),
|
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK, myDomainEventPMSuspendDiskCallback),
|
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED, myDomainEventDeviceRemovedCallback),
|
2016-04-14 15:16:35 +00:00
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2, myDomainEventBlockJobCallback),
|
2016-04-14 14:57:02 +00:00
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_TUNABLE, myDomainEventTunableCallback),
|
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE, myDomainEventAgentLifecycleCallback),
|
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_DEVICE_ADDED, myDomainEventDeviceAddedCallback),
|
2016-04-14 15:26:53 +00:00
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION, myDomainEventMigrationIterationCallback),
|
2016-04-14 15:31:52 +00:00
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_JOB_COMPLETED, myDomainEventJobCompletedCallback),
|
2016-04-14 15:34:50 +00:00
|
|
|
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED, myDomainEventDeviceRemovalFailedCallback),
|
2016-04-14 14:57:02 +00:00
|
|
|
};
|
|
|
|
|
2016-04-14 15:41:19 +00:00
|
|
|
/* make sure that the events are kept in sync */
|
|
|
|
verify(ARRAY_CARDINALITY(domainEvents) == VIR_DOMAIN_EVENT_ID_LAST);
|
|
|
|
|
2016-04-13 13:45:52 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
2008-10-23 13:18:18 +00:00
|
|
|
{
|
2016-03-16 08:55:47 +00:00
|
|
|
int ret = EXIT_FAILURE;
|
|
|
|
virConnectPtr dconn = NULL;
|
2009-05-25 09:44:10 +00:00
|
|
|
int callback1ret = -1;
|
2013-12-11 14:23:24 +00:00
|
|
|
int callback16ret = -1;
|
2010-04-25 10:50:23 +00:00
|
|
|
struct sigaction action_stop;
|
2016-04-14 14:57:02 +00:00
|
|
|
size_t i;
|
2010-03-18 17:47:02 +00:00
|
|
|
|
2012-03-29 09:52:04 +00:00
|
|
|
memset(&action_stop, 0, sizeof(action_stop));
|
2010-04-25 10:50:23 +00:00
|
|
|
|
|
|
|
action_stop.sa_handler = stop;
|
2008-10-23 13:18:18 +00:00
|
|
|
|
2011-03-23 14:30:30 +00:00
|
|
|
if (argc > 1 && STREQ(argv[1], "--help")) {
|
2016-04-13 13:21:17 +00:00
|
|
|
printf("%s uri\n", argv[0]);
|
2016-03-16 08:55:47 +00:00
|
|
|
goto cleanup;
|
2013-05-09 21:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (virInitialize() < 0) {
|
|
|
|
fprintf(stderr, "Failed to initialize libvirt");
|
2016-03-16 08:55:47 +00:00
|
|
|
goto cleanup;
|
2008-10-23 13:18:18 +00:00
|
|
|
}
|
2008-11-19 15:25:24 +00:00
|
|
|
|
2013-05-09 21:17:44 +00:00
|
|
|
if (virEventRegisterDefaultImpl() < 0) {
|
|
|
|
fprintf(stderr, "Failed to register event implementation: %s\n",
|
2016-05-19 19:10:19 +00:00
|
|
|
virGetLastErrorMessage());
|
2016-03-16 08:55:47 +00:00
|
|
|
goto cleanup;
|
2013-05-09 21:17:44 +00:00
|
|
|
}
|
2008-10-23 13:18:18 +00:00
|
|
|
|
2011-11-22 11:09:13 +00:00
|
|
|
dconn = virConnectOpenAuth(argc > 1 ? argv[1] : NULL,
|
|
|
|
virConnectAuthPtrDefault,
|
|
|
|
VIR_CONNECT_RO);
|
2008-10-23 13:18:18 +00:00
|
|
|
if (!dconn) {
|
|
|
|
printf("error opening\n");
|
2016-03-16 08:55:47 +00:00
|
|
|
goto cleanup;
|
2008-10-23 13:18:18 +00:00
|
|
|
}
|
|
|
|
|
2016-03-16 08:32:44 +00:00
|
|
|
if (virConnectRegisterCloseCallback(dconn,
|
|
|
|
connectClose, NULL, NULL) < 0) {
|
|
|
|
fprintf(stderr, "Unable to register close callback\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-07-19 14:59:59 +00:00
|
|
|
|
2008-11-19 15:25:24 +00:00
|
|
|
sigaction(SIGTERM, &action_stop, NULL);
|
|
|
|
sigaction(SIGINT, &action_stop, NULL);
|
|
|
|
|
2016-04-13 11:55:12 +00:00
|
|
|
printf("Registering event callbacks\n");
|
2008-10-23 13:18:18 +00:00
|
|
|
|
2009-05-25 09:44:10 +00:00
|
|
|
callback1ret = virConnectDomainEventRegister(dconn, myDomainEventCallback1,
|
|
|
|
strdup("callback 1"), myFreeFunc);
|
2016-04-14 14:57:02 +00:00
|
|
|
|
|
|
|
/* register common domain callbacks */
|
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(domainEvents); i++) {
|
|
|
|
struct domainEventData *event = domainEvents + i;
|
|
|
|
|
|
|
|
event->id = virConnectDomainEventRegisterAny(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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-11 14:23:24 +00:00
|
|
|
callback16ret = virConnectNetworkEventRegisterAny(dconn,
|
|
|
|
NULL,
|
|
|
|
VIR_NETWORK_EVENT_ID_LIFECYCLE,
|
|
|
|
VIR_NETWORK_EVENT_CALLBACK(myNetworkEventCallback),
|
|
|
|
strdup("net callback"), myFreeFunc);
|
2013-06-19 13:28:00 +00:00
|
|
|
|
2016-03-16 08:55:47 +00:00
|
|
|
if ((callback1ret == -1) ||
|
2016-04-14 14:57:02 +00:00
|
|
|
(callback16ret == -1))
|
2016-03-16 08:55:47 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virConnectSetKeepAlive(dconn, 5, 3) < 0) {
|
|
|
|
fprintf(stderr, "Failed to start keepalive protocol: %s\n",
|
2016-05-19 19:10:19 +00:00
|
|
|
virGetLastErrorMessage());
|
2016-03-16 08:55:47 +00:00
|
|
|
run = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (run) {
|
|
|
|
if (virEventRunDefaultImpl() < 0) {
|
|
|
|
fprintf(stderr, "Failed to run event loop: %s\n",
|
2016-05-19 19:10:19 +00:00
|
|
|
virGetLastErrorMessage());
|
2008-10-23 13:18:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-13 11:55:12 +00:00
|
|
|
printf("Deregistering event callbacks\n");
|
2016-03-16 08:55:47 +00:00
|
|
|
virConnectDomainEventDeregister(dconn, myDomainEventCallback1);
|
|
|
|
virConnectNetworkEventDeregisterAny(dconn, callback16ret);
|
|
|
|
|
2016-04-14 14:57:02 +00:00
|
|
|
|
|
|
|
printf("Deregistering domain event callbacks\n");
|
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(domainEvents); i++) {
|
|
|
|
if (domainEvents[i].id > 0)
|
|
|
|
virConnectDomainEventDeregisterAny(dconn, domainEvents[i].id);
|
|
|
|
}
|
2016-03-16 08:55:47 +00:00
|
|
|
|
2013-12-13 16:07:52 +00:00
|
|
|
virConnectUnregisterCloseCallback(dconn, connectClose);
|
2016-03-16 08:55:47 +00:00
|
|
|
ret = EXIT_SUCCESS;
|
2013-12-13 16:07:52 +00:00
|
|
|
|
2008-11-19 15:25:24 +00:00
|
|
|
|
2016-03-16 08:55:47 +00:00
|
|
|
cleanup:
|
|
|
|
if (dconn) {
|
2016-04-13 11:55:12 +00:00
|
|
|
printf("Closing connection: ");
|
2016-03-16 08:55:47 +00:00
|
|
|
if (virConnectClose(dconn) < 0)
|
2016-04-13 11:55:12 +00:00
|
|
|
printf("failed\n");
|
2016-03-16 08:55:47 +00:00
|
|
|
printf("done\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2008-10-23 13:18:18 +00:00
|
|
|
}
|