[PATCHv2 8/7] snapshot: implement snapshot roots listing in esx

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

 



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 |   17 +++++++++++++----
 src/esx/esx_vi.c     |   26 ++++++++++++++++----------
 src/esx/esx_vi.h     |    6 ++++--
 3 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index ab93efd..9718f61 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -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);

diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index 2d9890c..fa26dea 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -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;
diff --git a/src/esx/esx_vi.h b/src/esx/esx_vi.h
index 8677ca0..05ed3d0 100644
--- a/src/esx/esx_vi.h
+++ b/src/esx/esx_vi.h
@@ -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@xxxxxxxxxxxxxx>
  *
  * 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,
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]