提交 e9dc0739 编写于 作者: P Peter Krempa

virsh-nodedev: Refactor error paths, error messages and whitespace

This patch adds some empty lines to separate blocks of code, cleans up
unnecessary error message constructs in cmdNodeDeviceDetach,
cmdNodeDeviceReAttach, cmdNodeDeviceReset and refactors error paths in
cmdNodeDeviceDumpXML.
上级 7c5c51d1
...@@ -485,26 +485,28 @@ static bool ...@@ -485,26 +485,28 @@ static bool
cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd) cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd)
{ {
const char *name = NULL; const char *name = NULL;
virNodeDevicePtr device; virNodeDevicePtr device = NULL;
char *xml; char *xml = NULL;
bool ret = false;
if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0) if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
return false; return false;
if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) { if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
vshError(ctl, "%s '%s'", _("Could not find matching device"), name); vshError(ctl, _("Could not find matching device '%s'"), name);
return false; return false;
} }
xml = virNodeDeviceGetXMLDesc(device, 0); if (!(xml = virNodeDeviceGetXMLDesc(device, 0)))
if (!xml) { goto cleanup;
virNodeDeviceFree(device);
return false;
}
vshPrint(ctl, "%s\n", xml); vshPrint(ctl, "%s\n", xml);
ret = true;
cleanup:
VIR_FREE(xml); VIR_FREE(xml);
virNodeDeviceFree(device); virNodeDeviceFree(device);
return true; return ret;
} }
/* /*
...@@ -535,8 +537,9 @@ cmdNodeDeviceDetach(vshControl *ctl, const vshCmd *cmd) ...@@ -535,8 +537,9 @@ cmdNodeDeviceDetach(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0) if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
return false; return false;
if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) { if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
vshError(ctl, "%s '%s'", _("Could not find matching device"), name); vshError(ctl, _("Could not find matching device '%s'"), name);
return false; return false;
} }
...@@ -548,6 +551,7 @@ cmdNodeDeviceDetach(vshControl *ctl, const vshCmd *cmd) ...@@ -548,6 +551,7 @@ cmdNodeDeviceDetach(vshControl *ctl, const vshCmd *cmd)
vshError(ctl, _("Failed to detach device %s"), name); vshError(ctl, _("Failed to detach device %s"), name);
ret = false; ret = false;
} }
virNodeDeviceFree(device); virNodeDeviceFree(device);
return ret; return ret;
} }
...@@ -580,8 +584,9 @@ cmdNodeDeviceReAttach(vshControl *ctl, const vshCmd *cmd) ...@@ -580,8 +584,9 @@ cmdNodeDeviceReAttach(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0) if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
return false; return false;
if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) { if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
vshError(ctl, "%s '%s'", _("Could not find matching device"), name); vshError(ctl, _("Could not find matching device '%s'"), name);
return false; return false;
} }
...@@ -591,6 +596,7 @@ cmdNodeDeviceReAttach(vshControl *ctl, const vshCmd *cmd) ...@@ -591,6 +596,7 @@ cmdNodeDeviceReAttach(vshControl *ctl, const vshCmd *cmd)
vshError(ctl, _("Failed to re-attach device %s"), name); vshError(ctl, _("Failed to re-attach device %s"), name);
ret = false; ret = false;
} }
virNodeDeviceFree(device); virNodeDeviceFree(device);
return ret; return ret;
} }
...@@ -623,8 +629,9 @@ cmdNodeDeviceReset(vshControl *ctl, const vshCmd *cmd) ...@@ -623,8 +629,9 @@ cmdNodeDeviceReset(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0) if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
return false; return false;
if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) { if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
vshError(ctl, "%s '%s'", _("Could not find matching device"), name); vshError(ctl, _("Could not find matching device '%s'"), name);
return false; return false;
} }
...@@ -634,6 +641,7 @@ cmdNodeDeviceReset(vshControl *ctl, const vshCmd *cmd) ...@@ -634,6 +641,7 @@ cmdNodeDeviceReset(vshControl *ctl, const vshCmd *cmd)
vshError(ctl, _("Failed to reset device %s"), name); vshError(ctl, _("Failed to reset device %s"), name);
ret = false; ret = false;
} }
virNodeDeviceFree(device); virNodeDeviceFree(device);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册