]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh-nodedev: Refactor error paths, error messages and whitespace
authorPeter Krempa <pkrempa@redhat.com>
Mon, 21 Jan 2013 16:41:14 +0000 (17:41 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 4 Feb 2013 13:17:44 +0000 (14:17 +0100)
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.

tools/virsh-nodedev.c

index 8b4c75b0f08f1a05442a5eb81a506f87c7948dd4..f85bded7709c34a0ef980526fcebbadf7f71e857 100644 (file)
@@ -485,26 +485,28 @@ static bool
 cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd)
 {
     const char *name = NULL;
-    virNodeDevicePtr device;
-    char *xml;
+    virNodeDevicePtr device = NULL;
+    char *xml = NULL;
+    bool ret = false;
 
     if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
         return false;
+
     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;
     }
 
-    xml = virNodeDeviceGetXMLDesc(device, 0);
-    if (!xml) {
-        virNodeDeviceFree(device);
-        return false;
-    }
+    if (!(xml = virNodeDeviceGetXMLDesc(device, 0)))
+        goto cleanup;
 
     vshPrint(ctl, "%s\n", xml);
+    ret = true;
+
+cleanup:
     VIR_FREE(xml);
     virNodeDeviceFree(device);
-    return true;
+    return ret;
 }
 
 /*
@@ -535,8 +537,9 @@ cmdNodeDeviceDetach(vshControl *ctl, const vshCmd *cmd)
 
     if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
         return false;
+
     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;
     }
 
@@ -548,6 +551,7 @@ cmdNodeDeviceDetach(vshControl *ctl, const vshCmd *cmd)
         vshError(ctl, _("Failed to detach device %s"), name);
         ret = false;
     }
+
     virNodeDeviceFree(device);
     return ret;
 }
@@ -580,8 +584,9 @@ cmdNodeDeviceReAttach(vshControl *ctl, const vshCmd *cmd)
 
     if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
         return false;
+
     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;
     }
 
@@ -591,6 +596,7 @@ cmdNodeDeviceReAttach(vshControl *ctl, const vshCmd *cmd)
         vshError(ctl, _("Failed to re-attach device %s"), name);
         ret = false;
     }
+
     virNodeDeviceFree(device);
     return ret;
 }
@@ -623,8 +629,9 @@ cmdNodeDeviceReset(vshControl *ctl, const vshCmd *cmd)
 
     if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
         return false;
+
     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;
     }
 
@@ -634,6 +641,7 @@ cmdNodeDeviceReset(vshControl *ctl, const vshCmd *cmd)
         vshError(ctl, _("Failed to reset device %s"), name);
         ret = false;
     }
+
     virNodeDeviceFree(device);
     return ret;
 }