Relatively straight-forward filtering. * src/esx/esx_vi.h (esxVI_GetNumberOfSnapshotTrees) (esxVI_GetSnapshotTreeNames): Add parameter. * src/esx/esx_vi.c (esxVI_GetNumberOfSnapshotTrees) (esxVI_GetSnapshotTreeNames): Allow leaf filtering. * src/esx/esx_driver.c (esxDomainSnapshotNum) (esxDomainSnapshotListNames, esxDomainSnapshotNumChildren) (esxDomainSnapshotListChildrenNames): Pass new flag through. --- src/esx/esx_driver.c | 29 +++++++++++++++++++++-------- src/esx/esx_vi.c | 27 ++++++++++++++++----------- src/esx/esx_vi.h | 4 ++-- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index bcf2406..f2a8f64 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -4359,11 +4359,14 @@ esxDomainSnapshotNum(virDomainPtr domain, unsigned int flags) esxPrivate *priv = domain->conn->privateData; esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL; bool recurse; + bool leaves; virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | - VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1); + VIR_DOMAIN_SNAPSHOT_LIST_METADATA | + VIR_DOMAIN_SNAPSHOT_LIST_LEAVES, -1); recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) == 0; + leaves = (flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) != 0; if (esxVI_EnsureSession(priv->primary) < 0) { return -1; @@ -4378,7 +4381,8 @@ esxDomainSnapshotNum(virDomainPtr domain, unsigned int flags) return -1; } - count = esxVI_GetNumberOfSnapshotTrees(rootSnapshotTreeList, recurse); + count = esxVI_GetNumberOfSnapshotTrees(rootSnapshotTreeList, recurse, + leaves); esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList); @@ -4395,11 +4399,14 @@ esxDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen, esxPrivate *priv = domain->conn->privateData; esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL; bool recurse; + bool leaves; virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | - VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1); + VIR_DOMAIN_SNAPSHOT_LIST_METADATA | + VIR_DOMAIN_SNAPSHOT_LIST_LEAVES, -1); recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) == 0; + leaves = (flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) != 0; if (names == NULL || nameslen < 0) { ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument")); @@ -4420,7 +4427,7 @@ esxDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen, } result = esxVI_GetSnapshotTreeNames(rootSnapshotTreeList, names, nameslen, - recurse); + recurse, leaves); esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList); @@ -4437,11 +4444,14 @@ esxDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot, unsigned int flags) esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL; esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL; bool recurse; + bool leaves; virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | - VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1); + VIR_DOMAIN_SNAPSHOT_LIST_METADATA | + VIR_DOMAIN_SNAPSHOT_LIST_LEAVES, -1); recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS) != 0; + leaves = (flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) != 0; if (esxVI_EnsureSession(priv->primary) < 0) { return -1; @@ -4462,7 +4472,7 @@ esxDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot, unsigned int flags) } count = esxVI_GetNumberOfSnapshotTrees(snapshotTree->childSnapshotList, - recurse); + recurse, leaves); cleanup: esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList); @@ -4482,11 +4492,14 @@ esxDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot, esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL; esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL; bool recurse; + bool leaves; virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | - VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1); + VIR_DOMAIN_SNAPSHOT_LIST_METADATA | + VIR_DOMAIN_SNAPSHOT_LIST_LEAVES, -1); recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS) != 0; + leaves = (flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) != 0; if (names == NULL || nameslen < 0) { ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument")); @@ -4516,7 +4529,7 @@ esxDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot, } result = esxVI_GetSnapshotTreeNames(snapshotTree->childSnapshotList, - names, nameslen, recurse); + names, nameslen, recurse, leaves); cleanup: esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList); diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index 4a8c709..55a388a 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -2164,17 +2164,19 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine, int esxVI_GetNumberOfSnapshotTrees - (esxVI_VirtualMachineSnapshotTree *snapshotTreeList, bool recurse) + (esxVI_VirtualMachineSnapshotTree *snapshotTreeList, bool recurse, + bool leaves) { int count = 0; esxVI_VirtualMachineSnapshotTree *snapshotTree; for (snapshotTree = snapshotTreeList; snapshotTree != NULL; snapshotTree = snapshotTree->_next) { - count++; + if (!(leaves && snapshotTree->childSnapshotList)) + count++; if (recurse) count += esxVI_GetNumberOfSnapshotTrees - (snapshotTree->childSnapshotList, true); + (snapshotTree->childSnapshotList, true, leaves); } return count; @@ -2184,7 +2186,8 @@ esxVI_GetNumberOfSnapshotTrees int esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, - char **names, int nameslen, bool recurse) + char **names, int nameslen, bool recurse, + bool leaves) { int count = 0; int result; @@ -2194,14 +2197,16 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, for (snapshotTree = snapshotTreeList; snapshotTree != NULL && count < nameslen; snapshotTree = snapshotTree->_next) { - names[count] = strdup(snapshotTree->name); + if (!(leaves && snapshotTree->childSnapshotList)) { + names[count] = strdup(snapshotTree->name); - if (names[count] == NULL) { - virReportOOMError(); - goto failure; - } + if (names[count] == NULL) { + virReportOOMError(); + goto failure; + } - count++; + count++; + } if (count >= nameslen) { break; @@ -2211,7 +2216,7 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, result = esxVI_GetSnapshotTreeNames(snapshotTree->childSnapshotList, names + count, nameslen - count, - true); + true, leaves); if (result < 0) { goto failure; diff --git a/src/esx/esx_vi.h b/src/esx/esx_vi.h index 05ed3d0..b8e921f 100644 --- a/src/esx/esx_vi.h +++ b/src/esx/esx_vi.h @@ -359,11 +359,11 @@ int esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine, int esxVI_GetNumberOfSnapshotTrees (esxVI_VirtualMachineSnapshotTree *snapshotTreeList, - bool recurse); + bool recurse, bool leaves); int esxVI_GetSnapshotTreeNames (esxVI_VirtualMachineSnapshotTree *snapshotTreeList, char **names, - int nameslen, bool recurse); + int nameslen, bool recurse, bool leaves); 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