[PATCH 2/2] snapshot: implement getparent for vbox

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

 



Again, built by copying from existing functions.

* src/vbox/vbox_tmpl.c (vboxDomainSnapshotGetParent): New function.
---

I can only compile-test this; I'm relying on someone with an actual
vbox setup to actually test it.  Also, I didn't see anything in
existing code that would efficiently implement
virDomainSnapshotNumChildren; there may an API that I'm not aware of,
but someone else will have to implement that API (Matthias?)

 src/vbox/vbox_tmpl.c |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index b483d0f..3d5f4ae 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -6046,6 +6046,76 @@ cleanup:
 }

 static virDomainSnapshotPtr
+vboxDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
+                            unsigned int flags)
+{
+    virDomainPtr dom = snapshot->domain;
+    VBOX_OBJECT_CHECK(dom->conn, virDomainSnapshotPtr, NULL);
+    vboxIID iid = VBOX_IID_INITIALIZER;
+    IMachine *machine = NULL;
+    ISnapshot *snap = NULL;
+    ISnapshot *parent = NULL;
+    PRUnichar *nameUtf16 = NULL;
+    char *name = NULL;
+    nsresult rc;
+
+    virCheckFlags(0, NULL);
+
+    vboxIIDFromUUID(&iid, dom->uuid);
+    rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine);
+    if (NS_FAILED(rc)) {
+        vboxError(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, &snap);
+    if (NS_FAILED(rc)) {
+        vboxError(VIR_ERR_INTERNAL_ERROR, "%s",
+                  _("could not get current snapshot"));
+        goto cleanup;
+    }
+
+    rc = snap->vtbl->GetParent(snap, &parent);
+    if (NS_FAILED(rc)) {
+        vboxError(VIR_ERR_INTERNAL_ERROR,
+                  _("could not get parent of snapshot %s"),
+                  snapshot->name);
+        goto cleanup;
+    }
+    if (!parent) {
+        vboxError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
+                  _("snapshot '%s' does not have a parent"),
+                  snapshot->name);
+        goto cleanup;
+    }
+
+    rc = parent->vtbl->GetName(parent, &nameUtf16);
+    if (NS_FAILED(rc) || !nameUtf16) {
+        vboxError(VIR_ERR_INTERNAL_ERROR,
+                  _("could not get name of parent of snapshot %s"),
+                  snapshot->name);
+        goto cleanup;
+    }
+    VBOX_UTF16_TO_UTF8(nameUtf16, &name);
+    VBOX_UTF16_FREE(nameUtf16);
+
+    ret = virGetDomainSnapshot(dom, name);
+
+cleanup:
+    VBOX_UTF8_FREE(name);
+    VBOX_UTF16_FREE(nameUtf16);
+    VBOX_RELEASE(snap);
+    VBOX_RELEASE(parent);
+    VBOX_RELEASE(machine);
+    vboxIIDUnalloc(&iid);
+    return ret;
+}
+
+static virDomainSnapshotPtr
 vboxDomainSnapshotCurrent(virDomainPtr dom,
                           unsigned int flags)
 {
@@ -8879,6 +8949,7 @@ virDriver NAME(Driver) = {
     .domainSnapshotListNames = vboxDomainSnapshotListNames, /* 0.8.0 */
     .domainSnapshotLookupByName = vboxDomainSnapshotLookupByName, /* 0.8.0 */
     .domainHasCurrentSnapshot = vboxDomainHasCurrentSnapshot, /* 0.8.0 */
+    .domainSnapshotGetParent = vboxDomainSnapshotGetParent, /* 0.9.7 */
     .domainSnapshotCurrent = vboxDomainSnapshotCurrent, /* 0.8.0 */
     .domainRevertToSnapshot = vboxDomainRevertToSnapshot, /* 0.8.0 */
     .domainSnapshotDelete = vboxDomainSnapshotDelete, /* 0.8.0 */
-- 
1.7.4.4

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