[libvirt] [PATCH v2 1/9] virDomainGetState public API

Daniel P. Berrange berrange at redhat.com
Fri May 13 09:47:04 UTC 2011


On Tue, May 10, 2011 at 03:39:03PM +0200, Jiri Denemark wrote:
> This API is supposed to replace virDomainGetInfo when the only purpose
> of calling it is getting current domain status.
> ---
> Notes:
>     Version 2:
>     - rebased
>     - unsigned int flags parameter
>     - updated version info in public.syms
> 
>  include/libvirt/libvirt.h.in    |   56 +++++++++++++++++++++++++++++++++++++++
>  python/generator.py             |    1 +
>  python/libvirt-override-api.xml |    6 ++++
>  python/libvirt-override.c       |   30 +++++++++++++++++++++
>  src/libvirt_public.syms         |    5 +++
>  5 files changed, 98 insertions(+), 0 deletions(-)
> 
> diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
> index 5783303..ee636c5 100644
> --- a/include/libvirt/libvirt.h.in
> +++ b/include/libvirt/libvirt.h.in
> @@ -89,6 +89,58 @@ typedef enum {
>       VIR_DOMAIN_CRASHED = 6  /* the domain is crashed */
>  } virDomainState;
>  
> +typedef enum {
> +    VIR_DOMAIN_NOSTATE_UNKNOWN = 0,
> +} virDomainNostateReason;
> +
> +typedef enum {
> +    VIR_DOMAIN_RUNNING_UNKNOWN = 0,
> +    VIR_DOMAIN_RUNNING_BOOTED = 1,          /* normal startup from boot */
> +    VIR_DOMAIN_RUNNING_MIGRATED = 2,        /* migrated from another host */
> +    VIR_DOMAIN_RUNNING_RESTORED = 3,        /* restored from a state file */
> +    VIR_DOMAIN_RUNNING_FROM_SNAPSHOT = 4,   /* restored from snapshot */
> +    VIR_DOMAIN_RUNNING_UNPAUSED = 5,        /* returned from paused state */
> +    VIR_DOMAIN_RUNNING_MIGRATION_CANCELED = 6,  /* returned from migration */
> +    VIR_DOMAIN_RUNNING_SAVE_CANCELED = 7,   /* returned from failed save process */
> +} virDomainRunningReason;
> +
> +typedef enum {
> +    VIR_DOMAIN_BLOCKED_UNKNOWN = 0,     /* the reason is unknown */
> +} virDomainBlockedReason;
> +
> +typedef enum {
> +    VIR_DOMAIN_PAUSED_UNKNOWN = 0,      /* the reason is unknown */
> +    VIR_DOMAIN_PAUSED_USER = 1,         /* paused on user request */
> +    VIR_DOMAIN_PAUSED_MIGRATION = 2,    /* paused for offline migration */
> +    VIR_DOMAIN_PAUSED_SAVE = 3,         /* paused for save */
> +    VIR_DOMAIN_PAUSED_DUMP = 4,         /* paused for offline core dump */
> +    VIR_DOMAIN_PAUSED_IOERROR = 5,      /* paused due to a disk I/O error */
> +    VIR_DOMAIN_PAUSED_WATCHDOG = 6,     /* paused due to a watchdog event */
> +    VIR_DOMAIN_PAUSED_FROM_SNAPSHOT = 7, /* restored from a snapshot which was
> +                                          * taken while domain was paused */
> +} virDomainPausedReason;
> +
> +typedef enum {
> +    VIR_DOMAIN_SHUTDOWN_UNKNOWN = 0,    /* the reason is unknown */
> +    VIR_DOMAIN_SHUTDOWN_USER = 1,       /* shutting down on user request */
> +} virDomainShutdownReason;
> +
> +typedef enum {
> +    VIR_DOMAIN_SHUTOFF_UNKNOWN = 0,     /* the reason is unknown */
> +    VIR_DOMAIN_SHUTOFF_SHUTDOWN = 1,    /* normal shutdown */
> +    VIR_DOMAIN_SHUTOFF_DESTROYED = 2,   /* forced poweroff */
> +    VIR_DOMAIN_SHUTOFF_CRASHED = 3,     /* domain crashed */
> +    VIR_DOMAIN_SHUTOFF_MIGRATED = 4,    /* migrated to another host */
> +    VIR_DOMAIN_SHUTOFF_SAVED = 5,       /* saved to a file */
> +    VIR_DOMAIN_SHUTOFF_FAILED = 6,      /* domain failed to start */
> +    VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT = 7, /* restored from a snapshot which was
> +                                           * taken while domain was shutoff */
> +} virDomainShutoffReason;
> +
> +typedef enum {
> +    VIR_DOMAIN_CRASHED_UNKNOWN = 0,     /* crashed for unknown reason */
> +} virDomainCrashedReason;
> +
>  /**
>   * virDomainInfoPtr:
>   *
> @@ -674,6 +726,10 @@ int                     virDomainCoreDump       (virDomainPtr domain,
>   */
>  int                     virDomainGetInfo        (virDomainPtr domain,
>                                                   virDomainInfoPtr info);
> +int                     virDomainGetState       (virDomainPtr domain,
> +                                                 int *state,
> +                                                 int *reason,
> +                                                 unsigned int flags);
>  
>  /*
>   * Return scheduler type in effect 'sedf', 'credit', 'linux'
> diff --git a/python/generator.py b/python/generator.py
> index 4fa4f65..b395caf 100755
> --- a/python/generator.py
> +++ b/python/generator.py
> @@ -293,6 +293,7 @@ skip_impl = (
>      'virConnGetLastError',
>      'virGetLastError',
>      'virDomainGetInfo',
> +    'virDomainGetState',
>      'virDomainGetBlockInfo',
>      'virDomainGetJobInfo',
>      'virNodeGetInfo',
> diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
> index 54deeb5..ec08e69 100644
> --- a/python/libvirt-override-api.xml
> +++ b/python/libvirt-override-api.xml
> @@ -48,6 +48,12 @@
>        <return type='int *' info='the list of information or None in case of error'/>
>        <arg name='domain' type='virDomainPtr' info='a domain object'/>
>      </function>
> +    <function name='virDomainGetState' file='python'>
> +      <info>Extract domain state.</info>
> +      <return type='int *' info='the list containing state and reason or None in case of error'/>
> +      <arg name='domain' type='virDomainPtr' info='a domain object'/>
> +      <arg name='flags' type='unsigned int' info='additional flags'/>
> +    </function>
>      <function name='virDomainGetBlockInfo' file='python'>
>        <info>Extract information about a domain block device size</info>
>        <return type='int *' info='the list of information or None in case of error'/>
> diff --git a/python/libvirt-override.c b/python/libvirt-override.c
> index 4a9b432..11e1d0c 100644
> --- a/python/libvirt-override.c
> +++ b/python/libvirt-override.c
> @@ -1068,6 +1068,35 @@ libvirt_virDomainGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
>  }
>  
>  static PyObject *
> +libvirt_virDomainGetState(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
> +{
> +    PyObject *py_retval;
> +    int c_retval;
> +    virDomainPtr domain;
> +    PyObject *pyobj_domain;
> +    int state;
> +    int reason;
> +    unsigned int flags;
> +
> +    if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetState",
> +                          &pyobj_domain, &flags))
> +        return NULL;
> +
> +    domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
> +
> +    LIBVIRT_BEGIN_ALLOW_THREADS;
> +    c_retval = virDomainGetState(domain, &state, &reason, flags);
> +    LIBVIRT_END_ALLOW_THREADS;
> +    if (c_retval < 0)
> +        return VIR_PY_NONE;
> +
> +    py_retval = PyList_New(2);
> +    PyList_SetItem(py_retval, 0, libvirt_intWrap(state));
> +    PyList_SetItem(py_retval, 1, libvirt_intWrap(reason));
> +    return py_retval;
> +}
> +
> +static PyObject *
>  libvirt_virDomainGetBlockInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
>      PyObject *py_retval;
>      int c_retval;
> @@ -3527,6 +3556,7 @@ static PyMethodDef libvirtMethods[] = {
>      {(char *) "virConnectDomainEventRegisterAny", libvirt_virConnectDomainEventRegisterAny, METH_VARARGS, NULL},
>      {(char *) "virConnectDomainEventDeregisterAny", libvirt_virConnectDomainEventDeregisterAny, METH_VARARGS, NULL},
>      {(char *) "virDomainGetInfo", libvirt_virDomainGetInfo, METH_VARARGS, NULL},
> +    {(char *) "virDomainGetState", libvirt_virDomainGetState, METH_VARARGS, NULL},
>      {(char *) "virDomainGetBlockInfo", libvirt_virDomainGetBlockInfo, METH_VARARGS, NULL},
>      {(char *) "virNodeGetInfo", libvirt_virNodeGetInfo, METH_VARARGS, NULL},
>      {(char *) "virDomainGetUUID", libvirt_virDomainGetUUID, METH_VARARGS, NULL},
> diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
> index b4aed41..a11e347 100644
> --- a/src/libvirt_public.syms
> +++ b/src/libvirt_public.syms
> @@ -436,4 +436,9 @@ LIBVIRT_0.9.0 {
>          virStorageVolUpload;
>  } LIBVIRT_0.8.8;
>  
> +LIBVIRT_0.9.2 {
> +    global:
> +        virDomainGetState;
> +} LIBVIRT_0.9.0;
> +
>  # .... define new API here using predicted next version number ....

ACK, but needs a rebase for the InjectNMI command


Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list