mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
virsh: Slightly rework cmdDomblklist
Let's move some variables from an inside loop to global function declaration header block. It's going to be easier for next patches. At the same time, order the cleanup calls at the function's end so it's easier to track which variables are freed and which not. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
ea65fdba7f
commit
0efe8f5065
@ -486,6 +486,10 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
|
|||||||
xmlNodePtr *disks = NULL;
|
xmlNodePtr *disks = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
bool details = false;
|
bool details = false;
|
||||||
|
char *type = NULL;
|
||||||
|
char *device = NULL;
|
||||||
|
char *target = NULL;
|
||||||
|
char *source = NULL;
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "inactive"))
|
if (vshCommandOptBool(cmd, "inactive"))
|
||||||
flags |= VIR_DOMAIN_XML_INACTIVE;
|
flags |= VIR_DOMAIN_XML_INACTIVE;
|
||||||
@ -516,11 +520,6 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
|
|||||||
vshPrintExtra(ctl, "------------------------------------------------\n");
|
vshPrintExtra(ctl, "------------------------------------------------\n");
|
||||||
|
|
||||||
for (i = 0; i < ndisks; i++) {
|
for (i = 0; i < ndisks; i++) {
|
||||||
char *type = NULL;
|
|
||||||
char *device = NULL;
|
|
||||||
char *target;
|
|
||||||
char *source;
|
|
||||||
|
|
||||||
ctxt->node = disks[i];
|
ctxt->node = disks[i];
|
||||||
|
|
||||||
if (details) {
|
if (details) {
|
||||||
@ -528,8 +527,6 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
|
|||||||
device = virXPathString("string(./@device)", ctxt);
|
device = virXPathString("string(./@device)", ctxt);
|
||||||
if (!type || !device) {
|
if (!type || !device) {
|
||||||
vshPrint(ctl, "unable to query block list details");
|
vshPrint(ctl, "unable to query block list details");
|
||||||
VIR_FREE(type);
|
|
||||||
VIR_FREE(device);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -537,8 +534,6 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
|
|||||||
target = virXPathString("string(./target/@dev)", ctxt);
|
target = virXPathString("string(./target/@dev)", ctxt);
|
||||||
if (!target) {
|
if (!target) {
|
||||||
vshError(ctl, "unable to query block list");
|
vshError(ctl, "unable to query block list");
|
||||||
VIR_FREE(type);
|
|
||||||
VIR_FREE(device);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
source = virXPathString("string(./source/@file"
|
source = virXPathString("string(./source/@file"
|
||||||
@ -549,24 +544,28 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (details) {
|
if (details) {
|
||||||
vshPrint(ctl, "%-10s %-10s %-10s %s\n", type, device,
|
vshPrint(ctl, "%-10s %-10s %-10s %s\n", type, device,
|
||||||
target, source ? source : "-");
|
target, source ? source : "-");
|
||||||
VIR_FREE(type);
|
|
||||||
VIR_FREE(device);
|
|
||||||
} else {
|
} else {
|
||||||
vshPrint(ctl, "%-10s %s\n", target, source ? source : "-");
|
vshPrint(ctl, "%-10s %s\n", target, source ? source : "-");
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(target);
|
|
||||||
VIR_FREE(source);
|
VIR_FREE(source);
|
||||||
|
VIR_FREE(target);
|
||||||
|
VIR_FREE(device);
|
||||||
|
VIR_FREE(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
VIR_FREE(source);
|
||||||
|
VIR_FREE(target);
|
||||||
|
VIR_FREE(device);
|
||||||
|
VIR_FREE(type);
|
||||||
VIR_FREE(disks);
|
VIR_FREE(disks);
|
||||||
virDomainFree(dom);
|
|
||||||
VIR_FREE(xml);
|
|
||||||
xmlFreeDoc(xmldoc);
|
|
||||||
xmlXPathFreeContext(ctxt);
|
xmlXPathFreeContext(ctxt);
|
||||||
|
xmlFreeDoc(xmldoc);
|
||||||
|
VIR_FREE(xml);
|
||||||
|
virDomainFree(dom);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user