Re: [libvirt-glib 2/2] API to save and suspend

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

 



Hey,

On Fri, Dec 23, 2011 at 09:58:23PM +0200, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak@xxxxxxxxx>
> 
> Its just a set of synchronous and asynchronous wrappers around
> virDomainManagedSave.
> ---
>  libvirt-gobject/libvirt-gobject-domain.c |  120 ++++++++++++++++++++++++++++++
>  libvirt-gobject/libvirt-gobject-domain.h |   11 +++
>  libvirt-gobject/libvirt-gobject.sym      |    3 +
>  3 files changed, 134 insertions(+), 0 deletions(-)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
> index e4963ed..8496257 100644
> --- a/libvirt-gobject/libvirt-gobject-domain.c
> +++ b/libvirt-gobject/libvirt-gobject-domain.c
> @@ -708,3 +708,123 @@ gboolean gvir_domain_suspend (GVirDomain *dom,
>  cleanup:
>      return ret;
>  }
> +
> +/**
> + * gvir_domain_saved_suspend:

_saved_suspend is good for me even though it took me a while to get what it
means. Maybe _persistent_suspend would be better? Hopefully this won't turn
into some bikeshedding, but since we are not reusing the libvirt naming,I
feelt it was worth making an alternate suggestion :)

> + * @dom: the domain to save and suspend
> + * @flags: extra flags, currently unused
> + * @err: Place-holder for possible errors
> + *
> + * Just like #gvir_domain_suspend but also saves the state of the domain on disk
> + * and therefore makes it possible to restore the domain to its previous state
> + * even after shutdown/reboot of host machine.
> + *
> + * Returns: TRUE if domain was saved and suspended successfully, FALSE otherwise.
> + */
> +gboolean gvir_domain_saved_suspend (GVirDomain *dom,
> +                                    unsigned int flags,
> +                                    GError **err)
> +{
> +    gboolean ret = FALSE;
> +
> +    g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
> +
> +    if (virDomainManagedSave(dom->priv->handle, flags) < 0) {
> +        gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
> +                               0,
> +                               "Unable to saved and suspend domain");

"to save" (no -d)


> +        goto cleanup;
> +    }
> +
> +    ret = TRUE;
> +cleanup:
> +    return ret;
> +}

Imo, the code would flow more nicely with a return FALSE; in the error
case, return TRUE; otherwise, and no cleanup: and gboolean ret. If you
prefer it that way, that's fine with me.

