[libvirt] [libvirt-glib] [PATCH v4 3/3] GVirDomain: Add async version of _fetch_snapshots

Christophe Fergeau cfergeau at redhat.com
Mon Jul 7 10:55:33 UTC 2014


Hey,

On Mon, Jun 30, 2014 at 07:50:16PM +0200, Timm Bäder wrote:
> ---
>  libvirt-gobject/libvirt-gobject-domain.c | 60 ++++++++++++++++++++++++++++++++
>  libvirt-gobject/libvirt-gobject-domain.h | 10 ++++++
>  libvirt-gobject/libvirt-gobject.sym      |  2 ++
>  3 files changed, 72 insertions(+)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
> index b12a4a0..6b53d25 100644
> --- a/libvirt-gobject/libvirt-gobject-domain.c
> +++ b/libvirt-gobject/libvirt-gobject-domain.c
> @@ -1618,3 +1618,63 @@ GList *gvir_domain_get_snapshots(GVirDomain *dom)
>  
>      return snapshots;
>  }
> +
> +
> +
> +static void _fetch_snapshots_async_thread(GTask *task,
> +                                          gpointer source_object,
> +                                          gpointer task_data,
> +                                          GCancellable *cancellable) {
> +    GError *error = NULL;
> +    gboolean status;
> +
> +    status = gvir_domain_fetch_snapshots(source_object,
> +                                         GPOINTER_TO_UINT(task_data),
> +                                         cancellable,
> +                                         &error);
> +    if (status)
> +        g_task_return_boolean(task, TRUE);
> +    else
> +        g_task_return_error(task, error);
> +}
> +
> +
> +/**
> + *
> + * @dom: The domain
> + * @list_flags: bitwise-OR of #GVirDomainSnapshotListFlags
> + * @cancellable: (allow-none)(transfer-none): cancellation object
> + * @callback: (scope async): completion callback
> + * @user_data: (closure): opaque data for callback
> + */
> +void gvir_domain_fetch_snapshots_async(GVirDomain *dom,
> +                                       guint list_flags,
> +                                       GCancellable *cancellable,
> +                                       GAsyncReadyCallback callback,
> +                                       gpointer user_data) {
> +    GTask *task;
> +
> +    g_return_if_fail(GVIR_IS_DOMAIN(dom));
> +    g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
> +
> +    task = g_task_new(dom, cancellable, callback, user_data);

GTask was introduced in glib 2.36, so configure.ac needs to be updated
to reflect that. glib 2.36 was released in March 2013, and is available
in RHEL7, so using this would be fine with me. Others may want to
disagree though :)

> +    g_task_set_task_data(task, GUINT_TO_POINTER(list_flags), NULL);
> +    g_task_run_in_thread(task, _fetch_snapshots_async_thread);

I'm a bit unclear as how the initial ref obtained through g_task_new()
is handled. Have you checked it's correctly freed after _finish() has
been called and that it's not leaked?

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/20140707/06b44b5a/attachment-0001.sig>


More information about the libvir-list mailing list