]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Remove unnecessary else branches
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 8 Nov 2021 15:09:48 +0000 (16:09 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 12 Nov 2021 16:17:19 +0000 (17:17 +0100)
In a few cases we call a public API, wrapped in an if() statement
with both branches written out explicitly. The error branch jumps
onto cleanup label, while the successful prints out a message.
Right after these ifs there's 'ret = true;' and the cleanup
label. The code is a bit more readable if only the error branch
is kept and printing happens at the same level as setting the ret
variable.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Kristína Hanicová <khanicov@redhat.com>
tools/virsh-nodedev.c
tools/virsh-volume.c

index 1ad8db7a3f459609a8960eb9891b6208afcd363a..424865962f5fc99a6b4b044cbb482464a7a00eb3 100644 (file)
@@ -1024,13 +1024,12 @@ cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
     if (!dev)
         goto cleanup;
 
-    if (virNodeDeviceUndefine(dev, 0) == 0) {
-        vshPrintExtra(ctl, _("Undefined node device '%s'\n"), device_value);
-    } else {
+    if (virNodeDeviceUndefine(dev, 0) < 0) {
         vshError(ctl, _("Failed to undefine node device '%s'"), device_value);
         goto cleanup;
     }
 
+    vshPrintExtra(ctl, _("Undefined node device '%s'\n"), device_value);
     ret = true;
  cleanup:
     return ret;
index 4c8e841701b382858bd60eff3e7e5fc79857eabe..12773d900bf0e556790a59d7a152c02218a40432 100644 (file)
@@ -411,14 +411,14 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
-    if ((vol = virStorageVolCreateXML(pool, buffer, flags))) {
-        vshPrintExtra(ctl, _("Vol %s created from %s\n"),
-                      virStorageVolGetName(vol), from);
-        ret = true;
-    } else {
+    if (!(vol = virStorageVolCreateXML(pool, buffer, flags))) {
         vshError(ctl, _("Failed to create vol from %s"), from);
+        goto cleanup;
     }
 
+    vshPrintExtra(ctl, _("Vol %s created from %s\n"),
+                  virStorageVolGetName(vol), from);
+    ret = true;
  cleanup:
     return ret;
 }
@@ -489,14 +489,13 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
 
     newvol = virStorageVolCreateXMLFrom(pool, buffer, inputvol, flags);
 
-    if (newvol != NULL) {
-        vshPrintExtra(ctl, _("Vol %s created from input vol %s\n"),
-                      virStorageVolGetName(newvol), virStorageVolGetName(inputvol));
-    } else {
+    if (!newvol) {
         vshError(ctl, _("Failed to create vol from %s"), from);
         goto cleanup;
     }
 
+    vshPrintExtra(ctl, _("Vol %s created from input vol %s\n"),
+                  virStorageVolGetName(newvol), virStorageVolGetName(inputvol));
     ret = true;
  cleanup:
     return ret;
@@ -1147,20 +1146,19 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
-    if (virStorageVolResize(vol, capacity, flags) == 0) {
-        vshPrintExtra(ctl,
-                      delta ? _("Size of volume '%s' successfully changed by %s\n")
-                      : _("Size of volume '%s' successfully changed to %s\n"),
-                      virStorageVolGetName(vol), capacityStr);
-        ret = true;
-    } else {
+    if (virStorageVolResize(vol, capacity, flags) < 0) {
         vshError(ctl,
                  delta ? _("Failed to change size of volume '%s' by %s")
                  : _("Failed to change size of volume '%s' to %s"),
                  virStorageVolGetName(vol), capacityStr);
-        ret = false;
+        goto cleanup;
     }
 
+    vshPrintExtra(ctl,
+                  delta ? _("Size of volume '%s' successfully changed by %s\n")
+                  : _("Size of volume '%s' successfully changed to %s\n"),
+                  virStorageVolGetName(vol), capacityStr);
+    ret = true;
  cleanup:
     return ret;
 }