[libvirt] [PATCHv2 11/7] snapshot: optimize vbox snapshot name lookup

Eric Blake eblake at redhat.com
Mon Oct 3 23:11:37 UTC 2011


Older VBox required grabbing all snapshots, then looking through
them until a name match was found.  But when VBox 3.1 introduced
snapshot branching, it also added the ability to lookup a snapshot
by name instead of UUID; exploit this for faster snapshot lookup.

* src/vbox/vbox_tmpl.c (vboxDomainSnapshotGet): Newer vbox added
snapshot lookup by name.
---

Caveat - this is written solely by reading VBox documentation, and
I was only able to compile test.  I have no idea if this really
works, or if VBox 3.1 is the right cut-off point.

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

diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 2eb23fb..ba2252c 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -5586,9 +5586,12 @@ vboxDomainSnapshotGet(vboxGlobalData *data,
                       IMachine *machine,
                       const char *name)
 {
-    ISnapshot **snapshots = NULL;
     ISnapshot *snapshot = NULL;
     nsresult rc;
+
+#if VBOX_API_VERSION < 3001
+
+    ISnapshot **snapshots = NULL;
     int count = 0;
     int i;

@@ -5615,6 +5618,30 @@ vboxDomainSnapshotGet(vboxGlobalData *data,
             break;
     }

+#else /* VBOX_API_VERSION >= 3001 */
+    PRUnichar *nameUtf16 = NULL;
+
+    VBOX_UTF8_TO_UTF16(name, &nameUtf16);
+    if (!nameUtf16) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+# if VBOX_API_VERSION < 4000
+    rc = machine->vtbl->GetSnapshot(machine, nameUtf16, &snapshot);
+# else /* VBOX_API_VERSION >= 4000 */
+    rc = machine->vtbl->FindSnapshot(machine, nameUtf16, &snapshot);
+# endif /* VBOX_API_VERSION >= 4000 */
+    VBOX_UTF16_FREE(nameUtf16);
+    if (NS_FAILED(rc)) {
+        vboxError(VIR_ERR_INTERNAL_ERROR,
+                  _("could not get root snapshot for domain %s"),
+                  dom->name);
+        goto cleanup;
+    }
+
+#endif /* VBOX_API_VERSION >= 3001 */
+
     if (!snapshot) {
         vboxError(VIR_ERR_OPERATION_INVALID,
                   _("domain %s has no snapshots with name %s"),
@@ -5623,6 +5650,7 @@ vboxDomainSnapshotGet(vboxGlobalData *data,
     }

 cleanup:
+#if VBOX_API_VERSION < 3001
     if (count > 0) {
         for (i = 0; i < count; i++) {
             if (snapshots[i] != snapshot)
@@ -5630,6 +5658,7 @@ cleanup:
         }
     }
     VIR_FREE(snapshots);
+#endif /* VBOX_API_VERSION < 3001 */
     return snapshot;
 }

-- 
1.7.4.4




More information about the libvir-list mailing list