diff options
author | Michal Privoznik <mprivozn@redhat.com> | 2011-10-25 15:33:21 +0200 |
---|---|---|
committer | Daniel Veillard <veillard@redhat.com> | 2012-01-06 15:21:09 +0800 |
commit | 6308c47b7b9d2be2c1d9fa3979d0f707ef25df0d (patch) | |
tree | 3d277347e2063cfc747ccb4b50647a3afbaa09c2 | |
parent | bee46866e48265c982165ec9e01b9a781599e6d6 (diff) | |
download | libvirt-python-v6-6308c47b7b9d2be2c1d9fa3979d0f707ef25df0d.tar.gz libvirt-python-v6-6308c47b7b9d2be2c1d9fa3979d0f707ef25df0d.tar.xz libvirt-python-v6-6308c47b7b9d2be2c1d9fa3979d0f707ef25df0d.zip |
startupPolicy: Emit event on disk source dropping
https://bugzilla.redhat.com/show_bug.cgi?id=769853
If a disk source gets dropped because it is not accessible,
mgmt application might want to be informed about this. Therefore
we need to emit an event. The event presented in this patch
is however a bit superset of what written above. The reason is simple:
an intention to be easily expanded, e.g. on 'user ejected disk
in guest' events. Therefore, callback gets source string and disk alias
(which should be unique among a domain) and reason (an integer);
(cherry-picked from commit baf2ff7e9054975becd7d87ef8c67eb817388e80)
-rw-r--r-- | libvirt-override-virConnect.py | 9 | ||||
-rw-r--r-- | libvirt-override.c | 53 |
2 files changed, 62 insertions, 0 deletions
diff --git a/libvirt-override-virConnect.py b/libvirt-override-virConnect.py index 65b5342..b908b32 100644 --- a/libvirt-override-virConnect.py +++ b/libvirt-override-virConnect.py @@ -125,6 +125,15 @@ except AttributeError: pass + def _dispatchDomainEventDiskChangeCallback(self, dom, oldSrcPath, newSrcPath, devAlias, reason, cbData): + """Dispatches event to python user domain diskChange event callbacks + """ + cb = cbData["cb"] + opaque = cbData["opaque"] + + cb(self, virDomain(self, _obj=dom), oldSrcPath, newSrcPath, devAlias, reason, opaque) + return 0; + def domainEventDeregisterAny(self, callbackID): """Removes a Domain Event Callback. De-registering for a domain callback will disable delivery of this event type """ diff --git a/libvirt-override.c b/libvirt-override.c index b5650e2..b5823fe 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -4245,6 +4245,56 @@ libvirt_virConnectDomainEventBlockJobCallback(virConnectPtr conn ATTRIBUTE_UNUSE return ret; } +static int +libvirt_virConnectDomainEventDiskChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED, + virDomainPtr dom, + const char *oldSrcPath, + const char *newSrcPath, + const char *devAlias, + int reason, + void *opaque) +{ + PyObject *pyobj_cbData = (PyObject*)opaque; + PyObject *pyobj_dom; + PyObject *pyobj_ret; + PyObject *pyobj_conn; + PyObject *dictKey; + int ret = -1; + + LIBVIRT_ENSURE_THREAD_STATE; + /* Create a python instance of this virDomainPtr */ + virDomainRef(dom); + + pyobj_dom = libvirt_virDomainPtrWrap(dom); + Py_INCREF(pyobj_cbData); + + dictKey = libvirt_constcharPtrWrap("conn"); + pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey); + Py_DECREF(dictKey); + + /* Call the Callback Dispatcher */ + pyobj_ret = PyObject_CallMethod(pyobj_conn, + (char*)"_dispatchDomainEventDiskChangeCallback", + (char*)"OsssiO", + pyobj_dom, + oldSrcPath, newSrcPath, + devAlias, reason, pyobj_cbData); + + Py_DECREF(pyobj_cbData); + Py_DECREF(pyobj_dom); + + if(!pyobj_ret) { + DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret); + PyErr_Print(); + } else { + Py_DECREF(pyobj_ret); + ret = 0; + } + + LIBVIRT_RELEASE_THREAD_STATE; + return ret; +} + static PyObject * libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) @@ -4302,6 +4352,9 @@ libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self, case VIR_DOMAIN_EVENT_ID_BLOCK_JOB: cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBlockJobCallback); break; + case VIR_DOMAIN_EVENT_ID_DISK_CHANGE: + cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDiskChangeCallback); + break; } if (!cb) { |