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

[libvirt] [PATCH 58/66] vbox: Rewrite vboxDomainSnapshotIsCurrent



---
 src/vbox/vbox_common.c        |   57 +++++++++++++++++++++++++++++++++++++
 src/vbox/vbox_tmpl.c          |   63 -----------------------------------------
 src/vbox/vbox_uniformed_api.h |    2 ++
 3 files changed, 59 insertions(+), 63 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 32cbe60..f38305a 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -6372,3 +6372,60 @@ vboxDomainSnapshotCurrent(virDomainPtr dom, unsigned int flags)
     vboxIIDUnalloc(&iid);
     return ret;
 }
+
+int vboxDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
+                                unsigned int flags)
+{
+    virDomainPtr dom = snapshot->domain;
+    VBOX_OBJECT_CHECK(dom->conn, int, -1);
+    vboxIIDUnion iid;
+    IMachine *machine = NULL;
+    ISnapshot *snap = NULL;
+    ISnapshot *current = NULL;
+    PRUnichar *nameUtf16 = NULL;
+    char *name = NULL;
+    nsresult rc;
+
+    virCheckFlags(0, -1);
+
+    if (openSessionForMachine(data, dom->uuid, &iid, &machine, false) < 0)
+        goto cleanup;
+
+    if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot->name)))
+        goto cleanup;
+
+    rc = gVBoxAPI.UIMachine.GetCurrentSnapshot(machine, &current);
+    if (NS_FAILED(rc)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("could not get current snapshot"));
+        goto cleanup;
+    }
+    if (!current) {
+        ret = 0;
+        goto cleanup;
+    }
+
+    rc = gVBoxAPI.UISnapshot.GetName(current, &nameUtf16);
+    if (NS_FAILED(rc) || !nameUtf16) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("could not get current snapshot name"));
+        goto cleanup;
+    }
+
+    VBOX_UTF16_TO_UTF8(nameUtf16, &name);
+    if (!name) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    ret = STREQ(snapshot->name, name);
+
+ cleanup:
+    VBOX_UTF8_FREE(name);
+    VBOX_UTF16_FREE(nameUtf16);
+    VBOX_RELEASE(snap);
+    VBOX_RELEASE(current);
+    VBOX_RELEASE(machine);
+    vboxIIDUnalloc(&iid);
+    return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 87200f1..fb3ed61 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1523,69 +1523,6 @@ vboxDomainSnapshotGet(vboxGlobalData *data,
 }
 
 static int
-vboxDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
-                            unsigned int flags)
-{
-    virDomainPtr dom = snapshot->domain;
-    VBOX_OBJECT_CHECK(dom->conn, int, -1);
-    vboxIID iid = VBOX_IID_INITIALIZER;
-    IMachine *machine = NULL;
-    ISnapshot *snap = NULL;
-    ISnapshot *current = NULL;
-    PRUnichar *nameUtf16 = NULL;
-    char *name = NULL;
-    nsresult rc;
-
-    virCheckFlags(0, -1);
-
-    vboxIIDFromUUID(&iid, dom->uuid);
-    rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine);
-    if (NS_FAILED(rc)) {
-        virReportError(VIR_ERR_NO_DOMAIN, "%s",
-                       _("no domain with matching UUID"));
-        goto cleanup;
-    }
-
-    if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot->name)))
-        goto cleanup;
-
-    rc = machine->vtbl->GetCurrentSnapshot(machine, &current);
-    if (NS_FAILED(rc)) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("could not get current snapshot"));
-        goto cleanup;
-    }
-    if (!current) {
-        ret = 0;
-        goto cleanup;
-    }
-
-    rc = current->vtbl->GetName(current, &nameUtf16);
-    if (NS_FAILED(rc) || !nameUtf16) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("could not get current snapshot name"));
-        goto cleanup;
-    }
-
-    VBOX_UTF16_TO_UTF8(nameUtf16, &name);
-    if (!name) {
-        virReportOOMError();
-        goto cleanup;
-    }
-
-    ret = STREQ(snapshot->name, name);
-
- cleanup:
-    VBOX_UTF8_FREE(name);
-    VBOX_UTF16_FREE(nameUtf16);
-    VBOX_RELEASE(snap);
-    VBOX_RELEASE(current);
-    VBOX_RELEASE(machine);
-    vboxIIDUnalloc(&iid);
-    return ret;
-}
-
-static int
 vboxDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
                               unsigned int flags)
 {
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index c320ac2..c761bda 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -589,6 +589,8 @@ vboxDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
                             unsigned int flags);
 virDomainSnapshotPtr
 vboxDomainSnapshotCurrent(virDomainPtr dom, unsigned int flags);
+int vboxDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
+                                unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5


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