mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-01 17:35:17 +00:00
virsh-domain: Fix @ret handling in cmdSetmem and cmdSetmaxmem
These functions initialize @ret to true and only after something fails either they call cleanup code (which consists only from virshDomainFree()) and return false, or they set ret = false and carry on (when the failure occurred close to cleanup code). Switch them to the usual pattern in which ret is initialized to failure, goto cleanup is used and ret is set to true only after everything succeeded. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
168190e19c
commit
01a2339e1f
@ -8996,7 +8996,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd)
|
||||
unsigned long long bytes = 0;
|
||||
unsigned long long max;
|
||||
unsigned long kibibytes = 0;
|
||||
bool ret = true;
|
||||
bool ret = false;
|
||||
bool config = vshCommandOptBool(cmd, "config");
|
||||
bool live = vshCommandOptBool(cmd, "live");
|
||||
bool current = vshCommandOptBool(cmd, "current");
|
||||
@ -9019,20 +9019,20 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd)
|
||||
max = 1024ull * ULONG_MAX;
|
||||
else
|
||||
max = ULONG_MAX;
|
||||
if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) {
|
||||
virshDomainFree(dom);
|
||||
return false;
|
||||
}
|
||||
if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0)
|
||||
goto cleanup;
|
||||
kibibytes = VIR_DIV_UP(bytes, 1024);
|
||||
|
||||
if (!current && !live && !config) {
|
||||
if (virDomainSetMemory(dom, kibibytes) != 0)
|
||||
ret = false;
|
||||
goto cleanup;
|
||||
} else {
|
||||
if (virDomainSetMemoryFlags(dom, kibibytes, flags) < 0)
|
||||
ret = false;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = true;
|
||||
cleanup:
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
@ -9074,7 +9074,7 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd)
|
||||
unsigned long long bytes = 0;
|
||||
unsigned long long max;
|
||||
unsigned long kibibytes = 0;
|
||||
bool ret = true;
|
||||
bool ret = false;
|
||||
bool config = vshCommandOptBool(cmd, "config");
|
||||
bool live = vshCommandOptBool(cmd, "live");
|
||||
bool current = vshCommandOptBool(cmd, "current");
|
||||
@ -9097,24 +9097,24 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd)
|
||||
max = 1024ull * ULONG_MAX;
|
||||
else
|
||||
max = ULONG_MAX;
|
||||
if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) {
|
||||
virshDomainFree(dom);
|
||||
return false;
|
||||
}
|
||||
if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0)
|
||||
goto cleanup;
|
||||
kibibytes = VIR_DIV_UP(bytes, 1024);
|
||||
|
||||
if (flags == 0) {
|
||||
if (virDomainSetMaxMemory(dom, kibibytes) != 0) {
|
||||
vshError(ctl, "%s", _("Unable to change MaxMemorySize"));
|
||||
ret = false;
|
||||
goto cleanup;
|
||||
}
|
||||
} else {
|
||||
if (virDomainSetMemoryFlags(dom, kibibytes, flags | VIR_DOMAIN_MEM_MAXIMUM) < 0) {
|
||||
vshError(ctl, "%s", _("Unable to change MaxMemorySize"));
|
||||
ret = false;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
ret = true;
|
||||
cleanup:
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user