in some systems which actually have virConnectListAllDomains()
we can't detect this.
*/
-#ifdef LIBVIR_CHECK_VERSION
#if LIBVIR_CHECK_VERSION(0, 10, 2)
#define HAVE_LIST_ALL_DOMAINS 1
#endif
-#endif
#if LIBVIR_CHECK_VERSION(1, 0, 1)
#define HAVE_DOM_REASON_PAUSED_SNAPSHOT 1
case VIR_DOMAIN_EVENT_SHUTDOWN:
ret = VIR_DOMAIN_SHUTDOWN;
break;
+#ifdef HAVE_DOM_STATE_PMSUSPENDED
case VIR_DOMAIN_EVENT_PMSUSPENDED:
ret = VIR_DOMAIN_PMSUSPENDED;
break;
+#endif
+#ifdef HAVE_DOM_REASON_CRASHED
case VIR_DOMAIN_EVENT_CRASHED:
ret = VIR_DOMAIN_CRASHED;
break;
+#endif
default:
ret = VIR_DOMAIN_NOSTATE;
}
return ret;
}
+#ifdef HAVE_DOM_REASON
static int map_domain_event_detail_to_reason(int event, int detail) {
int ret;
switch (event) {
case VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT: /* Restored from snapshot */
ret = VIR_DOMAIN_RUNNING_FROM_SNAPSHOT;
break;
+#ifdef HAVE_DOM_REASON_RUNNING_WAKEUP
case VIR_DOMAIN_EVENT_STARTED_WAKEUP: /* Started due to wakeup event */
ret = VIR_DOMAIN_RUNNING_WAKEUP;
break;
+#endif
default:
ret = VIR_DOMAIN_RUNNING_UNKNOWN;
}
libvirt API call */
ret = VIR_DOMAIN_PAUSED_UNKNOWN;
break;
+#ifdef HAVE_DOM_REASON_POSTCOPY
case VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY: /* Suspended for post-copy
migration */
ret = VIR_DOMAIN_PAUSED_POSTCOPY;
post-copy */
ret = VIR_DOMAIN_PAUSED_POSTCOPY_FAILED;
break;
+#endif
default:
ret = VIR_DOMAIN_PAUSED_UNKNOWN;
}
case VIR_DOMAIN_EVENT_RESUMED_FROM_SNAPSHOT: /* Resumed from snapshot */
ret = VIR_DOMAIN_RUNNING_FROM_SNAPSHOT;
break;
+#ifdef HAVE_DOM_REASON_POSTCOPY
case VIR_DOMAIN_EVENT_RESUMED_POSTCOPY: /* Resumed, but migration is still
running in post-copy mode */
ret = VIR_DOMAIN_RUNNING_POSTCOPY;
break;
+#endif
default:
ret = VIR_DOMAIN_RUNNING_UNKNOWN;
}
ret = VIR_DOMAIN_SHUTDOWN_UNKNOWN;
}
break;
+#ifdef HAVE_DOM_STATE_PMSUSPENDED
case VIR_DOMAIN_EVENT_PMSUSPENDED:
switch (detail) {
case VIR_DOMAIN_EVENT_PMSUSPENDED_MEMORY: /* Guest was PM suspended to
ret = VIR_DOMAIN_PMSUSPENDED_UNKNOWN;
}
break;
+#endif
case VIR_DOMAIN_EVENT_CRASHED:
switch (detail) {
case VIR_DOMAIN_EVENT_CRASHED_PANICKED: /* Guest was panicked */
return ret;
}
-#ifdef HAVE_DOM_REASON
#define DOMAIN_STATE_REASON_MAX_SIZE 20
const char *domain_reasons[][DOMAIN_STATE_REASON_MAX_SIZE] = {
[VIR_DOMAIN_NOSTATE][VIR_DOMAIN_NOSTATE_UNKNOWN] =
[VIR_DOMAIN_RUNNING][VIR_DOMAIN_RUNNING_POSTCOPY] =
"running in post-copy migration mode",
#endif
-
[VIR_DOMAIN_BLOCKED][VIR_DOMAIN_BLOCKED_UNKNOWN] =
"the reason is unknown",
[VIR_DOMAIN_PAUSED][VIR_DOMAIN_PAUSED_POSTCOPY_FAILED] =
"paused after failed post-copy",
#endif
-
[VIR_DOMAIN_SHUTDOWN][VIR_DOMAIN_SHUTDOWN_UNKNOWN] =
"the reason is unknown",
[VIR_DOMAIN_SHUTDOWN][VIR_DOMAIN_SHUTDOWN_USER] =
virDomainPtr dom, int event, int detail,
__attribute__((unused)) void *opaque) {
int domain_state = map_domain_event_to_state(event);
- int domain_reason = map_domain_event_detail_to_reason(event, detail);
+ int domain_reason = 0; /* 0 means UNKNOWN reason for any state */
+#ifdef HAVE_DOM_REASON
+ domain_reason = map_domain_event_detail_to_reason(event, detail);
+#endif
domain_state_submit_notif(dom, domain_state, domain_reason);
return 0;
/* Get domains' metrics */
for (int i = 0; i < state->nr_domains; ++i) {
domain_t *dom = &state->domains[i];
- int status;
+ int status = 0;
if (dom->active)
status = get_domain_metrics(dom);
+#ifdef HAVE_DOM_REASON
else
status = get_domain_state(dom->ptr);
+#endif
if (status != 0)
ERROR(PLUGIN_NAME " failed to get metrics for domain=%s",