[libvirt] [PATCH v4 09/13] Introduce virConnectIsAlive API

Daniel P. Berrange berrange at redhat.com
Mon Nov 7 20:51:26 UTC 2011


On Thu, Oct 27, 2011 at 06:05:45PM +0200, Jiri Denemark wrote:
> This API can be used to check if the socket associated with
> virConnectPtr is still open or it was closed (probably because keepalive
> protocol timed out). If there the connection is local (i.e., no socket
> is associated with the connection, it is trivially always alive.
> ---
> Notes:
>     ACKed
> 
>     Version 4:
>     - no changes
>     
>     Version 3:
>     - no changes
>     
>     Version 2:
>     - new patch
> 
>  include/libvirt/libvirt.h.in |    1 +
>  src/driver.h                 |    3 +++
>  src/libvirt.c                |   36 ++++++++++++++++++++++++++++++++++++
>  src/libvirt_public.syms      |    1 +
>  4 files changed, 41 insertions(+), 0 deletions(-)
> 
> diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
> index 8ce4335..50e5b89 100644
> --- a/include/libvirt/libvirt.h.in
> +++ b/include/libvirt/libvirt.h.in
> @@ -2553,6 +2553,7 @@ int virInterfaceIsActive(virInterfacePtr iface);
>  
>  int virConnectIsEncrypted(virConnectPtr conn);
>  int virConnectIsSecure(virConnectPtr conn);
> +int virConnectIsAlive(virConnectPtr conn);
>  
>  /*
>   * CPU specification API
> diff --git a/src/driver.h b/src/driver.h
> index c1223c1..a23f05b 100644
> --- a/src/driver.h
> +++ b/src/driver.h
> @@ -509,6 +509,8 @@ typedef int
>  typedef int
>      (*virDrvConnectIsSecure)(virConnectPtr conn);
>  typedef int
> +    (*virDrvConnectIsAlive)(virConnectPtr conn);
> +typedef int
>      (*virDrvDomainIsActive)(virDomainPtr dom);
>  typedef int
>      (*virDrvDomainIsPersistent)(virDomainPtr dom);
> @@ -898,6 +900,7 @@ struct _virDriver {
>      virDrvDomainBlockJobSetSpeed domainBlockJobSetSpeed;
>      virDrvDomainBlockPull domainBlockPull;
>      virDrvSetKeepAlive setKeepAlive;
> +    virDrvConnectIsAlive isAlive;
>  };
>  
>  typedef int
> diff --git a/src/libvirt.c b/src/libvirt.c
> index 0c33da1..580b29a 100644
> --- a/src/libvirt.c
> +++ b/src/libvirt.c
> @@ -17021,3 +17021,39 @@ error:
>      virDispatchError(conn);
>      return -1;
>  }
> +
> +/**
> + * virConnectIsAlive:
> + * @conn: pointer to the connection object
> + *
> + * Determine if the connection to the hypervisor is still alive
> + *
> + * A connection will be classed as alive if it is either local, or running
> + * over a channel (TCP or UNIX socket) which is not closed.
> + *
> + * Returns 1 if alive, 0 if dead, -1 on error
> + */
> +int virConnectIsAlive(virConnectPtr conn)
> +{
> +    VIR_DEBUG("conn=%p", conn);
> +
> +    virResetLastError();
> +
> +    if (!VIR_IS_CONNECT(conn)) {
> +        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
> +        virDispatchError(NULL);
> +        return -1;
> +    }
> +    if (conn->driver->isAlive) {
> +        int ret;
> +        ret = conn->driver->isAlive(conn);
> +        if (ret < 0)
> +            goto error;
> +        return ret;
> +    }
> +
> +    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
> +error:
> +    virDispatchError(conn);
> +    return -1;
> +}
> diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
> index 468e28a..f1de89d 100644
> --- a/src/libvirt_public.syms
> +++ b/src/libvirt_public.syms
> @@ -491,6 +491,7 @@ LIBVIRT_0.9.5 {
>  
>  LIBVIRT_0.9.7 {
>      global:
> +        virConnectIsAlive;
>          virConnectSetKeepAlive;
>          virDomainReset;
>          virDomainSnapshotGetParent;

ACK, with update of syms file to 0.9.8 of course


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