aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2010-03-18 15:25:38 +0000
committerDaniel P. Berrange <berrange@redhat.com>2010-03-26 13:52:43 +0000
commit8613273458f3df4ac9fb4eadd0fcd504fe72ced0 (patch)
treeb76e938cbe12a474afe1cf1753b8c4bbf39f829e /examples
parentRename domain lifecycle event message (diff)
downloadlibvirt-8613273458f3df4ac9fb4eadd0fcd504fe72ced0.tar.gz
libvirt-8613273458f3df4ac9fb4eadd0fcd504fe72ced0.tar.bz2
libvirt-8613273458f3df4ac9fb4eadd0fcd504fe72ced0.zip
Add support for an explicit guest reboot event
The reboot event is not a normal lifecycle event, since the virtual machine on the host does not change state. Rather the guest OS is resetting the virtual CPUs. ie, the QEMU process does not restart. Thus, this does not belong in the current lifecycle events callback. This introduces a new event type VIR_DOMAIN_EVENT_ID_REBOOT It takes no parameters, besides the virDomainPtr, so it can use the generic callback signature. * daemon/remote.c: Dispatch reboot events to client * examples/domain-events/events-c/event-test.c: Watch for reboot events * include/libvirt/libvirt.h.in: Define new reboot event ID * src/conf/domain_event.c, src/conf/domain_event.h, src/libvirt_private.syms: Extend API to handle reboot events * src/qemu/qemu_driver.c: Connect to the QEMU monitor event for reboots and emit a libvirt reboot event * src/remote/remote_driver.c: Receive and dispatch reboot events to application * src/remote/remote_protocol.x: Wire protocol definition for reboot events
Diffstat (limited to 'examples')
-rw-r--r--examples/domain-events/events-c/event-test.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/examples/domain-events/events-c/event-test.c b/examples/domain-events/events-c/event-test.c
index ed00fb859..c7da0c0fe 100644
--- a/examples/domain-events/events-c/event-test.c
+++ b/examples/domain-events/events-c/event-test.c
@@ -172,6 +172,16 @@ static int myDomainEventCallback2(virConnectPtr conn ATTRIBUTE_UNUSED,
return 0;
}
+static int myDomainEventRebootCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ void *opaque ATTRIBUTE_UNUSED)
+{
+ printf("%s EVENT: Domain %s(%d) rebooted\n", __func__, virDomainGetName(dom),
+ virDomainGetID(dom));
+
+ return 0;
+}
+
static void myFreeFunc(void *opaque)
{
char *str = opaque;
@@ -289,6 +299,7 @@ int main(int argc, char **argv)
int sts;
int callback1ret = -1;
int callback2ret = -1;
+ int callback3ret = -1;
struct sigaction action_stop = {
.sa_handler = stop
@@ -326,9 +337,15 @@ int main(int argc, char **argv)
VIR_DOMAIN_EVENT_ID_LIFECYCLE,
VIR_DOMAIN_EVENT_CALLBACK(myDomainEventCallback2),
strdup("callback 2"), myFreeFunc);
+ callback3ret = virConnectDomainEventRegisterAny(dconn,
+ NULL,
+ VIR_DOMAIN_EVENT_ID_REBOOT,
+ VIR_DOMAIN_EVENT_CALLBACK(myDomainEventRebootCallback),
+ strdup("callback reboot"), myFreeFunc);
if ((callback1ret != -1) &&
- (callback2ret != -1)) {
+ (callback2ret != -1) &&
+ (callback3ret != -1)) {
while(run) {
struct pollfd pfd = { .fd = h_fd,
.events = h_event,
@@ -366,6 +383,7 @@ int main(int argc, char **argv)
DEBUG0("Deregistering event handlers");
virConnectDomainEventDeregister(dconn, myDomainEventCallback1);
virConnectDomainEventDeregisterAny(dconn, callback2ret);
+ virConnectDomainEventDeregisterAny(dconn, callback3ret);
}