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

[libvirt] [PATCH] GVirDomainSnapshot: Add _revert_to



Add a way to revert a domain to one of its snapshots.
---
 libvirt-gobject/libvirt-gobject-domain-snapshot.c | 35 +++++++++++++++++++++++
 libvirt-gobject/libvirt-gobject-domain-snapshot.h | 18 ++++++++++++
 libvirt-gobject/libvirt-gobject.sym               |  2 ++
 3 files changed, 55 insertions(+)

diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.c b/libvirt-gobject/libvirt-gobject-domain-snapshot.c
index c53e877..56c9ddb 100644
--- a/libvirt-gobject/libvirt-gobject-domain-snapshot.c
+++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.c
@@ -268,3 +268,38 @@ gboolean gvir_domain_snapshot_get_is_current(GVirDomainSnapshot *snapshot,
 
     return TRUE;
 }
+
+
+
+/**
+ * gvir_domain_snapshot_revert_to:
+ * @snapshot: The domain snapshot
+ * @flags: Bitwise OR of GVirDomainSnapshotRevertFlags
+ * @cancellable: (allow-none) (transfer none): cancellation object
+ * @error: (allow-none): Place-holder for error or %NULL
+ *
+ * Returns: %TRUE if the snapshot's domain has successfully been
+ * reverted to the given snapshot, %FALSE otherwise, in which case
+ * @error will be set.
+ */
+gboolean gvir_domain_snapshot_revert_to(GVirDomainSnapshot *snapshot,
+                                        guint flags,
+                                        GCancellable *cancellable,
+                                        GError **error) {
+    int status;
+
+    g_return_val_if_fail(GVIR_IS_DOMAIN_SNAPSHOT(snapshot), FALSE);
+    g_return_val_if_fail((error == NULL) || (*error == NULL), FALSE);
+
+
+    status = virDomainRevertToSnapshot(snapshot->priv->handle,
+                                       flags);
+    if (status != 0) {
+        gvir_set_error(error, GVIR_DOMAIN_SNAPSHOT_ERROR,
+                       0, "Failed to revert to snapshot `%s'",
+                       gvir_domain_snapshot_get_name(snapshot));
+        return FALSE;
+    }
+
+    return TRUE;
+}
diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.h b/libvirt-gobject/libvirt-gobject-domain-snapshot.h
index 0a0bb96..c67b345 100644
--- a/libvirt-gobject/libvirt-gobject-domain-snapshot.h
+++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.h
@@ -71,6 +71,19 @@ typedef enum {
 } GVirDomainSnapshotDeleteFlags;
 
 
+/**
+ * GVirDomainSnapshotRevertFlags:
+ * @GVIR_DOMAIN_SNAPSHOT_REVERT_RUNNING: Run after revert
+ * @GVIR_DOMAIN_SNAPSHOT_REVERT_PAUSED: Pause after revert
+ * @GVIR_DOMAIN_SNAPSHOT_REVERT_FORCE: Allow risky reverts
+ */
+typedef enum {
+  GVIR_DOMAIN_SNAPSHOT_REVERT_RUNNING = 1,
+  GVIR_DOMAIN_SNAPSHOT_REVERT_PAUSED = 2,
+  GVIR_DOMAIN_SNAPSHOT_REVERT_FORCE = 4
+} GVirDomainSnapshotRevertFlags;
+
+
 GType gvir_domain_snapshot_get_type(void);
 GType gvir_domain_snapshot_handle_get_type(void);
 
@@ -89,6 +102,11 @@ gboolean gvir_domain_snapshot_get_is_current(GVirDomainSnapshot *snapshot,
                                              guint flags,
                                              gboolean *is_current,
                                              GError **error);
+
+gboolean gvir_domain_snapshot_revert_to(GVirDomainSnapshot *snapshot,
+                                        guint flags,
+                                        GCancellable *cancellable,
+                                        GError **error);
 G_END_DECLS
 
 #endif /* __LIBVIRT_GOBJECT_DOMAIN_SNAPSHOT_H__ */
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
index c740f88..c1c9421 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -244,6 +244,8 @@ LIBVIRT_GOBJECT_0.1.9 {
 	gvir_domain_snapshot_delete_flags_get_type;
 	gvir_domain_snapshot_get_is_current;
 	gvir_domain_snapshot_list_flags_get_type;
+	gvir_domain_snapshot_revert_flags_get_type;
+	gvir_domain_snapshot_revert_to;
 	gvir_storage_pool_state_get_type;
 	gvir_storage_vol_resize_flags_get_type;
 	gvir_storage_vol_type_get_type;
-- 
2.0.4


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