提交 e570d7c4 编写于 作者: E Eric Blake

snapshot: implement LIST_LEAVES flag in esx

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.
上级 9f4b49cd
...@@ -4359,11 +4359,14 @@ esxDomainSnapshotNum(virDomainPtr domain, unsigned int flags) ...@@ -4359,11 +4359,14 @@ esxDomainSnapshotNum(virDomainPtr domain, unsigned int flags)
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL; esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
bool recurse; bool recurse;
bool leaves;
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | 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; recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) == 0;
leaves = (flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) != 0;
if (esxVI_EnsureSession(priv->primary) < 0) { if (esxVI_EnsureSession(priv->primary) < 0) {
return -1; return -1;
...@@ -4378,7 +4381,8 @@ esxDomainSnapshotNum(virDomainPtr domain, unsigned int flags) ...@@ -4378,7 +4381,8 @@ esxDomainSnapshotNum(virDomainPtr domain, unsigned int flags)
return -1; return -1;
} }
count = esxVI_GetNumberOfSnapshotTrees(rootSnapshotTreeList, recurse); count = esxVI_GetNumberOfSnapshotTrees(rootSnapshotTreeList, recurse,
leaves);
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList); esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
...@@ -4395,11 +4399,14 @@ esxDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen, ...@@ -4395,11 +4399,14 @@ esxDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen,
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL; esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
bool recurse; bool recurse;
bool leaves;
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | 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; recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) == 0;
leaves = (flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) != 0;
if (names == NULL || nameslen < 0) { if (names == NULL || nameslen < 0) {
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument")); ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument"));
...@@ -4420,7 +4427,7 @@ esxDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen, ...@@ -4420,7 +4427,7 @@ esxDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen,
} }
result = esxVI_GetSnapshotTreeNames(rootSnapshotTreeList, names, nameslen, result = esxVI_GetSnapshotTreeNames(rootSnapshotTreeList, names, nameslen,
recurse); recurse, leaves);
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList); esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
...@@ -4437,11 +4444,14 @@ esxDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot, unsigned int flags) ...@@ -4437,11 +4444,14 @@ esxDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot, unsigned int flags)
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL; esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL; esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
bool recurse; bool recurse;
bool leaves;
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | 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; recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS) != 0;
leaves = (flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) != 0;
if (esxVI_EnsureSession(priv->primary) < 0) { if (esxVI_EnsureSession(priv->primary) < 0) {
return -1; return -1;
...@@ -4462,7 +4472,7 @@ esxDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot, unsigned int flags) ...@@ -4462,7 +4472,7 @@ esxDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot, unsigned int flags)
} }
count = esxVI_GetNumberOfSnapshotTrees(snapshotTree->childSnapshotList, count = esxVI_GetNumberOfSnapshotTrees(snapshotTree->childSnapshotList,
recurse); recurse, leaves);
cleanup: cleanup:
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList); esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
...@@ -4482,11 +4492,14 @@ esxDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot, ...@@ -4482,11 +4492,14 @@ esxDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot,
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL; esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL; esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
bool recurse; bool recurse;
bool leaves;
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | 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; recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS) != 0;
leaves = (flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) != 0;
if (names == NULL || nameslen < 0) { if (names == NULL || nameslen < 0) {
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument")); ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument"));
...@@ -4516,7 +4529,7 @@ esxDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot, ...@@ -4516,7 +4529,7 @@ esxDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot,
} }
result = esxVI_GetSnapshotTreeNames(snapshotTree->childSnapshotList, result = esxVI_GetSnapshotTreeNames(snapshotTree->childSnapshotList,
names, nameslen, recurse); names, nameslen, recurse, leaves);
cleanup: cleanup:
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList); esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
......
...@@ -2161,17 +2161,19 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine, ...@@ -2161,17 +2161,19 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine,
int int
esxVI_GetNumberOfSnapshotTrees esxVI_GetNumberOfSnapshotTrees
(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, bool recurse) (esxVI_VirtualMachineSnapshotTree *snapshotTreeList, bool recurse,
bool leaves)
{ {
int count = 0; int count = 0;
esxVI_VirtualMachineSnapshotTree *snapshotTree; esxVI_VirtualMachineSnapshotTree *snapshotTree;
for (snapshotTree = snapshotTreeList; snapshotTree != NULL; for (snapshotTree = snapshotTreeList; snapshotTree != NULL;
snapshotTree = snapshotTree->_next) { snapshotTree = snapshotTree->_next) {
if (!(leaves && snapshotTree->childSnapshotList))
count++; count++;
if (recurse) if (recurse)
count += esxVI_GetNumberOfSnapshotTrees count += esxVI_GetNumberOfSnapshotTrees
(snapshotTree->childSnapshotList, true); (snapshotTree->childSnapshotList, true, leaves);
} }
return count; return count;
...@@ -2181,7 +2183,8 @@ esxVI_GetNumberOfSnapshotTrees ...@@ -2181,7 +2183,8 @@ esxVI_GetNumberOfSnapshotTrees
int int
esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList,
char **names, int nameslen, bool recurse) char **names, int nameslen, bool recurse,
bool leaves)
{ {
int count = 0; int count = 0;
int result; int result;
...@@ -2191,6 +2194,7 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, ...@@ -2191,6 +2194,7 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList,
for (snapshotTree = snapshotTreeList; for (snapshotTree = snapshotTreeList;
snapshotTree != NULL && count < nameslen; snapshotTree != NULL && count < nameslen;
snapshotTree = snapshotTree->_next) { snapshotTree = snapshotTree->_next) {
if (!(leaves && snapshotTree->childSnapshotList)) {
names[count] = strdup(snapshotTree->name); names[count] = strdup(snapshotTree->name);
if (names[count] == NULL) { if (names[count] == NULL) {
...@@ -2199,6 +2203,7 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, ...@@ -2199,6 +2203,7 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList,
} }
count++; count++;
}
if (count >= nameslen) { if (count >= nameslen) {
break; break;
...@@ -2208,7 +2213,7 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, ...@@ -2208,7 +2213,7 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList,
result = esxVI_GetSnapshotTreeNames(snapshotTree->childSnapshotList, result = esxVI_GetSnapshotTreeNames(snapshotTree->childSnapshotList,
names + count, names + count,
nameslen - count, nameslen - count,
true); true, leaves);
if (result < 0) { if (result < 0) {
goto failure; goto failure;
......
...@@ -359,11 +359,11 @@ int esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine, ...@@ -359,11 +359,11 @@ int esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine,
int esxVI_GetNumberOfSnapshotTrees int esxVI_GetNumberOfSnapshotTrees
(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, (esxVI_VirtualMachineSnapshotTree *snapshotTreeList,
bool recurse); bool recurse, bool leaves);
int esxVI_GetSnapshotTreeNames int esxVI_GetSnapshotTreeNames
(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, char **names, (esxVI_VirtualMachineSnapshotTree *snapshotTreeList, char **names,
int nameslen, bool recurse); int nameslen, bool recurse, bool leaves);
int esxVI_GetSnapshotTreeByName int esxVI_GetSnapshotTreeByName
(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, const char *name, (esxVI_VirtualMachineSnapshotTree *snapshotTreeList, const char *name,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册