]> xenbits.xensource.com Git - libvirt.git/commitdiff
snapshot: implement snapshot roots listing in vbox
authorEric Blake <eblake@redhat.com>
Mon, 3 Oct 2011 21:20:25 +0000 (15:20 -0600)
committerEric Blake <eblake@redhat.com>
Wed, 5 Oct 2011 14:57:58 +0000 (08:57 -0600)
Commit 9f5e53e introduced the ability to filter snapshots to
just roots, but it was never implemented for VBox until now.

The VBox implementation prohibits deletion of a snapshot with
multiple children.  Hence, there can only be at most one root,
which is found by searching for the snapshot with a NULL uuid.

Prior to 4.0, snapshotGet looked up by UUID, and snapshotFind
looked up by name; after that point, snapshotGet disappeared
and snapshotFind handles uuid or name.

* src/vbox/vbox_tmpl.c (vboxDomainSnapshotNum)
(vboxDomainSnapshotListNames): Implement limiting list to root.

src/vbox/vbox_tmpl.c

index 2eb23fb2ac0dcc022dc277a847e97f7edcf5c1c3..8c53f1f5494d5a0dda5df6d1ee93ad12ceacd794 100644 (file)
@@ -5871,7 +5871,8 @@ vboxDomainSnapshotNum(virDomainPtr dom,
     nsresult rc;
     PRUint32 snapshotCount;
 
-    virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
+    virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
+                  VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
 
     vboxIIDFromUUID(&iid, dom->uuid);
     rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine);
@@ -5895,7 +5896,11 @@ vboxDomainSnapshotNum(virDomainPtr dom,
         goto cleanup;
     }
 
-    ret = snapshotCount;
+    /* VBox has at most one root snapshot.  */
+    if (snapshotCount && (flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS))
+        ret = 1;
+    else
+        ret = snapshotCount;
 
 cleanup:
     VBOX_RELEASE(machine);
@@ -5917,7 +5922,8 @@ vboxDomainSnapshotListNames(virDomainPtr dom,
     int count = 0;
     int i;
 
-    virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
+    virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
+                  VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
 
     vboxIIDFromUUID(&iid, dom->uuid);
     rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine);
@@ -5932,8 +5938,29 @@ vboxDomainSnapshotListNames(virDomainPtr dom,
         goto cleanup;
     }
 
-    if ((count = vboxDomainSnapshotGetAll(dom, machine, &snapshots)) < 0)
-        goto cleanup;
+    if (flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) {
+        vboxIID empty = VBOX_IID_INITIALIZER;
+
+        if (VIR_ALLOC_N(snapshots, 1) < 0) {
+            virReportOOMError();
+            goto cleanup;
+        }
+#if VBOX_API_VERSION < 4000
+        rc = machine->vtbl->GetSnapshot(machine, empty.value, snapshots);
+#else /* VBOX_API_VERSION >= 4000 */
+        rc = machine->vtbl->FindSnapshot(machine, empty.value, snapshots);
+#endif /* VBOX_API_VERSION >= 4000 */
+        if (NS_FAILED(rc) || !snapshots[0]) {
+            vboxError(VIR_ERR_INTERNAL_ERROR,
+                      _("could not get root snapshot for domain %s"),
+                      dom->name);
+            goto cleanup;
+        }
+        count = 1;
+    } else {
+        if ((count = vboxDomainSnapshotGetAll(dom, machine, &snapshots)) < 0)
+            goto cleanup;
+    }
 
     for (i = 0; i < nameslen; i++) {
         PRUnichar *nameUtf16;