mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
virsh: Remove unnecessary else branches
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>
This commit is contained in:
parent
a4056d52eb
commit
842cfc9d41
@ -1024,13 +1024,12 @@ cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
|
|||||||
if (!dev)
|
if (!dev)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virNodeDeviceUndefine(dev, 0) == 0) {
|
if (virNodeDeviceUndefine(dev, 0) < 0) {
|
||||||
vshPrintExtra(ctl, _("Undefined node device '%s'\n"), device_value);
|
|
||||||
} else {
|
|
||||||
vshError(ctl, _("Failed to undefine node device '%s'"), device_value);
|
vshError(ctl, _("Failed to undefine node device '%s'"), device_value);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vshPrintExtra(ctl, _("Undefined node device '%s'\n"), device_value);
|
||||||
ret = true;
|
ret = true;
|
||||||
cleanup:
|
cleanup:
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -411,14 +411,14 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((vol = virStorageVolCreateXML(pool, buffer, flags))) {
|
if (!(vol = virStorageVolCreateXML(pool, buffer, flags))) {
|
||||||
vshPrintExtra(ctl, _("Vol %s created from %s\n"),
|
|
||||||
virStorageVolGetName(vol), from);
|
|
||||||
ret = true;
|
|
||||||
} else {
|
|
||||||
vshError(ctl, _("Failed to create vol from %s"), from);
|
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:
|
cleanup:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -489,14 +489,13 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
newvol = virStorageVolCreateXMLFrom(pool, buffer, inputvol, flags);
|
newvol = virStorageVolCreateXMLFrom(pool, buffer, inputvol, flags);
|
||||||
|
|
||||||
if (newvol != NULL) {
|
if (!newvol) {
|
||||||
vshPrintExtra(ctl, _("Vol %s created from input vol %s\n"),
|
|
||||||
virStorageVolGetName(newvol), virStorageVolGetName(inputvol));
|
|
||||||
} else {
|
|
||||||
vshError(ctl, _("Failed to create vol from %s"), from);
|
vshError(ctl, _("Failed to create vol from %s"), from);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vshPrintExtra(ctl, _("Vol %s created from input vol %s\n"),
|
||||||
|
virStorageVolGetName(newvol), virStorageVolGetName(inputvol));
|
||||||
ret = true;
|
ret = true;
|
||||||
cleanup:
|
cleanup:
|
||||||
return ret;
|
return ret;
|
||||||
@ -1147,20 +1146,19 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virStorageVolResize(vol, capacity, flags) == 0) {
|
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 {
|
|
||||||
vshError(ctl,
|
vshError(ctl,
|
||||||
delta ? _("Failed to change size of volume '%s' by %s")
|
delta ? _("Failed to change size of volume '%s' by %s")
|
||||||
: _("Failed to change size of volume '%s' to %s"),
|
: _("Failed to change size of volume '%s' to %s"),
|
||||||
virStorageVolGetName(vol), capacityStr);
|
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:
|
cleanup:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user