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

Re: [libvirt] [libvirt-glib] [PATCH 3/4] GVirDomain: Add async version of _create_snapshot



On Fri, Aug 15, 2014 at 12:05:46PM +0200, Timm Bäder wrote:
> ---
>  libvirt-gobject/libvirt-gobject-domain.c | 67 ++++++++++++++++++++++++++++++++
>  libvirt-gobject/libvirt-gobject-domain.h | 11 ++++++
>  libvirt-gobject/libvirt-gobject.sym      |  2 +
>  3 files changed, 80 insertions(+)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
> index aa2a170..29b82d0 100644
> --- a/libvirt-gobject/libvirt-gobject-domain.c
> +++ b/libvirt-gobject/libvirt-gobject-domain.c
> @@ -61,6 +61,11 @@ enum {
>      LAST_SIGNAL
>  };
>  
> +typedef struct {
> +    guint create_flags;
> +    GVirConfigDomainSnapshot *snapshot_config;
> +} SnapshotCreateData;
> +
>  static gint signals[LAST_SIGNAL];
>  
>  #define GVIR_DOMAIN_ERROR gvir_domain_error_quark()
> @@ -1524,6 +1529,68 @@ gvir_domain_create_snapshot(GVirDomain *dom,
>  }
>  
>  
> +static void _create_snapshot_async_thread(GTask *task,
> +                                          gpointer source_object,
> +                                          gpointer task_data,
> +                                          GCancellable *cancellable) {
> +    GError *error = NULL;
> +    GVirDomainSnapshot *snapshot;
> +    SnapshotCreateData *create_data = task_data;
> +
> +    snapshot = gvir_domain_create_snapshot(source_object,
> +                                           create_data->snapshot_config,
> +                                           create_data->create_flags,
> +                                           &error);
> +    if (snapshot)
> +      g_task_return_pointer(task, snapshot, g_object_unref);
> +    else
> +      g_task_return_error(task, error);
> +}
> +
> +/**
> + * gvir_domain_create_snapshot_async:
> + * @dom: The #GVirDomain
> + * @custom_conf: (allow-none): Configuration of snapshot or %NULL
> + * @flags: Bitwise-OR of #GVirDomainSnapshotCreateFlags
> + * @callback: (scope async): Complection callback
> + * @user_data: (closure): Opaque data for callback
> + */
> +void gvir_domain_create_snapshot_async(GVirDomain *dom,
> +                                       GVirConfigDomainSnapshot *custom_conf,
> +                                       guint flags,
> +                                       GAsyncReadyCallback callback,
> +                                       gpointer user_data) {

No GCancellable either?

> +    SnapshotCreateData *create_data;
> +    GTask *task;
> +
> +    g_return_if_fail(GVIR_IS_DOMAIN(dom));
> +    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(custom_conf));
> +
> +    create_data = g_slice_new(SnapshotCreateData);
> +    create_data->create_flags = flags;
> +    create_data->snapshot_config = custom_conf;

I'd take a ref on snapshot_config as we don't really know what the
caller will do with it once we return from this method.

> +
> +    task = g_task_new(dom, NULL, callback, user_data);
> +    g_task_set_task_data(task, create_data, NULL);

You need to have pass a GDestroyNotify argument as you allocated
create_data in this function.

Christophe

Attachment: pgpABADbINVFx.pgp
Description: PGP signature


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