Re: [libvirt-glib] [PATCH v5 1/3] libvirt-gobject-domain: Add _fetch_snapshots

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jul 09, 2014 at 06:23:23PM +0200, Timm Bäder wrote:
> This function can be used to fetch the snapshots of a domain (according
> to the given GVirDomainSnapshotListFlags) and save them in a
> domain-internal GHashTable. A function to access them from outside will
> be added in a later patch.
> ---
>  libvirt-gobject/libvirt-gobject-domain.c | 86 ++++++++++++++++++++++++++++++++
>  libvirt-gobject/libvirt-gobject-domain.h | 37 ++++++++++++++
>  libvirt-gobject/libvirt-gobject.sym      |  2 +
>  3 files changed, 125 insertions(+)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
> index c6e30e5..adb5179 100644
> --- a/libvirt-gobject/libvirt-gobject-domain.c
> +++ b/libvirt-gobject/libvirt-gobject-domain.c
> @@ -38,6 +38,8 @@ struct _GVirDomainPrivate
>  {
>      virDomainPtr handle;
>      gchar uuid[VIR_UUID_STRING_BUFLEN];
> +    GHashTable *snapshots;
> +    GMutex *lock;
>  };
>  
>  G_DEFINE_TYPE(GVirDomain, gvir_domain, G_TYPE_OBJECT);
> @@ -121,6 +123,11 @@ static void gvir_domain_finalize(GObject *object)
>  
>      g_debug("Finalize GVirDomain=%p", domain);
>  
> +    if (priv->snapshots) {
> +        g_hash_table_unref(priv->snapshots);
> +    }
> +    g_mutex_free(priv->lock);
> +
>      virDomainFree(priv->handle);
>  
>      G_OBJECT_CLASS(gvir_domain_parent_class)->finalize(object);
> @@ -237,6 +244,7 @@ static void gvir_domain_init(GVirDomain *domain)
>      g_debug("Init GVirDomain=%p", domain);
>  
>      domain->priv = GVIR_DOMAIN_GET_PRIVATE(domain);
> +    domain->priv->lock = g_mutex_new();
>  }
>  
>  typedef struct virDomain GVirDomainHandle;
> @@ -1514,3 +1522,81 @@ gvir_domain_create_snapshot(GVirDomain *dom,
>      g_free(custom_xml);
>      return dom_snapshot;
>  }
> +
> +
> +
> +/**
> + * gvir_domain_fetch_snapshots:
> + * @dom: The domain
> + * @list_flags: bitwise-OR of #GVirDomainSnapshotListFlags
> + * @cancellable: (allow-none)(transfer-none): cancellation object
> + * @error: (allow-none): Place-holder for error or NULL
> + *
> + * Returns: TRUE on success, FALSE otherwise.
> + */
> +gboolean gvir_domain_fetch_snapshots(GVirDomain *dom,
> +                                     guint list_flags,
> +                                     GCancellable *cancellable,
> +                                     GError **error)
> +{
> +    GVirDomainPrivate *priv;
> +    virDomainSnapshotPtr *snapshots = NULL;
> +    GVirDomainSnapshot *snap;
> +    GHashTable *snap_table;
> +    int n_snaps = 0;
> +    int i;
> +    gboolean ret = TRUE;

Small nit, in such situations, I tend to set the return value to FALSE
(ie the error value), and only explicitly set it to TRUE when the
operation is successful, this way it's harder to mistakenly report
success instead of failure to the caller. This is what
gvir_connection_fetch_pools and gvir_connection_fetch_domains do.

Christophe

Attachment: pgpSYWOOgIuMe.pgp
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]