aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2012-07-13 17:05:17 +0800
committerGuannan Ren <gren@redhat.com>2012-07-14 16:02:26 +0800
commit7ed6d7dda78b48ee02af285f6edfbe6dd719c2bc (patch)
tree788cebf1b5c723de6564b929a7c0a7b50b1c9d40 /examples
parentARMHF: CPU Support for armhf. (diff)
downloadlibvirt-7ed6d7dda78b48ee02af285f6edfbe6dd719c2bc.tar.gz
libvirt-7ed6d7dda78b48ee02af285f6edfbe6dd719c2bc.tar.bz2
libvirt-7ed6d7dda78b48ee02af285f6edfbe6dd719c2bc.zip
Define public API for receiving guest memory balloon events
When the guest changes its memory balloon applications may want to know what the new value is, without having to periodically poll on XML / domain info. Introduce a "balloon change" event to let apps see this * include/libvirt/libvirt.h.in: Define the virConnectDomainEventBalloonChangeCallback callback and VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE constant * python/libvirt-override-virConnect.py, python/libvirt-override.c: Wire up helpers for new event * daemon/remote.c: Helper for serializing balloon event * examples/domain-events/events-c/event-test.c, examples/domain-events/events-python/event-test.py: Add example of balloon event usage * src/conf/domain_event.c, src/conf/domain_event.h: Handling of balloon events * src/remote/remote_driver.c: Add handler of balloon events * src/remote/remote_protocol.x: Define wire protocol for balloon events * src/remote_protocol-structs: Likewise. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/domain-events/events-c/event-test.c22
-rw-r--r--examples/domain-events/events-python/event-test.py3
2 files changed, 24 insertions, 1 deletions
diff --git a/examples/domain-events/events-c/event-test.c b/examples/domain-events/events-c/event-test.c
index c54778f7d..ef6e77a65 100644
--- a/examples/domain-events/events-c/event-test.c
+++ b/examples/domain-events/events-c/event-test.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <signal.h>
+#include <inttypes.h>
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
@@ -222,6 +223,17 @@ static int myDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
return 0;
}
+static int myDomainEventBalloonChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ unsigned long long actual,
+ void *opaque ATTRIBUTE_UNUSED)
+{
+ printf("%s EVENT: Domain %s(%d) balloon change %" PRIuMAX "KB\n",
+ __func__, virDomainGetName(dom), virDomainGetID(dom), (uintmax_t)actual);
+
+ return 0;
+}
+
static int myDomainEventWatchdogCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
virDomainPtr dom,
int action,
@@ -391,6 +403,7 @@ int main(int argc, char **argv)
int callback10ret = -1;
int callback11ret = -1;
int callback12ret = -1;
+ int callback13ret = -1;
struct sigaction action_stop;
memset(&action_stop, 0, sizeof(action_stop));
@@ -476,6 +489,11 @@ int main(int argc, char **argv)
VIR_DOMAIN_EVENT_ID_PMSUSPEND,
VIR_DOMAIN_EVENT_CALLBACK(myDomainEventPMSuspendCallback),
strdup("pmsuspend"), myFreeFunc);
+ callback13ret = virConnectDomainEventRegisterAny(dconn,
+ NULL,
+ VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE,
+ VIR_DOMAIN_EVENT_CALLBACK(myDomainEventBalloonChangeCallback),
+ strdup("callback balloonchange"), myFreeFunc);
if ((callback1ret != -1) &&
(callback2ret != -1) &&
(callback3ret != -1) &&
@@ -486,7 +504,8 @@ int main(int argc, char **argv)
(callback9ret != -1) &&
(callback10ret != -1) &&
(callback11ret != -1) &&
- (callback12ret != -1)) {
+ (callback12ret != -1) &&
+ (callback13ret != -1)) {
if (virConnectSetKeepAlive(dconn, 5, 3) < 0) {
virErrorPtr err = virGetLastError();
fprintf(stderr, "Failed to start keepalive protocol: %s\n",
@@ -514,6 +533,7 @@ int main(int argc, char **argv)
virConnectDomainEventDeregisterAny(dconn, callback10ret);
virConnectDomainEventDeregisterAny(dconn, callback11ret);
virConnectDomainEventDeregisterAny(dconn, callback12ret);
+ virConnectDomainEventDeregisterAny(dconn, callback13ret);
if (callback8ret != -1)
virConnectDomainEventDeregisterAny(dconn, callback8ret);
}
diff --git a/examples/domain-events/events-python/event-test.py b/examples/domain-events/events-python/event-test.py
index 96dc2684f..137c31c88 100644
--- a/examples/domain-events/events-python/event-test.py
+++ b/examples/domain-events/events-python/event-test.py
@@ -483,6 +483,8 @@ def myDomainEventPMWakeupCallback(conn, dom, reason, opaque):
def myDomainEventPMSuspendCallback(conn, dom, reason, opaque):
print "myDomainEventPMSuspendCallback: Domain %s(%s) system pmsuspend" % (
dom.name(), dom.ID())
+def myDomainEventBalloonChangeCallback(conn, dom, utcoffset, actual):
+ print "myDomainEventBalloonChangeCallback: Domain %s(%s) %d" % (dom.name(), dom.ID(), actual)
def usage(out=sys.stderr):
print >>out, "usage: "+os.path.basename(sys.argv[0])+" [-hdl] [uri]"
print >>out, " uri will default to qemu:///system"
@@ -544,6 +546,7 @@ def main():
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_TRAY_CHANGE, myDomainEventTrayChangeCallback, None)
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_PMWAKEUP, myDomainEventPMWakeupCallback, None)
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_PMSUSPEND, myDomainEventPMSuspendCallback, None)
+ vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE, myDomainEventBalloonChangeCallback, None)
vc.setKeepAlive(5, 3)