[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 4/8] list: use the new snapshot API in virsh when possible



Using the new API is so much shorter than the rest of the remainder
of the function.

* tools/virsh.c (vshSnapshotList): Use the new API.
---
 tools/virsh.c |   30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 936b9fe..b2d5a74 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -16754,13 +16754,41 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
     int count = 0;
     bool descendants = false;
     bool roots = false;
+    virDomainSnapshotPtr *snaps;
     vshSnapshotListPtr snaplist = vshMalloc(ctl, sizeof(*snaplist));
     vshSnapshotListPtr ret = NULL;
     const char *fromname = NULL;
     int start_index = -1;
     int deleted = 0;

-    /* 0.9.13 will be adding a new listing API.  */
+    /* Try the interface available in 0.9.13 and newer.  */
+    if (from) {
+        count = virDomainSnapshotListAllChildren(from, &snaps, flags);
+        /* When mixing --from and --tree, we also want from in the
+         * list; thankfully we know the API allocated a spare slot at
+         * the end for a trailing NULL, which we reuse.  */
+        if (tree && count >= 0) {
+            snaps[count++] = from;
+            virDomainSnapshotRef(from);
+        }
+    } else {
+        count = virDomainListAllSnapshots(dom, &snaps, flags);
+    }
+    if (count >= 0) {
+        snaplist->snaps = vshCalloc(ctl, sizeof(*snaplist->snaps), count);
+        snaplist->nsnaps = count;
+        for (i = 0; i < count; i++)
+            snaplist->snaps[i].snap = snaps[i];
+        VIR_FREE(snaps);
+        if (tree) {
+            for (i = 0; i < count; i++) {
+                if (vshGetSnapshotParent(ctl, snaplist->snaps[i].snap,
+                                         &snaplist->snaps[i].parent) < 0)
+                    goto cleanup;
+            }
+        }
+        goto success;
+    }

     /* Assume that if we got this far, then the --no-leaves and
      * --no-metadata flags were not supported.  Disable groups that
-- 
1.7.10.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]