提交 23b1e5c0 编写于 作者: C Chris Lalancette

Better error reporting in virsh.

When hitting failures in virsh, a common idiom is
to jump to a cleanup label, free some resources, and
then return a FALSE error code to vshCommandRun.
In theory, vshCommandRun is then supposed to print
out the last error.  The problem is that many of
the cleanup paths have library calls to free resources,
and all of those library calls clear out the last error.
This is leading to situations where no error is being
reported at all.

This patch remedies the situation somewhat by
printing out the errors inside the command methods
themselves when we know it will go through a cleanup
path that will lose the error.
Signed-off-by: NChris Lalancette <clalance@redhat.com>
上级 86fe2ba6
......@@ -2622,9 +2622,8 @@ cmdDomXMLFromNative(vshControl *ctl, const vshCmd *cmd)
format = vshCommandOptString(cmd, "format", NULL);
configFile = vshCommandOptString(cmd, "config", NULL);
if (virFileReadAll(configFile, 1024*1024, &configData) < 0) {
if (virFileReadAll(configFile, 1024*1024, &configData) < 0)
return FALSE;
}
xmlData = virConnectDomainXMLFromNative(ctl->conn, format, configData, flags);
if (xmlData != NULL) {
......@@ -2668,9 +2667,8 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd)
format = vshCommandOptString(cmd, "format", NULL);
xmlFile = vshCommandOptString(cmd, "xml", NULL);
if (virFileReadAll(xmlFile, 1024*1024, &xmlData) < 0) {
if (virFileReadAll(xmlFile, 1024*1024, &xmlData) < 0)
return FALSE;
}
configData = virConnectDomainXMLToNative(ctl->conn, format, xmlData, flags);
if (configData != NULL) {
......@@ -4329,9 +4327,8 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd)
return FALSE;
}
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
return FALSE;
}
dev = virNodeDeviceCreateXML(ctl->conn, buffer, 0);
VIR_FREE(buffer);
......@@ -5426,6 +5423,7 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
}
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
virshReportError(ctl);
virStoragePoolFree(pool);
return FALSE;
}
......@@ -5487,6 +5485,7 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
virshReportError(ctl);
goto cleanup;
}
......@@ -6927,6 +6926,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
}
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
virshReportError(ctl);
virDomainFree(dom);
return FALSE;
}
......@@ -6994,6 +6994,7 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
}
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
virshReportError(ctl);
virDomainFree(dom);
return FALSE;
}
......@@ -7061,6 +7062,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd)
}
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
virshReportError(ctl);
virDomainFree(dom);
return FALSE;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册