1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-09-20 05:44:53 +03:00

snapshot: virsh indentation cleanup

No semantic change; this will make it easier to refactor code.

* tools/virsh.c (cmdSnapshotList): Drop level of indentation, and
rename a variable.
This commit is contained in:
Eric Blake
2012-06-08 15:59:21 -06:00
parent c8564ad476
commit 903560245f

View File

@@ -16599,10 +16599,9 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
unsigned int flags = 0; unsigned int flags = 0;
int parent_filter = 0; /* -1 for roots filtering, 0 for no parent int parent_filter = 0; /* -1 for roots filtering, 0 for no parent
information needed, 1 for parent column */ information needed, 1 for parent column */
int numsnaps;
char **names = NULL; char **names = NULL;
char **parents = NULL; char **parents = NULL;
int actual = 0; int count = 0;
int i; int i;
xmlDocPtr xml = NULL; xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL; xmlXPathContextPtr ctxt = NULL;
@@ -16676,9 +16675,9 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
if (descendants || tree) { if (descendants || tree) {
flags |= VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS; flags |= VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS;
} }
numsnaps = ctl->useSnapshotOld ? -1 : count = ctl->useSnapshotOld ? -1 :
virDomainSnapshotNumChildren(start, flags); virDomainSnapshotNumChildren(start, flags);
if (numsnaps < 0) { if (count < 0) {
if (ctl->useSnapshotOld || if (ctl->useSnapshotOld ||
last_error->code == VIR_ERR_NO_SUPPORT) { last_error->code == VIR_ERR_NO_SUPPORT) {
/* We can emulate --from. */ /* We can emulate --from. */
@@ -16687,27 +16686,27 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
last_error = NULL; last_error = NULL;
ctl->useSnapshotOld = true; ctl->useSnapshotOld = true;
flags &= ~VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS; flags &= ~VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS;
numsnaps = virDomainSnapshotNum(dom, flags); count = virDomainSnapshotNum(dom, flags);
} }
} else if (tree) { } else if (tree) {
numsnaps++; count++;
} }
} else { } else {
numsnaps = virDomainSnapshotNum(dom, flags); count = virDomainSnapshotNum(dom, flags);
/* Fall back to simulation if --roots was unsupported. */ /* Fall back to simulation if --roots was unsupported. */
/* XXX can we also emulate --leaves? */ /* XXX can we also emulate --leaves? */
if (numsnaps < 0 && last_error->code == VIR_ERR_INVALID_ARG && if (count < 0 && last_error->code == VIR_ERR_INVALID_ARG &&
(flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS)) { (flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS)) {
virFreeError(last_error); virFreeError(last_error);
last_error = NULL; last_error = NULL;
parent_filter = -1; parent_filter = -1;
flags &= ~VIR_DOMAIN_SNAPSHOT_LIST_ROOTS; flags &= ~VIR_DOMAIN_SNAPSHOT_LIST_ROOTS;
numsnaps = virDomainSnapshotNum(dom, flags); count = virDomainSnapshotNum(dom, flags);
} }
} }
if (numsnaps < 0) { if (count < 0) {
if (!last_error) if (!last_error)
vshError(ctl, _("missing support")); vshError(ctl, _("missing support"));
goto cleanup; goto cleanup;
@@ -16725,41 +16724,40 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
"------------------------------------------------------------\n"); "------------------------------------------------------------\n");
} }
if (!numsnaps) { if (!count) {
ret = true; ret = true;
goto cleanup; goto cleanup;
} }
if (VIR_ALLOC_N(names, numsnaps) < 0) if (VIR_ALLOC_N(names, count) < 0)
goto cleanup; goto cleanup;
if (from && !ctl->useSnapshotOld) { if (from && !ctl->useSnapshotOld) {
/* When mixing --from and --tree, we want to start the tree at the /* When mixing --from and --tree, we want to start the tree at the
* given snapshot. Without --tree, only list the children. */ * given snapshot. Without --tree, only list the children. */
if (tree) { if (tree) {
if (numsnaps) if (count)
actual = virDomainSnapshotListChildrenNames(start, names + 1, count = virDomainSnapshotListChildrenNames(start, names + 1,
numsnaps - 1, count - 1, flags);
flags); if (count >= 0) {
if (actual >= 0) { count++;
actual++;
names[0] = vshStrdup(ctl, from); names[0] = vshStrdup(ctl, from);
} }
} else { } else {
actual = virDomainSnapshotListChildrenNames(start, names, count = virDomainSnapshotListChildrenNames(start, names,
numsnaps, flags); count, flags);
} }
} else { } else {
actual = virDomainSnapshotListNames(dom, names, numsnaps, flags); count = virDomainSnapshotListNames(dom, names, count, flags);
} }
if (actual < 0) if (count < 0)
goto cleanup; goto cleanup;
qsort(&names[0], actual, sizeof(char*), namesorter); qsort(&names[0], count, sizeof(char*), namesorter);
if (tree || (from && ctl->useSnapshotOld)) { if (tree || (from && ctl->useSnapshotOld)) {
parents = vshCalloc(ctl, sizeof(char *), actual); parents = vshCalloc(ctl, sizeof(char *), count);
for (i = (from && !ctl->useSnapshotOld); i < actual; i++) { for (i = (from && !ctl->useSnapshotOld); i < count; i++) {
if (from && ctl->useSnapshotOld && STREQ(names[i], from)) { if (from && ctl->useSnapshotOld && STREQ(names[i], from)) {
start_index = i; start_index = i;
continue; continue;
@@ -16781,29 +16779,30 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
if (tree) { if (tree) {
struct vshTreeArray arrays = { names, parents }; struct vshTreeArray arrays = { names, parents };
for (i = 0 ; i < actual ; i++) { for (i = 0 ; i < count ; i++) {
if ((from && ctl->useSnapshotOld) ? STREQ(names[i], from) : if ((from && ctl->useSnapshotOld) ? STREQ(names[i], from) :
!parents[i] && !parents[i] &&
vshTreePrint(ctl, vshTreeArrayLookup, &arrays, actual, i) < 0) vshTreePrint(ctl, vshTreeArrayLookup, &arrays, count, i) < 0)
goto cleanup; goto cleanup;
} }
ret = true; ret = true;
goto cleanup; goto cleanup;
} else { }
if (ctl->useSnapshotOld && descendants) { if (ctl->useSnapshotOld && descendants) {
bool changed = false; bool changed = false;
/* Make multiple passes over the list - first pass NULLs /* Make multiple passes over the list - first pass NULLs out
* out all roots except start, remaining passes NULL out * all roots except start, remaining passes NULL out any entry
* any entry whose parent is not still in list. Also, we * whose parent is not still in list. Also, we NULL out
* NULL out parent when name is known to be in list. * parent when name is known to be in list. Sorry, this is
* Sorry, this is O(n^3) - hope your hierarchy isn't huge. */ * O(n^3) - hope your hierarchy isn't huge. */
if (start_index < 0) { if (start_index < 0) {
vshError(ctl, _("snapshot %s disappeared from list"), from); vshError(ctl, _("snapshot %s disappeared from list"), from);
goto cleanup; goto cleanup;
} }
for (i = 0; i < actual; i++) { for (i = 0; i < count; i++) {
if (i == start_index) if (i == start_index)
continue; continue;
if (!parents[i]) { if (!parents[i]) {
@@ -16819,13 +16818,13 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
} }
while (changed) { while (changed) {
changed = false; changed = false;
for (i = 0; i < actual; i++) { for (i = 0; i < count; i++) {
bool found = false; bool found = false;
int j; int j;
if (!names[i] || !parents[i]) if (!names[i] || !parents[i])
continue; continue;
for (j = 0; j < actual; j++) { for (j = 0; j < count; j++) {
if (!names[j] || i == j) if (!names[j] || i == j)
continue; continue;
if (STREQ(parents[i], names[j])) { if (STREQ(parents[i], names[j])) {
@@ -16844,7 +16843,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
VIR_FREE(names[start_index]); VIR_FREE(names[start_index]);
} }
for (i = 0; i < actual; i++) { for (i = 0; i < count; i++) {
if (from && ctl->useSnapshotOld && if (from && ctl->useSnapshotOld &&
(descendants ? !names[i] : STRNEQ_NULLABLE(parents[i], from))) (descendants ? !names[i] : STRNEQ_NULLABLE(parents[i], from)))
continue; continue;
@@ -16898,7 +16897,6 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
else else
vshPrint(ctl, " %-20s %-25s %s\n", names[i], timestr, state); vshPrint(ctl, " %-20s %-25s %s\n", names[i], timestr, state);
} }
}
ret = true; ret = true;
@@ -16913,7 +16911,7 @@ cleanup:
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
xmlFreeDoc(xml); xmlFreeDoc(xml);
VIR_FREE(doc); VIR_FREE(doc);
for (i = 0; i < actual; i++) { for (i = 0; i < count; i++) {
VIR_FREE(names[i]); VIR_FREE(names[i]);
if (parents) if (parents)
VIR_FREE(parents[i]); VIR_FREE(parents[i]);