[PATCH 60/66] vbox: Rewrite vboxDomainRevertToSnapshot

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

 



---
 src/vbox/vbox_common.c        |   68 +++++++++++++++++++++++++++++++++++
 src/vbox/vbox_tmpl.c          |   80 ++---------------------------------------
 src/vbox/vbox_uniformed_api.h |    3 ++
 3 files changed, 74 insertions(+), 77 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index dcd8ab8..f5b07cf 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -6456,3 +6456,71 @@ int vboxDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
     vboxIIDUnalloc(&iid);
     return ret;
 }
+
+int vboxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
+                               unsigned int flags)
+{
+    virDomainPtr dom = snapshot->domain;
+    VBOX_OBJECT_CHECK(dom->conn, int, -1);
+    vboxIIDUnion domiid;
+    IMachine *machine = NULL;
+    ISnapshot *newSnapshot = NULL;
+    ISnapshot *prevSnapshot = NULL;
+    PRBool online = PR_FALSE;
+    PRUint32 state;
+    nsresult rc;
+
+    virCheckFlags(0, -1);
+
+    if (openSessionForMachine(data, dom->uuid, &domiid, &machine, false) < 0)
+        goto cleanup;
+
+    newSnapshot = vboxDomainSnapshotGet(data, dom, machine, snapshot->name);
+    if (!newSnapshot)
+        goto cleanup;
+
+    rc = gVBoxAPI.UISnapshot.GetOnline(newSnapshot, &online);
+    if (NS_FAILED(rc)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("could not get online state of snapshot %s"),
+                       snapshot->name);
+        goto cleanup;
+    }
+
+    rc = gVBoxAPI.UIMachine.GetCurrentSnapshot(machine, &prevSnapshot);
+    if (NS_FAILED(rc)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("could not get current snapshot of domain %s"),
+                       dom->name);
+        goto cleanup;
+    }
+
+    rc = gVBoxAPI.UIMachine.GetState(machine, &state);
+    if (NS_FAILED(rc)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("could not get domain state"));
+        goto cleanup;
+    }
+
+    if (gVBoxAPI.machineStateChecker.Online(state)) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("cannot revert snapshot of running domain"));
+        goto cleanup;
+    }
+
+    if (gVBoxAPI.snapshotRestore(dom, machine, newSnapshot))
+        goto cleanup;
+
+    if (online) {
+        ret = vboxDomainCreate(dom);
+        if (!ret)
+            gVBoxAPI.snapshotRestore(dom, machine, prevSnapshot);
+    } else
+        ret = 0;
+
+ cleanup:
+    VBOX_RELEASE(prevSnapshot);
+    VBOX_RELEASE(newSnapshot);
+    vboxIIDUnalloc(&domiid);
+    return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 6d80a26..adba028 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1524,7 +1524,7 @@ vboxDomainSnapshotGet(vboxGlobalData *data,
 
 #if VBOX_API_VERSION < 3001000
 static int
-vboxDomainSnapshotRestore(virDomainPtr dom,
+_vboxDomainSnapshotRestore(virDomainPtr dom,
                           IMachine *machine,
                           ISnapshot *snapshot)
 {
@@ -1554,7 +1554,7 @@ vboxDomainSnapshotRestore(virDomainPtr dom,
 }
 #else
 static int
-vboxDomainSnapshotRestore(virDomainPtr dom,
+_vboxDomainSnapshotRestore(virDomainPtr dom,
                           IMachine *machine,
                           ISnapshot *snapshot)
 {
@@ -1630,81 +1630,6 @@ vboxDomainSnapshotRestore(virDomainPtr dom,
 #endif
 
 static int
-vboxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
-                           unsigned int flags)
-{
-    virDomainPtr dom = snapshot->domain;
-    VBOX_OBJECT_CHECK(dom->conn, int, -1);
-    vboxIID domiid = VBOX_IID_INITIALIZER;
-    IMachine *machine = NULL;
-    ISnapshot *newSnapshot = NULL;
-    ISnapshot *prevSnapshot = NULL;
-    PRBool online = PR_FALSE;
-    PRUint32 state;
-    nsresult rc;
-
-    virCheckFlags(0, -1);
-
-    vboxIIDFromUUID(&domiid, dom->uuid);
-    rc = VBOX_OBJECT_GET_MACHINE(domiid.value, &machine);
-    if (NS_FAILED(rc)) {
-        virReportError(VIR_ERR_NO_DOMAIN, "%s",
-                       _("no domain with matching UUID"));
-        goto cleanup;
-    }
-
-    newSnapshot = vboxDomainSnapshotGet(data, dom, machine, snapshot->name);
-    if (!newSnapshot)
-        goto cleanup;
-
-    rc = newSnapshot->vtbl->GetOnline(newSnapshot, &online);
-    if (NS_FAILED(rc)) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("could not get online state of snapshot %s"),
-                       snapshot->name);
-        goto cleanup;
-    }
-
-    rc = machine->vtbl->GetCurrentSnapshot(machine, &prevSnapshot);
-    if (NS_FAILED(rc)) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("could not get current snapshot of domain %s"),
-                       dom->name);
-        goto cleanup;
-    }
-
-    rc = machine->vtbl->GetState(machine, &state);
-    if (NS_FAILED(rc)) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("could not get domain state"));
-        goto cleanup;
-    }
-
-    if (state >= MachineState_FirstOnline
-        && state <= MachineState_LastOnline) {
-        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                       _("cannot revert snapshot of running domain"));
-        goto cleanup;
-    }
-
-    if (vboxDomainSnapshotRestore(dom, machine, newSnapshot))
-        goto cleanup;
-
-    if (online) {
-        ret = vboxDomainCreate(dom);
-        if (!ret)
-            vboxDomainSnapshotRestore(dom, machine, prevSnapshot);
-    } else
-        ret = 0;
-
- cleanup:
-    VBOX_RELEASE(prevSnapshot);
-    VBOX_RELEASE(newSnapshot);
-    vboxIIDUnalloc(&domiid);
-    return ret;
-}
-
-static int
 vboxDomainSnapshotDeleteSingle(vboxGlobalData *data,
                                IConsole *console,
                                ISnapshot *snapshot)
@@ -7492,6 +7417,7 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
     pVBoxAPI->dumpFloppy = _dumpFloppy;
     pVBoxAPI->attachFloppy = _attachFloppy;
     pVBoxAPI->detachFloppy = _detachFloppy;
+    pVBoxAPI->snapshotRestore = _vboxDomainSnapshotRestore;
     pVBoxAPI->UPFN = _UPFN;
     pVBoxAPI->UIID = _UIID;
     pVBoxAPI->UArray = _UArray;
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index ac8a6b7..005b21b 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -473,6 +473,7 @@ typedef struct {
     void (*dumpFloppy)(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine);
     int (*attachFloppy)(vboxGlobalData *data, IMachine *machine, const char *src);
     int (*detachFloppy)(IMachine *machine);
+    int (*snapshotRestore)(virDomainPtr dom, IMachine *machine, ISnapshot *snapshot);
     vboxUniformedPFN UPFN;
     vboxUniformedIID UIID;
     vboxUniformedArray UArray;
@@ -593,6 +594,8 @@ int vboxDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
                                 unsigned int flags);
 int vboxDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
                                 unsigned int flags);
+int vboxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
+                               unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
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]