diff options
author | 2012-03-23 21:44:50 +0800 | |
---|---|---|
committer | 2012-03-23 23:10:26 +0800 | |
commit | a26a1969c37c865b18294c5717544c1dc90beb3c (patch) | |
tree | ef2b2fc5785ae3e052c128fbc1b630f8c9dda9c2 /examples | |
parent | Implement sysinfo on PowerPC. (diff) | |
download | libvirt-a26a1969c37c865b18294c5717544c1dc90beb3c.tar.gz libvirt-a26a1969c37c865b18294c5717544c1dc90beb3c.tar.bz2 libvirt-a26a1969c37c865b18294c5717544c1dc90beb3c.zip |
Add support for event tray moved of removable disks
This patch introduces a new event type for the QMP event
DEVICE_TRAY_MOVED, which occurs when the tray of a removable
disk is moved (i.e opened or closed):
VIR_DOMAIN_EVENT_ID_TRAY_CHANGE
The event's data includes the device alias and the reason
for tray status' changing, which indicates why the tray
status was changed. Thus the callback definition for the event
is:
enum {
VIR_DOMAIN_EVENT_TRAY_CHANGE_OPEN = 0,
VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE,
\#ifdef VIR_ENUM_SENTINELS
VIR_DOMAIN_EVENT_TRAY_CHANGE_LAST
\#endif
} virDomainEventTrayChangeReason;
typedef void
(*virConnectDomainEventTrayChangeCallback)(virConnectPtr conn,
virDomainPtr dom,
const char *devAlias,
int reason,
void *opaque);
Diffstat (limited to 'examples')
-rw-r--r-- | examples/domain-events/events-c/event-test.c | 26 | ||||
-rw-r--r-- | examples/domain-events/events-python/event-test.py | 4 |
2 files changed, 29 insertions, 1 deletions
diff --git a/examples/domain-events/events-c/event-test.c b/examples/domain-events/events-c/event-test.c index f4938c438..cca9a1a35 100644 --- a/examples/domain-events/events-c/event-test.c +++ b/examples/domain-events/events-c/event-test.c @@ -313,6 +313,22 @@ static int myDomainEventDiskChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED, return 0; } +const char *trayChangeReasonStrings[] = { + "open", + "close", +}; + +static int myDomainEventTrayChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED, + virDomainPtr dom, + const char *devAlias, + int reason, + void *opaque ATTRIBUTE_UNUSED) +{ + printf("%s EVENT: Domain %s(%d) removable disk's tray change devAlias: %s reason: %s\n", + __func__, virDomainGetName(dom), virDomainGetID(dom), + devAlias, trayChangeReasonStrings[reason]); + return 0; +} static void myFreeFunc(void *opaque) { @@ -349,6 +365,7 @@ int main(int argc, char **argv) int callback7ret = -1; int callback8ret = -1; int callback9ret = -1; + int callback10ret = -1; struct sigaction action_stop; memset(&action_stop, 0, sizeof action_stop); @@ -419,6 +436,11 @@ int main(int argc, char **argv) VIR_DOMAIN_EVENT_ID_DISK_CHANGE, VIR_DOMAIN_EVENT_CALLBACK(myDomainEventDiskChangeCallback), strdup("disk change"), myFreeFunc); + callback10ret = virConnectDomainEventRegisterAny(dconn, + NULL, + VIR_DOMAIN_EVENT_ID_TRAY_CHANGE, + VIR_DOMAIN_EVENT_CALLBACK(myDomainEventTrayChangeCallback), + strdup("tray change"), myFreeFunc); if ((callback1ret != -1) && (callback2ret != -1) && @@ -427,7 +449,8 @@ int main(int argc, char **argv) (callback5ret != -1) && (callback6ret != -1) && (callback7ret != -1) && - (callback9ret != -1)) { + (callback9ret != -1) && + (callback10ret != -1)) { if (virConnectSetKeepAlive(dconn, 5, 3) < 0) { virErrorPtr err = virGetLastError(); fprintf(stderr, "Failed to start keepalive protocol: %s\n", @@ -452,6 +475,7 @@ int main(int argc, char **argv) virConnectDomainEventDeregisterAny(dconn, callback6ret); virConnectDomainEventDeregisterAny(dconn, callback7ret); virConnectDomainEventDeregisterAny(dconn, callback9ret); + virConnectDomainEventDeregisterAny(dconn, callback10ret); 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 0c750914e..6e0409d56 100644 --- a/examples/domain-events/events-python/event-test.py +++ b/examples/domain-events/events-python/event-test.py @@ -474,6 +474,9 @@ def myDomainEventGraphicsCallback(conn, dom, phase, localAddr, remoteAddr, authS def myDomainEventDiskChangeCallback(conn, dom, oldSrcPath, newSrcPath, devAlias, reason, opaque): print "myDomainEventDiskChangeCallback: Domain %s(%s) disk change oldSrcPath: %s newSrcPath: %s devAlias: %s reason: %s" % ( dom.name(), dom.ID(), oldSrcPath, newSrcPath, devAlias, reason) +def myDomainEventTrayChangeCallback(conn, dom, devAlias, reason, opaque): + print "myDomainEventTrayChangeCallback: Domain %s(%s) tray change devAlias: %s reason: %s" % ( + dom.name(), dom.ID(), devAlias, reason) def usage(out=sys.stderr): print >>out, "usage: "+os.path.basename(sys.argv[0])+" [-hdl] [uri]" print >>out, " uri will default to qemu:///system" @@ -532,6 +535,7 @@ def main(): vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_WATCHDOG, myDomainEventWatchdogCallback, None) vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_GRAPHICS, myDomainEventGraphicsCallback, None) vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_DISK_CHANGE, myDomainEventDiskChangeCallback, None) + vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_TRAY_CHANGE, myDomainEventTrayChangeCallback, None) vc.setKeepAlive(5, 3) |