mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
examples: Handle VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED event
This commit is contained in:
parent
4421e257dd
commit
ee023f6c1f
@ -428,6 +428,17 @@ static int myDomainEventPMSuspendDiskCallback(virConnectPtr conn ATTRIBUTE_UNUSE
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
myDomainEventDeviceRemovedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
virDomainPtr dom,
|
||||
const char *devAlias,
|
||||
void *opaque ATTRIBUTE_UNUSED)
|
||||
{
|
||||
printf("%s EVENT: Domain %s(%d) device removed: %s\n",
|
||||
__func__, virDomainGetName(dom), virDomainGetID(dom), devAlias);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void myFreeFunc(void *opaque)
|
||||
{
|
||||
char *str = opaque;
|
||||
@ -467,6 +478,7 @@ int main(int argc, char **argv)
|
||||
int callback12ret = -1;
|
||||
int callback13ret = -1;
|
||||
int callback14ret = -1;
|
||||
int callback15ret = -1;
|
||||
struct sigaction action_stop;
|
||||
|
||||
memset(&action_stop, 0, sizeof(action_stop));
|
||||
@ -575,6 +587,12 @@ int main(int argc, char **argv)
|
||||
VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK,
|
||||
VIR_DOMAIN_EVENT_CALLBACK(myDomainEventPMSuspendDiskCallback),
|
||||
strdup("pmsuspend-disk"), myFreeFunc);
|
||||
callback15ret = virConnectDomainEventRegisterAny(dconn,
|
||||
NULL,
|
||||
VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED,
|
||||
VIR_DOMAIN_EVENT_CALLBACK(myDomainEventDeviceRemovedCallback),
|
||||
strdup("device removed"), myFreeFunc);
|
||||
|
||||
if ((callback1ret != -1) &&
|
||||
(callback2ret != -1) &&
|
||||
(callback3ret != -1) &&
|
||||
@ -587,7 +605,8 @@ int main(int argc, char **argv)
|
||||
(callback11ret != -1) &&
|
||||
(callback12ret != -1) &&
|
||||
(callback13ret != -1) &&
|
||||
(callback14ret != -1)) {
|
||||
(callback14ret != -1) &&
|
||||
(callback15ret != -1)) {
|
||||
if (virConnectSetKeepAlive(dconn, 5, 3) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
fprintf(stderr, "Failed to start keepalive protocol: %s\n",
|
||||
@ -616,6 +635,8 @@ int main(int argc, char **argv)
|
||||
virConnectDomainEventDeregisterAny(dconn, callback11ret);
|
||||
virConnectDomainEventDeregisterAny(dconn, callback12ret);
|
||||
virConnectDomainEventDeregisterAny(dconn, callback13ret);
|
||||
virConnectDomainEventDeregisterAny(dconn, callback14ret);
|
||||
virConnectDomainEventDeregisterAny(dconn, callback15ret);
|
||||
if (callback8ret != -1)
|
||||
virConnectDomainEventDeregisterAny(dconn, callback8ret);
|
||||
}
|
||||
|
@ -495,6 +495,9 @@ def myDomainEventBalloonChangeCallback(conn, dom, actual, opaque):
|
||||
def myDomainEventPMSuspendDiskCallback(conn, dom, reason, opaque):
|
||||
print "myDomainEventPMSuspendDiskCallback: Domain %s(%s) system pmsuspend_disk" % (
|
||||
dom.name(), dom.ID())
|
||||
def myDomainEventDeviceRemovedCallback(conn, dom, dev, opaque):
|
||||
print "myDomainEventDeviceRemovedCallback: Domain %s(%s) device removed: %s" % (
|
||||
dom.name(), dom.ID(), dev)
|
||||
|
||||
run = True
|
||||
|
||||
@ -570,6 +573,7 @@ def main():
|
||||
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_PMSUSPEND, myDomainEventPMSuspendCallback, None)
|
||||
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE, myDomainEventBalloonChangeCallback, None)
|
||||
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK, myDomainEventPMSuspendDiskCallback, None)
|
||||
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED, myDomainEventDeviceRemovedCallback, None)
|
||||
|
||||
vc.setKeepAlive(5, 3)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user