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

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



---
 libvirt-gobject/libvirt-gobject-connection.c |  137 ++++++++++++++++++++++++++
 libvirt-gobject/libvirt-gobject-connection.h |   20 ++++
 libvirt-gobject/libvirt-gobject-domain.c     |   22 ++---
 libvirt-gobject/libvirt-gobject-domain.h     |   10 ++
 libvirt-gobject/libvirt-gobject.sym          |    4 +
 5 files changed, 180 insertions(+), 13 deletions(-)

diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
index 3a99034..5f21c11 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -1605,3 +1605,140 @@ gvir_connection_get_capabilities_finish(GVirConnection *conn,
 
     return g_object_ref(caps);
 }
+
+/**
+ * gvir_connection_domain_restore:
+ * @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
+ */
+gboolean gvir_connection_domain_restore(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((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;
+}
+
+static void
+gvir_connection_domain_restore_helper(GSimpleAsyncResult *res,
+                                      GObject *object,
+                                      GCancellable *cancellable G_GNUC_UNUSED)
+{
+    GVirConnection *conn = GVIR_CONNECTION(object);
+    GVirDomainRestoreFromFileData *data;
+    GError *err = NULL;
+
+    data = g_simple_async_result_get_op_res_gpointer(res);
+
+    if (!gvir_connection_domain_restore(conn, data->filename, data->custom_conf,
+                                        data->flags, &err))
+        g_simple_async_result_take_error(res, err);
+}
+
+/**
+ * gvir_connection_domain_restore_async:
+ * @conn: a #GVirConnection
+ * @filename: path to input file
+ * @custom_conf: (allow-none): configuration for domain or NULL
+ * @flags: the flags
+ * @cancellable: (allow-none) (transfer none): cancallation object
+ * @callback: (scope async): completion callback
+ * @user_data: (closure): opaque data for callback
+ *
+ * Asynchronous variant of #gvir_connection_domain_restore
+ */
+void gvir_connection_domain_restore_async(GVirConnection *conn,
+                                          gchar *filename,
+                                          GVirConfigDomain *custom_conf,
+                                          guint flags,
+                                          GCancellable *cancellable,
+                                          GAsyncReadyCallback callback,
+                                          gpointer user_data)
+{
+    GSimpleAsyncResult *res;
+    GVirDomainRestoreFromFileData *data;
+
+    g_return_if_fail(GVIR_IS_CONNECTION(conn));
+    g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
+
+    data = g_slice_new0(GVirDomainRestoreFromFileData);
+    data->filename = g_strdup(filename);
+    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_domain_restore_async);
+    g_simple_async_result_set_op_res_gpointer
+                          (res, data,
+                           (GDestroyNotify)gvir_domain_save_to_file_data_free);
+
+    g_simple_async_result_run_in_thread(res,
+                                        gvir_connection_domain_restore_helper,
+                                        G_PRIORITY_DEFAULT,
+                                        cancellable);
+
+    g_object_unref(res);
+}
+
+/**
+ * gvir_connection_domain_finish:
+ * @conn: a #GVirConnection
+ * @result: (transfer none): async method result
+ * @err: Place-holder for possible errors
+ *
+ * Finishes the operation started by #gvir_domain_restore_async.
+ *
+ * Returns: TRUE if domain was restored successfully, FALSE otherwise.
+ */
+gboolean gvir_connection_domain_restore_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_domain_restore_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..5932661 100644
--- a/libvirt-gobject/libvirt-gobject-connection.h
+++ b/libvirt-gobject/libvirt-gobject-connection.h
@@ -38,6 +38,8 @@ G_BEGIN_DECLS
 
 #define GVIR_TYPE_CONNECTION_HANDLE      (gvir_connection_handle_get_type ())
 
+#define GVirDomainRestoreFromFileData GVirDomainSaveToFileData
+
 typedef struct _GVirNodeInfo GVirNodeInfo;
 struct _GVirNodeInfo
 {
@@ -202,6 +204,24 @@ gvir_connection_get_capabilities_finish(GVirConnection *conn,
                                         GAsyncResult *result,
                                         GError **err);
 
+gboolean gvir_connection_domain_restore(GVirConnection *conn,
+                                        gchar *filename,
+                                        GVirConfigDomain *custom_conf,
+                                        guint flags,
+                                        GError **err);
+
+void gvir_connection_domain_restore_async(GVirConnection *conn,
+                                          gchar *filename,
+                                          GVirConfigDomain *custom_conf,
+                                          guint flags,
+                                          GCancellable *cancellable,
+                                          GAsyncReadyCallback callback,
+                                          gpointer user_data);
+
+gboolean gvir_connection_domain_restore_finish(GVirConnection *conn,
+                                               GAsyncResult *result,
+                                               GError **err);
+
 G_END_DECLS
 
 #endif /* __LIBVIRT_GOBJECT_CONNECTION_H__ */
diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
index 308a817..61c153b 100644
--- a/libvirt-gobject/libvirt-gobject-domain.c
+++ b/libvirt-gobject/libvirt-gobject-domain.c
@@ -602,17 +602,11 @@ gboolean gvir_domain_save_to_file(GVirDomain *dom,
     return TRUE;
 }
 
-typedef struct {
-    gchar *filename;
-    GVirConfigDomain *custom_conf;
-    guint flags;
-} DomainSaveToFileData;
-
-static void domain_save_to_file_data_free(DomainSaveToFileData *data)
+void gvir_domain_save_to_file_data_free(GVirDomainSaveToFileData *data)
 {
     g_free(data->filename);
     g_object_unref(data->custom_conf);
-    g_slice_free(DomainSaveToFileData, data);
+    g_slice_free(GVirDomainSaveToFileData, data);
 }
 
 static void
@@ -621,7 +615,7 @@ gvir_domain_save_to_file_helper(GSimpleAsyncResult *res,
                                 GCancellable *cancellable G_GNUC_UNUSED)
 {
     GVirDomain *dom = GVIR_DOMAIN(object);
-    DomainSaveToFileData *data;
+    GVirDomainSaveToFileData *data;
     GError *err = NULL;
 
     data = g_simple_async_result_get_op_res_gpointer(res);
@@ -651,12 +645,12 @@ void gvir_domain_save_to_file_async(GVirDomain *dom,
                                     gpointer user_data)
 {
     GSimpleAsyncResult *res;
-    DomainSaveToFileData *data;
+    GVirDomainSaveToFileData *data;
 
     g_return_if_fail(GVIR_IS_DOMAIN(dom));
     g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
 
-    data = g_slice_new0(DomainSaveToFileData);
+    data = g_slice_new0(GVirDomainSaveToFileData);
     data->filename = g_strdup(filename);
     data->custom_conf = g_object_ref(custom_conf);
     data->flags = flags;
@@ -665,8 +659,10 @@ void gvir_domain_save_to_file_async(GVirDomain *dom,
                                     callback,
                                     user_data,
                                     gvir_domain_save_to_file_async);
-    g_simple_async_result_set_op_res_gpointer(res, data, (GDestroyNotify)
-                                              domain_save_to_file_data_free);
+    g_simple_async_result_set_op_res_gpointer
+                                 (res, data,
+                                  (GDestroyNotify)
+                                  gvir_domain_save_to_file_data_free);
 
     g_simple_async_result_run_in_thread(res,
                                         gvir_domain_save_to_file_helper,
diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h
index 8f17799..ac225a2 100644
--- a/libvirt-gobject/libvirt-gobject-domain.h
+++ b/libvirt-gobject/libvirt-gobject-domain.h
@@ -112,6 +112,14 @@ struct _GVirDomainInfo
     guint64 cpuTime;       /* the CPU time used in nanoseconds */
 };
 
+typedef struct _GVirDomainSaveToFileData GVirDomainSaveToFileData;
+struct _GVirDomainSaveToFileData
+{
+    gchar *filename;
+    GVirConfigDomain *custom_conf;
+    guint flags;
+};
+
 GType gvir_domain_get_type(void);
 GType gvir_domain_info_get_type(void);
 GType gvir_domain_handle_get_type(void);
@@ -166,6 +174,8 @@ gboolean gvir_domain_save_to_file_finish(GVirDomain *dom,
                                          GAsyncResult *result,
                                          GError **err);
 
+void gvir_domain_save_to_file_data_free(GVirDomainSaveToFileData *data);
+
 GVirDomainInfo *gvir_domain_get_info(GVirDomain *dom,
                                      GError **err);
 void gvir_domain_get_info_async(GVirDomain *dom,
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
index 54a093a..dde0e70 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_domain_restore;
+	gvir_connection_domain_restore_async;
+	gvir_connection_domain_restore_finish;
 
 	gvir_domain_device_get_type;
 	gvir_domain_device_get_domain;
@@ -78,6 +81,7 @@ LIBVIRT_GOBJECT_0.0.8 {
 	gvir_domain_save_to_file;
 	gvir_domain_save_to_file_async;
 	gvir_domain_save_to_file_finish;
+	gvir_domain_save_to_file_data_free;
 
 	gvir_domain_snapshot_get_type;
 	gvir_domain_snapshot_handle_get_type;
-- 
1.7.10.4


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