2011/10/4 Eric Blake <eblake(a)redhat.com>:
Adding this for VBox was a bit harder than for ESX, but the same
principles apply for starting the traversal at a known point
rather than covering the entire hierarchy.
* src/vbox/vbox_tmpl.c (vboxCountDescendants)
(vboxDomainSnapshotNumChildren)
(vboxDomainSnapshotListChildrenNames): New functions.
---
Caveat: Again, only compile-tested. No idea if it really works.
It copies a good chunk of code from vboxDomainSnapshotGetAll, but
I didn't really see a clean way to factor that repeated chunk into
its own function.
src/vbox/vbox_tmpl.c | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 208 insertions(+), 0 deletions(-)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index d1da6fd..a5372e8 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
+static int
+vboxDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot,
+ char **names,
+ int nameslen,
+ unsigned int flags)
+ if (flags & VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS) {
+ int top = children.count;
+ int next;
+
+ for (next = 0; next < count; next++) {
+ if (!snapshots[next])
+ break;
This line is wrong I think. In vboxDomainSnapshotGetAll this works,
because list[0] is pre-filled with the root, but here it's initially
NULL and the whole loop is directly left.
+ rc = vboxArrayGet(&children, snapshots[next],
+ snapshots[next]->vtbl->GetChildren);
+ if (NS_FAILED(rc)) {
+ vboxError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("could not get children
snapshots"));
+ goto cleanup;
+ }
+ for (i = 0; i < children.count; i++) {
+ ISnapshot *child = children.items[i];
+ if (!child)
+ continue;
+ if (top == count) {
+ vboxError(VIR_ERR_INTERNAL_ERROR,
+ _("unexpected number of snapshots > %u"),
count);
+ vboxArrayRelease(&children);
+ goto cleanup;
+ }
+ VBOX_ADDREF(child);
+ snapshots[top++] = child;
+ }
+ vboxArrayRelease(&children);
+ }
+ count = top;
+ } else {
+ count = children.count;
+ }
+
+ for (i = 0; i < nameslen; i++) {
+ PRUnichar *nameUtf16;
+ char *name;
+
+ if (i >= count)
+ break;
+
+ rc = snapshots[i]->vtbl->GetName(snapshots[i], &nameUtf16);
This triggers a segfault, because snapshots[0] is NULL.
I ran out of time for debugging this.
--
Matthias Bolte
http://photron.blogspot.com