[libvirt] [libvirt-glib] [PATCH 1/4] GVirDomainSnapshot: Add _is_current

Christophe Fergeau cfergeau at redhat.com
Tue Aug 5 10:13:00 UTC 2014


Hey,

On Sat, Aug 02, 2014 at 10:41:46AM +0200, mail at baedert.org wrote:
> From: Timm Bäder <mail at baedert.org>
> 
> Add a way to determine if the given GVirDomainSnapshot is the current
> snapshot of its GVirDomain.
> ---
>  libvirt-gobject/libvirt-gobject-domain-snapshot.c | 29 +++++++++++++++++++++++
>  libvirt-gobject/libvirt-gobject-domain-snapshot.h |  3 +++
>  libvirt-gobject/libvirt-gobject.sym               |  1 +
>  3 files changed, 33 insertions(+)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.c b/libvirt-gobject/libvirt-gobject-domain-snapshot.c
> index 7bb89f1..69b6e5a 100644
> --- a/libvirt-gobject/libvirt-gobject-domain-snapshot.c
> +++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.c
> @@ -235,3 +235,32 @@ gboolean gvir_domain_snapshot_delete (GVirDomainSnapshot *snapshot,
>      }
>      return TRUE;
>  }
> +
> +
> +/**
> + * gvir_domain_snapshot_is_current:
> + * @snapshot: The domain snapshot
> + * @flags: Currently unused, pass 0
> + * @error: (allow-none): Place-holder for error or NULL
> + *
> + * Returns: TRUE if the given snapshot is the current snapshot
> + * of its domain or FALSE if it is not or an error occurs.

Sticking a tri-state value (current, non-current, error) in a boolean
does not seem so good. We could go with an enum instead, but this will
be less convenient to use. So I'm not really sure which way to go :(

> + */
> +gboolean gvir_domain_snapshot_is_current(GVirDomainSnapshot *snapshot,
> +                                         guint flags,
> +                                         GError **error) {
> +    gint status;
> +
> +    g_return_val_if_fail(GVIR_IS_DOMAIN_SNAPSHOT(snapshot), FALSE);
> +    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
> +
> +    status = virDomainSnapshotIsCurrent(snapshot->priv->handle, flags);
> +    if (status == -1) {
> +        gvir_set_error(error, GVIR_DOMAIN_SNAPSHOT_ERROR, 0,
> +                       "Could not determine if `%s' is the current snapshot",
> +                       gvir_domain_snapshot_get_name(snapshot));
> +        return FALSE;
> +    }
> +
> +    return status;
> +}
> diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.h b/libvirt-gobject/libvirt-gobject-domain-snapshot.h
> index b3ebe7f..bf697b3 100644
> --- a/libvirt-gobject/libvirt-gobject-domain-snapshot.h
> +++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.h
> @@ -85,6 +85,9 @@ gboolean gvir_domain_snapshot_delete (GVirDomainSnapshot *snapshot,
>                                        guint flags,
>                                        GError **error);
>  
> +gboolean gvir_domain_snapshot_is_current(GVirDomainSnapshot *snapshot,
> +                                         guint flags,
> +                                         GError **error);
>  G_END_DECLS
>  
>  #endif /* __LIBVIRT_GOBJECT_DOMAIN_SNAPSHOT_H__ */
> diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
> index 6aa8b86..641c4da 100644
> --- a/libvirt-gobject/libvirt-gobject.sym
> +++ b/libvirt-gobject/libvirt-gobject.sym
> @@ -242,6 +242,7 @@ LIBVIRT_GOBJECT_0.1.9 {
>  	gvir_domain_get_snapshots;
>  	gvir_domain_snapshot_delete;
>  	gvir_domain_snapshot_list_flags_get_type;
> +	gvir_domain_snapshot_is_current;

This needs to come in alphabetical order or make syntax-check will fail.
Looks good otherwise.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140805/37804b7b/attachment-0001.sig>


More information about the libvir-list mailing list