snapshot: implement snapshot roots listing in vbox

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.
This commit is contained in:
Eric Blake 2011-10-03 15:20:25 -06:00
parent fcd2bd55d7
commit 869b69ea3d

View 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;