[libvirt] [glib PATCH V4] Add bindings for virDomainRestore*()

Christophe Fergeau cfergeau at redhat.com
Mon Jul 30 10:19:50 UTC 2012


Hey,

This mostly looks good, but I had a few comments nonetheless..


On Sun, Jul 29, 2012 at 06:06:36PM +0200, Jovanka Gulicoska wrote:
> ---
>  libvirt-gobject/libvirt-gobject-connection.c |  164 ++++++++++++++++++++++++++
>  libvirt-gobject/libvirt-gobject-connection.h |   20 ++++
>  libvirt-gobject/libvirt-gobject.sym          |    3 +
>  3 files changed, 187 insertions(+)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
> index 3a99034..b4a7af4 100644
> --- a/libvirt-gobject/libvirt-gobject-connection.c
> +++ b/libvirt-gobject/libvirt-gobject-connection.c
> @@ -1605,3 +1605,167 @@ gvir_connection_get_capabilities_finish(GVirConnection *conn,
>  
>      return g_object_ref(caps);
>  }
> +
> +/**
> + * gvir_connection_restore_domain_from_file:
> + * @conn: a #GVirConnection
> + * @filename: path to input file
> + * @custom_conf: (allow-none): configuration for domain or NULL
> + * @flags: the flags
> + *
> + * Returns: TRUE on success, FALSE otherwise
> + *
> + * Restores the domain saved with #gvir_domain_save_to_file
> + */
> +gboolean gvir_connection_restore_domain_from_file(GVirConnection *conn,
> +                                                  gchar *filename,
> +                                                  GVirConfigDomain *custom_conf,
> +                                                  guint flags,
> +                                                  GError **err)
> +{
> +    GVirConnectionPrivate *priv;
> +    int ret;
> +
> +    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
> +    g_return_val_if_fail((filename != NULL), FALSE);
> +    g_return_val_if_fail((err == NULL) || (*err == NULL), FALSE);
> +
> +    priv = conn->priv;
> +
> +    if (flags || (custom_conf != NULL)) {
> +        gchar *custom_xml = NULL;
> +
> +       if (custom_conf != NULL)
> +           custom_xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(custom_conf));
> +
> +       ret = virDomainRestoreFlags(priv->conn, filename, custom_xml, flags);
> +       g_free (custom_xml);
> +    }
> +    else {
> +       ret = virDomainRestore(priv->conn, filename);
> +    }
> +
> +    if (ret < 0) {
> +        gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
> +                              0,
> +                              "Unable to restore domain");
> +
> +       return FALSE;
> +    }
> +
> +    return TRUE;
> +}
> +
> +typedef struct {
> +    gchar *filename;
> +    GVirConfigDomain *custom_conf;
> +    guint flags;
> +} DomainRestoreFromFileData;
> +
> +static void restore_domain_from_file_data_free(DomainRestoreFromFileData *data)
> +{
> +    g_free(data->filename);
> +    if (custom_conf != NULL)

This should be data->custom_conf

> +        g_object_unref(data->custom_conf);
> +    g_slice_free(DomainRestoreFromFileData, data);
> +}
> +
> +
> +static void
> +gvir_connection_restore_domain_from_file_helper
> +                               (GSimpleAsyncResult *res,
> +                                GObject *object,
> +                                GCancellable *cancellable G_GNUC_UNUSED)
> +{
> +    GVirConnection *conn = GVIR_CONNECTION(object);
> +    DomainRestoreFromFileData *data;
> +    GError *err = NULL;
> +
> +    data = g_simple_async_result_get_op_res_gpointer(res);
> +
> +    if (!gvir_connection_restore_domain_from_file(conn, data->filename,
> +                                                  data->custom_conf,
> +                                                  data->flags, &err))
> +       g_simple_async_result_take_error(res, err);
> +}
> +
> +/**
> + * gvir_connection_restore_domain_from_file_async:
> + * @conn: a #GVirConnection
> + * @filename: path to input file
> + * @custom_conf: (allow-none): configuration for domain
> + * @flags: the flags
> + * @cancellable: (allow-none) (transfer none):cancallation object

cancellation object (instead of 'cancallation')

> + * @callback: (scope async): completion callback
> + * @user_data: (closure): opaque data for callback
> + *
> + * Asynchronous variant of #gvir_connection_restore_domain_from_file
> + */
> +void
> +gvir_connection_restore_domain_from_file_async(GVirConnection *conn,
> +                                               gchar *filename,
> +                                               GVirConfigDomain *custom_conf,
> +                                               guint flags,
> +                                               GCancellable *cancellable,
> +                                               GAsyncReadyCallback callback,
> +                                               gpointer user_data)
> +{
> +    GSimpleAsyncResult *res;
> +    DomainRestoreFromFileData *data;
> +
> +    g_return_if_fail(GVIR_IS_CONNECTION(conn));
> +    g_return_if_fail(filename != NULL);
> +    g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
> +
> +    data = g_slice_new0(DomainRestoreFromFileData);
> +    data->filename = g_strdup(filename);
> +    if (custom_conf != NULL)
> +        data->custom_conf = g_object_ref(custom_conf);
> +    data->flags = flags;
> +
> +    res = g_simple_async_result_new
> +                         (G_OBJECT(conn),
> +                          callback,
> +                          user_data,
> +                          gvir_connection_restore_domain_from_file_async);
> +    g_simple_async_result_set_op_res_gpointer
> +                          (res,
> +                           data,
> +                           (GDestroyNotify)restore_domain_from_file_data_free);
> +
> +    g_simple_async_result_run_in_thread
> +                          (res,
> +                           gvir_connection_restore_domain_from_file_helper,
> +                           G_PRIORITY_DEFAULT,
> +                           cancellable);
> +
> +    g_object_unref(res);
> +}
> +
> +/**
> + * gvir_connection_restore_domain_from_file_finish:
> + * @conn: a #GVirConnection
> + * @result: (transfer none): async method result
> + * @err: Place-holder for possible errors
> + *
> + * Finishes the operation started by #gvir_restore_domain_from_file_async.
> + *
> + * Returns: TRUE if domain was restored successfully, FALSE otherwise.
> + */
> +gboolean
> +gvir_connection_restore_domain_from_file_finish(GVirConnection *conn,
> +                                                GAsyncResult *result,
> +                                                GError **err)
> +{
> +    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
> +    g_return_val_if_fail(g_simple_async_result_is_valid
> +                           (result, G_OBJECT(conn),
> +                            gvir_connection_restore_domain_from_file_async),
> +                            FALSE);
> +
> +     if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
> +                                               err))
> +         return FALSE;
> +
> +    return TRUE;
> +}
> diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h
> index c80eecf..d658b01 100644
> --- a/libvirt-gobject/libvirt-gobject-connection.h
> +++ b/libvirt-gobject/libvirt-gobject-connection.h
> @@ -202,6 +202,26 @@ gvir_connection_get_capabilities_finish(GVirConnection *conn,
>                                          GAsyncResult *result,
>                                          GError **err);
>  
> +gboolean
> +gvir_connection_restore_domain_from_file(GVirConnection *conn,
> +                                         gchar *filename,
> +                                         GVirConfigDomain *custom_conf,
> +                                         guint flags,
> +                                         GError **err);
> +
> +void
> +gvir_connection_restore_domain_from_file_async(GVirConnection *conn,
> +                                               gchar *filename,
> +                                               GVirConfigDomain *custom_conf,
> +                                               guint flags,
> +                                               GCancellable *cancellable,
> +                                               GAsyncReadyCallback callback,
> +                                               gpointer user_data);
> +
> +gboolean
> +gvir_connection_restore_domain_from_file_finish(GVirConnection *conn,
> +                                                GAsyncResult *result,
> +                                                GError **err);
>  G_END_DECLS
>  
>  #endif /* __LIBVIRT_GOBJECT_CONNECTION_H__ */
> diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
> index 54a093a..42c90ef 100644
> --- a/libvirt-gobject/libvirt-gobject.sym
> +++ b/libvirt-gobject/libvirt-gobject.sym
> @@ -31,6 +31,9 @@ LIBVIRT_GOBJECT_0.0.8 {
>  	gvir_connection_create_storage_pool;
>  	gvir_connection_start_domain;
>  	gvir_connection_get_node_info;
> +	gvir_connection_restore_domain_from_file;
> +	gvir_connection_restore_domain_from_file_async;
> +	gvir_connection_restore_domain_from_file_finish;
>  
>  	gvir_domain_device_get_type;
>  	gvir_domain_device_get_domain;

The new symbols should go in a newer section at the end of the file:
LIBVIRT_GOBJECT_0.1.1 {
  global:
+	gvir_connection_restore_domain_from_file;
+	gvir_connection_restore_domain_from_file_async;
+	gvir_connection_restore_domain_from_file_finish;
+
        gvir_domain_shutdown_flags_get_type;
        gvir_domain_xml_flags_get_type;

} LIBVIRT_GOBJECT_0.0.9;

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


More information about the libvir-list mailing list