> +
> +typedef struct {
> +    guint flags;
> +} DomainSavedSuspendData;
> +
> +static void
> +gvir_domain_saved_suspend_helper(GSimpleAsyncResult *res,
> +                                 GObject *object,
> +                                 GCancellable *cancellable G_GNUC_UNUSED)
> +{
> +    GVirDomain *dom = GVIR_DOMAIN(object);
> +    DomainSavedSuspendData *data;
> +    GError *err = NULL;
> +
> +    data = (DomainSavedSuspendData *) g_object_get_data(G_OBJECT(res),
> +                                                      "DomainSavedSuspendData");
> +
> +    if (!gvir_domain_saved_suspend(dom, data->flags, &err)) {
> +        g_simple_async_result_set_from_error(res, err);
> +        g_error_free(err);

There's a g_simple_async_result_take_error

> +    }
> +
> +    g_slice_free (DomainSavedSuspendData, data);
> +}
> +
> +/**
> + * gir_domain_saved_suspend_async:
> + * @dom: the domain to save and suspend
> + * @flags: extra flags, currently unused
> + * @cancellable: (allow-none)(transfer none): cancellation object
> + * @callback: (scope async): completion callback
> + * @user_data: (closure): opaque data for callback
> + *
> + * Asynchronous variant of #gvir_domain_saved_suspend.
> + */
> +void gvir_domain_saved_suspend_async (GVirDomain *dom,
> +                                      unsigned int flags,
> +                                      GCancellable *cancellable,
> +                                      GAsyncReadyCallback callback,
> +                                      gpointer user_data)
> +{
> +    GSimpleAsyncResult *res;
> +    DomainSavedSuspendData *data;
> +
> +    g_return_if_fail(GVIR_IS_DOMAIN(dom));
> +
> +    data = g_new0(DomainSavedSuspendData, 1);

Don't forget to change this to g_slice_new0 as Marc-André and Daniel have
pointed out.
Rest of the patch looks good to me, so ACK from me.

Christophe

> +    data->flags = flags;
> +
> +    res = g_simple_async_result_new(G_OBJECT(dom),
> +                                    callback,
> +                                    user_data,
> +                                    gvir_domain_saved_suspend);
> +    g_object_set_data(G_OBJECT(res), "DomainSavedSuspendData", data);
> +    g_simple_async_result_run_in_thread(res,
> +                                        gvir_domain_saved_suspend_helper,
> +                                        G_PRIORITY_DEFAULT,
> +                                        cancellable);
> +    g_object_unref(res);
> +}
> +
> +/**
> + * gir_domain_saved_suspend_finish:
> + * @dom: the domain to save and suspend
> + * @result: (transfer none): async method result
> + * @err: Place-holder for possible errors
> + *
> + * Finishes the operation started by #gvir_domain_saved_suspend_async.
> + *
> + * Returns: TRUE if domain was saved and suspended successfully, FALSE otherwise.
> + */
> +gboolean gvir_domain_saved_suspend_finish (GVirDomain *dom,
> +                                           GAsyncResult *result,
> +                                           GError **err)
> +{
> +    g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
> +    g_return_val_if_fail(G_IS_ASYNC_RESULT(result), FALSE);
> +
> +    if (G_IS_SIMPLE_ASYNC_RESULT(result)) {
> +        GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(result);
> +        g_warn_if_fail (g_simple_async_result_get_source_tag(simple) ==
> +                        gvir_domain_saved_suspend);
> +        if (g_simple_async_result_propagate_error(simple, err))
> +            return FALSE;
> +    }
> +
> +    return TRUE;
> +}
> diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h
> index a5923f4..96a1560 100644
> --- a/libvirt-gobject/libvirt-gobject-domain.h
> +++ b/libvirt-gobject/libvirt-gobject-domain.h
> @@ -155,6 +155,17 @@ gboolean gvir_domain_open_graphics(GVirDomain *dom,
>  
>  gboolean gvir_domain_suspend (GVirDomain *dom,
>                                GError **err);
> +gboolean gvir_domain_saved_suspend (GVirDomain *dom,
> +                                    unsigned int flags,
> +                                    GError **err);
> +void gvir_domain_saved_suspend_async (GVirDomain *dom,
> +                                      unsigned int flags,
> +                                      GCancellable *cancellable,
> +                                      GAsyncReadyCallback callback,
> +                                      gpointer user_data);
> +gboolean gvir_domain_saved_suspend_finish (GVirDomain *dom,
> +                                           GAsyncResult *result,
> +                                           GError **err);
>  
>  G_END_DECLS
>  
> diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
> index 526098d..c04d67a 100644
> --- a/libvirt-gobject/libvirt-gobject.sym
> +++ b/libvirt-gobject/libvirt-gobject.sym
> @@ -52,6 +52,9 @@ LIBVIRT_GOBJECT_0.0.3 {
>  	gvir_domain_resume;
>  	gvir_domain_stop;
>  	gvir_domain_suspend;
> +	gvir_domain_saved_suspend;
> +	gvir_domain_saved_suspend_async;
> +	gvir_domain_saved_suspend_finish;
>  	gvir_domain_delete;
>  	gvir_domain_open_console;
>  	gvir_domain_open_graphics;
> -- 
> 1.7.7.4
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

Attachment: pgpoMbdWndHyr.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]