mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
virsh: fix range of memtune command
* tools/virsh.c (cmdMemtune): Use long long for memory sizes. Simplify allocation, and plug memory leak.
This commit is contained in:
parent
c1564268c4
commit
009035ffad
@ -2905,7 +2905,7 @@ static int
|
|||||||
cmdMemtune(vshControl * ctl, const vshCmd * cmd)
|
cmdMemtune(vshControl * ctl, const vshCmd * cmd)
|
||||||
{
|
{
|
||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
int hard_limit, soft_limit, swap_hard_limit, min_guarantee;
|
long long hard_limit, soft_limit, swap_hard_limit, min_guarantee;
|
||||||
int nparams = 0;
|
int nparams = 0;
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
virMemoryParameterPtr params = NULL, temp = NULL;
|
virMemoryParameterPtr params = NULL, temp = NULL;
|
||||||
@ -2918,24 +2918,22 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
hard_limit =
|
hard_limit =
|
||||||
vshCommandOptInt(cmd, VIR_DOMAIN_MEMORY_HARD_LIMIT, &hard_limit);
|
vshCommandOptLongLong(cmd, VIR_DOMAIN_MEMORY_HARD_LIMIT, NULL);
|
||||||
if (hard_limit)
|
if (hard_limit)
|
||||||
nparams++;
|
nparams++;
|
||||||
|
|
||||||
soft_limit =
|
soft_limit =
|
||||||
vshCommandOptInt(cmd, VIR_DOMAIN_MEMORY_SOFT_LIMIT, &soft_limit);
|
vshCommandOptLongLong(cmd, VIR_DOMAIN_MEMORY_SOFT_LIMIT, NULL);
|
||||||
if (soft_limit)
|
if (soft_limit)
|
||||||
nparams++;
|
nparams++;
|
||||||
|
|
||||||
swap_hard_limit =
|
swap_hard_limit =
|
||||||
vshCommandOptInt(cmd, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT,
|
vshCommandOptLongLong(cmd, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT, NULL);
|
||||||
&swap_hard_limit);
|
|
||||||
if (swap_hard_limit)
|
if (swap_hard_limit)
|
||||||
nparams++;
|
nparams++;
|
||||||
|
|
||||||
min_guarantee =
|
min_guarantee =
|
||||||
vshCommandOptInt(cmd, VIR_DOMAIN_MEMORY_MIN_GUARANTEE,
|
vshCommandOptLongLong(cmd, VIR_DOMAIN_MEMORY_MIN_GUARANTEE, NULL);
|
||||||
&min_guarantee);
|
|
||||||
if (min_guarantee)
|
if (min_guarantee)
|
||||||
nparams++;
|
nparams++;
|
||||||
|
|
||||||
@ -2954,8 +2952,7 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* now go get all the memory parameters */
|
/* now go get all the memory parameters */
|
||||||
params = vshMalloc(ctl, sizeof(virMemoryParameter) * nparams);
|
params = vshCalloc(ctl, nparams, sizeof(*params));
|
||||||
memset(params, 0, sizeof(virMemoryParameter) * nparams);
|
|
||||||
if (virDomainGetMemoryParameters(dom, params, &nparams, 0) != 0) {
|
if (virDomainGetMemoryParameters(dom, params, &nparams, 0) != 0) {
|
||||||
vshError(ctl, "%s", _("Unable to get memory parameters"));
|
vshError(ctl, "%s", _("Unable to get memory parameters"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -2995,9 +2992,8 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
|
|||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
} else {
|
} else {
|
||||||
/* set the memory parameters */
|
/* set the memory parameters */
|
||||||
params = vshMalloc(ctl, sizeof(virMemoryParameter) * nparams);
|
params = vshCalloc(ctl, nparams, sizeof(*params));
|
||||||
|
|
||||||
memset(params, 0, sizeof(virMemoryParameter) * nparams);
|
|
||||||
for (i = 0; i < nparams; i++) {
|
for (i = 0; i < nparams; i++) {
|
||||||
temp = ¶ms[i];
|
temp = ¶ms[i];
|
||||||
temp->type = VIR_DOMAIN_MEMORY_PARAM_ULLONG;
|
temp->type = VIR_DOMAIN_MEMORY_PARAM_ULLONG;
|
||||||
@ -3037,6 +3033,7 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
VIR_FREE(params);
|
||||||
virDomainFree(dom);
|
virDomainFree(dom);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user