|
|
9119d9 |
From 5c899f2d34886652affe2bdd360d7286ab5804cb Mon Sep 17 00:00:00 2001
|
|
|
9119d9 |
Message-Id: <5c899f2d34886652affe2bdd360d7286ab5804cb@dist-git>
|
|
|
9119d9 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
9119d9 |
Date: Mon, 24 Nov 2014 17:51:19 +0100
|
|
|
9119d9 |
Subject: [PATCH] examples: Add support for the guest agent lifecycle event
|
|
|
9119d9 |
|
|
|
9119d9 |
https://bugzilla.redhat.com/show_bug.cgi?id=1146944
|
|
|
9119d9 |
|
|
|
9119d9 |
Add code to support the event in the object-event example.
|
|
|
9119d9 |
|
|
|
9119d9 |
(cherry picked from commit 4ca2744e8b8dcb3e05b332b6419c85b34697ab42)
|
|
|
9119d9 |
|
|
|
9119d9 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
9119d9 |
---
|
|
|
9119d9 |
examples/object-events/event-test.c | 67 ++++++++++++++++++++++++++++++++++++-
|
|
|
9119d9 |
1 file changed, 66 insertions(+), 1 deletion(-)
|
|
|
9119d9 |
|
|
|
9119d9 |
diff --git a/examples/object-events/event-test.c b/examples/object-events/event-test.c
|
|
|
9119d9 |
index 0c6faf4..d94babd 100644
|
|
|
9119d9 |
--- a/examples/object-events/event-test.c
|
|
|
9119d9 |
+++ b/examples/object-events/event-test.c
|
|
|
9119d9 |
@@ -244,6 +244,47 @@ networkEventToString(int event)
|
|
|
9119d9 |
return ret;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
+static const char *
|
|
|
9119d9 |
+guestAgentLifecycleEventStateToString(int event)
|
|
|
9119d9 |
+{
|
|
|
9119d9 |
+ const char *ret = "";
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ switch ((virConnectDomainEventAgentLifecycleState) event) {
|
|
|
9119d9 |
+ case VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_DISCONNECTED:
|
|
|
9119d9 |
+ ret = "Disconnected";
|
|
|
9119d9 |
+ break;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ case VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_CONNECTED:
|
|
|
9119d9 |
+ ret = "Connected";
|
|
|
9119d9 |
+ break;
|
|
|
9119d9 |
+ }
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ return ret;
|
|
|
9119d9 |
+}
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+static const char *
|
|
|
9119d9 |
+guestAgentLifecycleEventReasonToString(int event)
|
|
|
9119d9 |
+{
|
|
|
9119d9 |
+ const char *ret = "";
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ switch ((virConnectDomainEventAgentLifecycleReason) event) {
|
|
|
9119d9 |
+ case VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_UNKNOWN:
|
|
|
9119d9 |
+ ret = "Unknown";
|
|
|
9119d9 |
+ break;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ case VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED:
|
|
|
9119d9 |
+ ret = "Domain started";
|
|
|
9119d9 |
+ break;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ case VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL:
|
|
|
9119d9 |
+ ret = "Channel event";
|
|
|
9119d9 |
+ break;
|
|
|
9119d9 |
+ }
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ return ret;
|
|
|
9119d9 |
+}
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+
|
|
|
9119d9 |
static int myDomainEventCallback1(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
9119d9 |
virDomainPtr dom,
|
|
|
9119d9 |
int event,
|
|
|
9119d9 |
@@ -509,6 +550,21 @@ myDomainEventTunableCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
9119d9 |
return 0;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
+static int
|
|
|
9119d9 |
+myDomainEventAgentLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
9119d9 |
+ virDomainPtr dom,
|
|
|
9119d9 |
+ int state,
|
|
|
9119d9 |
+ int reason,
|
|
|
9119d9 |
+ void *opaque ATTRIBUTE_UNUSED)
|
|
|
9119d9 |
+{
|
|
|
9119d9 |
+ printf("%s EVENT: Domain %s(%d) guest agent state changed: %s reason: %s\n",
|
|
|
9119d9 |
+ __func__, virDomainGetName(dom), virDomainGetID(dom),
|
|
|
9119d9 |
+ guestAgentLifecycleEventStateToString(state),
|
|
|
9119d9 |
+ guestAgentLifecycleEventReasonToString(reason));
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ return 0;
|
|
|
9119d9 |
+}
|
|
|
9119d9 |
+
|
|
|
9119d9 |
static void myFreeFunc(void *opaque)
|
|
|
9119d9 |
{
|
|
|
9119d9 |
char *str = opaque;
|
|
|
9119d9 |
@@ -551,6 +607,7 @@ int main(int argc, char **argv)
|
|
|
9119d9 |
int callback15ret = -1;
|
|
|
9119d9 |
int callback16ret = -1;
|
|
|
9119d9 |
int callback17ret = -1;
|
|
|
9119d9 |
+ int callback18ret = -1;
|
|
|
9119d9 |
struct sigaction action_stop;
|
|
|
9119d9 |
|
|
|
9119d9 |
memset(&action_stop, 0, sizeof(action_stop));
|
|
|
9119d9 |
@@ -674,6 +731,11 @@ int main(int argc, char **argv)
|
|
|
9119d9 |
VIR_DOMAIN_EVENT_ID_TUNABLE,
|
|
|
9119d9 |
VIR_DOMAIN_EVENT_CALLBACK(myDomainEventTunableCallback),
|
|
|
9119d9 |
strdup("tunable"), myFreeFunc);
|
|
|
9119d9 |
+ callback18ret = virConnectDomainEventRegisterAny(dconn,
|
|
|
9119d9 |
+ NULL,
|
|
|
9119d9 |
+ VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE,
|
|
|
9119d9 |
+ VIR_DOMAIN_EVENT_CALLBACK(myDomainEventAgentLifecycleCallback),
|
|
|
9119d9 |
+ strdup("guest agent lifecycle"), myFreeFunc);
|
|
|
9119d9 |
|
|
|
9119d9 |
if ((callback1ret != -1) &&
|
|
|
9119d9 |
(callback2ret != -1) &&
|
|
|
9119d9 |
@@ -690,7 +752,8 @@ int main(int argc, char **argv)
|
|
|
9119d9 |
(callback14ret != -1) &&
|
|
|
9119d9 |
(callback15ret != -1) &&
|
|
|
9119d9 |
(callback16ret != -1) &&
|
|
|
9119d9 |
- (callback17ret != -1)) {
|
|
|
9119d9 |
+ (callback17ret != -1) &&
|
|
|
9119d9 |
+ (callback18ret != -1)) {
|
|
|
9119d9 |
if (virConnectSetKeepAlive(dconn, 5, 3) < 0) {
|
|
|
9119d9 |
virErrorPtr err = virGetLastError();
|
|
|
9119d9 |
fprintf(stderr, "Failed to start keepalive protocol: %s\n",
|
|
|
9119d9 |
@@ -723,6 +786,8 @@ int main(int argc, char **argv)
|
|
|
9119d9 |
virConnectDomainEventDeregisterAny(dconn, callback15ret);
|
|
|
9119d9 |
virConnectNetworkEventDeregisterAny(dconn, callback16ret);
|
|
|
9119d9 |
virConnectDomainEventDeregisterAny(dconn, callback17ret);
|
|
|
9119d9 |
+ virConnectDomainEventDeregisterAny(dconn, callback18ret);
|
|
|
9119d9 |
+
|
|
|
9119d9 |
if (callback8ret != -1)
|
|
|
9119d9 |
virConnectDomainEventDeregisterAny(dconn, callback8ret);
|
|
|
9119d9 |
}
|
|
|
9119d9 |
--
|
|
|
9119d9 |
2.1.3
|
|
|
9119d9 |
|