Older VBox provided snapshotGet, which looks up by UUID (and
where NULL looked up the root) and snapshotFind, which looks up
by name. VBox 4.0 consolidated into snapshotFind that looks up
by UUID or name (and NULL still looks up the root). But since
name lookup has always been present, we don't need to recurse
through the snapshot tree ourselves.
* src/vbox/vbox_tmpl.c (vboxDomainSnapshotGet): Use name lookup,
rather than crawling through entire hierarchy.
---
v2: Use snapshotFind for all versions, dropping all cruft that
attempted snapshotGet, based on Matthias' review.
It would be nice if someone could test this on VBox 2.2 prior to
pushing...
src/vbox/vbox_tmpl.c | 45 ++++++++++-----------------------------------
1 files changed, 10 insertions(+), 35 deletions(-)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 8c53f1f..c74d2cf 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -5586,50 +5586,25 @@ vboxDomainSnapshotGet(vboxGlobalData *data,
IMachine *machine,
const char *name)
{
- ISnapshot **snapshots = NULL;
ISnapshot *snapshot = NULL;
nsresult rc;
- int count = 0;
- int i;
-
- if ((count = vboxDomainSnapshotGetAll(dom, machine, &snapshots)) < 0)
- goto cleanup;
-
- for (i = 0; i < count; i++) {
- PRUnichar *nameUtf16;
- char *nameUtf8;
-
- rc = snapshots[i]->vtbl->GetName(snapshots[i], &nameUtf16);
- if (NS_FAILED(rc) || !nameUtf16) {
- vboxError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("could not get snapshot name"));
- goto cleanup;
- }
- VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8);
- VBOX_UTF16_FREE(nameUtf16);
- if (STREQ(name, nameUtf8))
- snapshot = snapshots[i];
- VBOX_UTF8_FREE(nameUtf8);
+ PRUnichar *nameUtf16 = NULL;
- if (snapshot)
- break;
+ VBOX_UTF8_TO_UTF16(name, &nameUtf16);
+ if (!nameUtf16) {
+ virReportOOMError();
+ return NULL;
}
- if (!snapshot) {
- vboxError(VIR_ERR_OPERATION_INVALID,
+ rc = machine->vtbl->FindSnapshot(machine, nameUtf16, &snapshot);
+ VBOX_UTF16_FREE(nameUtf16);
+ if (NS_FAILED(rc) || !snapshot) {
+ vboxError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
_("domain %s has no snapshots with name %s"),
dom->name, name);
- goto cleanup;
+ return NULL;
}
-cleanup:
- if (count > 0) {
- for (i = 0; i < count; i++) {
- if (snapshots[i] != snapshot)
- VBOX_RELEASE(snapshots[i]);
- }
- }
- VIR_FREE(snapshots);
return snapshot;
}
--
1.7.4.4