]> xenbits.xensource.com Git - libvirt.git/commitdiff
snapshot: implement snapshot roots listing in esx
authorEric Blake <eblake@redhat.com>
Mon, 3 Oct 2011 17:38:21 +0000 (11:38 -0600)
committerEric Blake <eblake@redhat.com>
Wed, 5 Oct 2011 14:16:15 +0000 (08:16 -0600)
Commit 9f5e53e introduced the ability to filter snapshots to
just roots, but it was never implemented for ESX until now.

* src/esx/esx_vi.h (esxVI_GetNumberOfSnapshotTrees)
(esxVI_GetSnapshotTreeNames): Add parameter.
* src/esx/esx_vi.c (esxVI_GetNumberOfSnapshotTrees)
(esxVI_GetSnapshotTreeNames): Allow choice of recursion or not.
* src/esx/esx_driver.c (esxDomainSnapshotNum)
(esxDomainSnapshotListNames): Use it to limit to roots.

src/esx/esx_driver.c
src/esx/esx_vi.c
src/esx/esx_vi.h

index ab93efd12cf83155e187110116517d422edbfaba..9718f61211816002b67bf156e4d3d84bcfc3f5a1 100644 (file)
@@ -4359,8 +4359,12 @@ esxDomainSnapshotNum(virDomainPtr domain, unsigned int flags)
     int count;
     esxPrivate *priv = domain->conn->privateData;
     esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
+    bool recurse;
 
-    virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
+    virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
+                  VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
+
+    recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) == 0;
 
     if (esxVI_EnsureSession(priv->primary) < 0) {
         return -1;
@@ -4375,7 +4379,7 @@ esxDomainSnapshotNum(virDomainPtr domain, unsigned int flags)
         return -1;
     }
 
-    count = esxVI_GetNumberOfSnapshotTrees(rootSnapshotTreeList);
+    count = esxVI_GetNumberOfSnapshotTrees(rootSnapshotTreeList, recurse);
 
     esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
 
@@ -4391,8 +4395,12 @@ esxDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen,
     int result;
     esxPrivate *priv = domain->conn->privateData;
     esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
+    bool recurse;
+
+    virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
+                  VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
 
-    virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
+    recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) == 0;
 
     if (names == NULL || nameslen < 0) {
         ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument"));
@@ -4412,7 +4420,8 @@ esxDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen,
         return -1;
     }
 
-    result = esxVI_GetSnapshotTreeNames(rootSnapshotTreeList, names, nameslen);
+    result = esxVI_GetSnapshotTreeNames(rootSnapshotTreeList, names, nameslen,
+                                        recurse);
 
     esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
 
index 2d9890cb0248392b2c323ecbbed87b3d651fa5f2..fa26dea1fb87cc33852b568701f7846eda1e9312 100644 (file)
@@ -2164,15 +2164,17 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine,
 
 int
 esxVI_GetNumberOfSnapshotTrees
-  (esxVI_VirtualMachineSnapshotTree *snapshotTreeList)
+  (esxVI_VirtualMachineSnapshotTree *snapshotTreeList, bool recurse)
 {
     int count = 0;
     esxVI_VirtualMachineSnapshotTree *snapshotTree;
 
     for (snapshotTree = snapshotTreeList; snapshotTree != NULL;
          snapshotTree = snapshotTree->_next) {
-        count += 1 + esxVI_GetNumberOfSnapshotTrees
-                       (snapshotTree->childSnapshotList);
+        count++;
+        if (recurse)
+            count += esxVI_GetNumberOfSnapshotTrees
+                (snapshotTree->childSnapshotList, true);
     }
 
     return count;
@@ -2182,7 +2184,7 @@ esxVI_GetNumberOfSnapshotTrees
 
 int
 esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList,
-                           char **names, int nameslen)
+                           char **names, int nameslen, bool recurse)
 {
     int count = 0;
     int result;
@@ -2205,14 +2207,18 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList,
             break;
         }
 
-        result = esxVI_GetSnapshotTreeNames(snapshotTree->childSnapshotList,
-                                            names + count, nameslen - count);
+        if (recurse) {
+            result = esxVI_GetSnapshotTreeNames(snapshotTree->childSnapshotList,
+                                                names + count,
+                                                nameslen - count,
+                                                true);
 
-        if (result < 0) {
-            goto failure;
-        }
+            if (result < 0) {
+                goto failure;
+            }
 
-        count += result;
+            count += result;
+        }
     }
 
     return count;
index 8677ca0461d1a8dd20a1421dd06065806dc09cf5..05ed3d06f15f2c909eca150fc28ed1565bc3f973 100644 (file)
@@ -2,6 +2,7 @@
 /*
  * esx_vi.h: client for the VMware VI API 2.5 to manage ESX hosts
  *
+ * Copyright (C) 2011 Red Hat, Inc.
  * Copyright (C) 2009-2010 Matthias Bolte <matthias.bolte@googlemail.com>
  *
  * This library is free software; you can redistribute it and/or
@@ -357,11 +358,12 @@ int esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine,
                                     int *id, char **name, unsigned char *uuid);
 
 int esxVI_GetNumberOfSnapshotTrees
-      (esxVI_VirtualMachineSnapshotTree *snapshotTreeList);
+      (esxVI_VirtualMachineSnapshotTree *snapshotTreeList,
+       bool recurse);
 
 int esxVI_GetSnapshotTreeNames
       (esxVI_VirtualMachineSnapshotTree *snapshotTreeList, char **names,
-       int nameslen);
+       int nameslen, bool recurse);
 
 int esxVI_GetSnapshotTreeByName
       (esxVI_VirtualMachineSnapshotTree *snapshotTreeList, const char *name,