[libvirt] [python PATCH 1/2] qemu: support arbitrary monitor events

Michal Privoznik mprivozn at redhat.com
Fri Mar 21 16:22:41 UTC 2014


On 05.02.2014 03:01, Eric Blake wrote:
> Wrap the new virConnectDomainQemuMonitorEventRegister function
> being added in libvirt 1.2.2.  This patch copies heavily from
> network events (commit 6ea5be0) and from event loop callbacks
> in libvirt-override.c, since in the libvirt_qemu module, we
> must expose top-level functions rather than class members.
>
> * generator.py (qemu_skip_function): Don't generate event code.
> (qemuBuildWrappers): Delay manual portion until after imports.
> * libvirt-qemu-override.py (qemuMonitorEventRegister)
> (qemuMonitorEventDeregister): New file.
> * libvirt-qemu-override.c
> (libvirt_qemu_virConnectDomainQemuMonitorEventFreeFunc)
> (libvirt_qemu_virConnectDomainQemuMonitorEventCallback)
> (libvirt_qemu_virConnectDomainQemuMonitorEventRegister)
> (libvirt_qemu_virConnectDomainQemuMonitorEventDeregister)
> (libvirt_qemu_lookupPythonFunc, getLibvirtQemuDictObject)
> (getLibvirtQemuModuleObject): New functions.
>
> Signed-off-by: Eric Blake <eblake at redhat.com>
> ---
>   generator.py             |  20 +++--
>   libvirt-qemu-override.c  | 221 ++++++++++++++++++++++++++++++++++++++++++++++-
>   libvirt-qemu-override.py |  36 ++++++++
>   3 files changed, 268 insertions(+), 9 deletions(-)
>   create mode 100644 libvirt-qemu-override.py
>

> diff --git a/libvirt-qemu-override.c b/libvirt-qemu-override.c
> index 480a7d3..0abcd3f 100644
> --- a/libvirt-qemu-override.c
> +++ b/libvirt-qemu-override.c

> @@ -122,6 +192,151 @@ libvirt_qemu_virDomainQemuAgentCommand(PyObject *self ATTRIBUTE_UNUSED, PyObject
>   }
>   #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
>
> +
> +#if LIBVIR_CHECK_VERSION(1, 2, 2)
> +static void
> +libvirt_qemu_virConnectDomainQemuMonitorEventFreeFunc(void *opaque)
> +{
> +    PyObject *pyobj_conn = (PyObject*)opaque;
> +    LIBVIRT_ENSURE_THREAD_STATE;
> +    Py_DECREF(pyobj_conn);
> +    LIBVIRT_RELEASE_THREAD_STATE;
> +}
> +
> +static void
> +libvirt_qemu_virConnectDomainQemuMonitorEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
> +                                                      virDomainPtr dom,
> +                                                      const char *event,
> +                                                      long long seconds,
> +                                                      unsigned int micros,
> +                                                      const char *details,
> +                                                      void *opaque)
> +{
> +    PyObject *pyobj_cbData = (PyObject*)opaque;
> +    PyObject *pyobj_dom;
> +    PyObject *pyobj_ret;
> +    PyObject *pyobj_conn;
> +    PyObject *dictKey;
> +    PyObject *pyobj_cb;
> +
> +    LIBVIRT_ENSURE_THREAD_STATE;
> +
> +    pyobj_cb = libvirt_qemu_lookupPythonFunc("_dispatchQemuMonitorEventCallback");
> +    if (!pyobj_cb) {
> +        goto cleanup;
> +    }
> +
> +    dictKey = libvirt_constcharPtrWrap("conn");
> +    if (!dictKey)
> +        return;
> +    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
> +    Py_DECREF(dictKey);
> +
> +    /* Create a python instance of this virDomainPtr */
> +    virDomainRef(dom);

1: ^^^

> +    pyobj_dom = libvirt_virDomainPtrWrap(dom);
> +    Py_INCREF(pyobj_cbData);
> +
> +    /* Call the Callback Dispatcher */
> +    pyobj_ret = PyObject_CallFunction(pyobj_cb,
> +                                      (char *)"OOsLIsO",
> +                                      pyobj_conn, pyobj_dom, event, seconds,
> +                                      micros, details, pyobj_cbData);
> +
> +    Py_DECREF(pyobj_cbData);
> +    Py_DECREF(pyobj_dom);

I'd expect counterpart of [1] here.

> +
> +    if (!pyobj_ret) {
> +        DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
> +        PyErr_Print();
> +    } else {
> +        Py_DECREF(pyobj_ret);
> +    }
> +
> +cleanup:
> +    LIBVIRT_RELEASE_THREAD_STATE;
> +}
> +
> +

Besides that, the code looks okay. ACK.

Michal




More information about the libvir-list mailing list