From 869b69ea3dda89e05802c9f030c3655f2741ebe6 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 3 Oct 2011 15:20:25 -0600 Subject: [PATCH] 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. --- src/vbox/vbox_tmpl.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 2eb23fb2ac..8c53f1f549 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -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; -- GitLab