[libvirt] [glib PATCH V5] Add bindings for virDomainSave*()

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Fri Jul 13 02:01:47 UTC 2012


I could only see one issue this time that I should have seen before:

On Fri, Jul 13, 2012 at 3:13 AM, Jovanka Gulicoska
<jovanka.gulicoska at gmail.com> wrote:
> ---
>  libvirt-gobject/libvirt-gobject-domain.c |  153 ++++++++++++++++++++++++++++++
>  libvirt-gobject/libvirt-gobject-domain.h |   18 ++++
>  libvirt-gobject/libvirt-gobject.sym      |    3 +
>  3 files changed, 174 insertions(+)
>
> diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
> index 088cd33..5d9cfff 100644
> --- a/libvirt-gobject/libvirt-gobject-domain.c
> +++ b/libvirt-gobject/libvirt-gobject-domain.c
> @@ -557,6 +557,159 @@ gboolean gvir_domain_reboot(GVirDomain *dom,
>  }
>
>  /**
> + * gvir_domain_save_to_file:
> + * @dom: the domain
> + * @filename: path to the output file
> + * @custom_conf: (allow-none): configuration for domain or NULL
> + * @flags: the flags
> + *
> + * Returns: TRUE on success, FALSE otherwise
> + */
> +gboolean gvir_domain_save_to_file(GVirDomain *dom,
> +                                  gchar *filename,
> +                                  GVirConfigDomain *custom_conf,
> +                                  guint flags,
> +                                  GError **err)
> +{
> +    GVirDomainPrivate *priv;
> +    int ret;
> +
> +    g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
> +    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
> +
> +    priv = dom->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 = virDomainSaveFlags(priv->handle, filename, custom_xml, flags);
> +        g_free(custom_xml);
> +    }
> +    else {
> +        ret = virDomainSave(priv->handle, filename);
> +    }
> +
> +    if (ret < 0) {
> +        gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
> +                               0,
> +                               "Unable to save domain to file");
> +        return FALSE;
> +    }
> +
> +    return TRUE;
> +}
> +
> +typedef struct {
> +    gchar *filename;
> +    gchar *custom_xml;
> +    guint flags;
> +} DomainSaveToFileData;
> +
> +static void domain_save_to_file_data_free(DomainSaveToFileData *data)
> +{
> +    g_free(data->filename);
> +    g_free(data->custom_xml);
> +    g_slice_free(DomainSaveToFileData, data);
> +}
> +
> +static void
> +gvir_domain_save_to_file_helper(GSimpleAsyncResult *res,
> +                                GObject *object,
> +                                GCancellable *cancellable G_GNUC_UNUSED)
> +{
> +    GVirDomain *dom = GVIR_DOMAIN(object);
> +    DomainSaveToFileData *data;
> +    GVirConfigDomain *conf;
> +    GError *err = NULL;
> +
> +    data = g_simple_async_result_get_op_res_gpointer(res);
> +    conf = gvir_domain_get_config(dom, data->flags, &err);
> +
> +    if (!gvir_domain_save_to_file(dom, data->filename, conf, data->flags, &err))

I somehow missed this before. You are taking the xml from the passed
custom_conf in gvir_domain_save_to_file_async but you are not passing
it to gvir_domain_save_to_file here but rather getting the existing
config from the domain. You want to keep a ref to the original custom
config object (no need to get xml string out of it) and pass it here
through the DomainSaveToFileData. g_strdup/g_free will have to be
replaced by g_object_ref/unref too.

-- 
Regards,

Zeeshan Ali (Khattak)
FSF member#5124




More information about the libvir-list mailing list