mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-22 22:13:18 +00:00
virsh: Use virTypedParams* APIs in numatune
This commit is contained in:
parent
7786233009
commit
ec3e50644e
@ -7308,8 +7308,9 @@ cmdNumatune(vshControl * ctl, const vshCmd * cmd)
|
|||||||
{
|
{
|
||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
int nparams = 0;
|
int nparams = 0;
|
||||||
|
int maxparams = 0;
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
virTypedParameterPtr params = NULL, temp = NULL;
|
virTypedParameterPtr params = NULL;
|
||||||
const char *nodeset = NULL;
|
const char *nodeset = NULL;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
@ -7336,18 +7337,32 @@ cmdNumatune(vshControl * ctl, const vshCmd * cmd)
|
|||||||
|
|
||||||
if (vshCommandOptString(cmd, "nodeset", &nodeset) < 0) {
|
if (vshCommandOptString(cmd, "nodeset", &nodeset) < 0) {
|
||||||
vshError(ctl, "%s", _("Unable to parse nodeset."));
|
vshError(ctl, "%s", _("Unable to parse nodeset."));
|
||||||
virDomainFree(dom);
|
goto cleanup;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (nodeset)
|
if (nodeset &&
|
||||||
nparams++;
|
virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
||||||
|
VIR_DOMAIN_NUMA_NODESET, nodeset) < 0)
|
||||||
|
goto save_error;
|
||||||
|
|
||||||
if (vshCommandOptString(cmd, "mode", &mode) < 0) {
|
if (vshCommandOptString(cmd, "mode", &mode) < 0) {
|
||||||
vshError(ctl, "%s", _("Unable to parse mode."));
|
vshError(ctl, "%s", _("Unable to parse mode."));
|
||||||
virDomainFree(dom);
|
goto cleanup;
|
||||||
return false;
|
}
|
||||||
|
if (mode) {
|
||||||
|
int m;
|
||||||
|
/* Accept string or integer, in case server understands newer
|
||||||
|
* integer than what strings we were compiled with
|
||||||
|
*/
|
||||||
|
if ((m = virDomainNumatuneMemModeTypeFromString(mode)) < 0 &&
|
||||||
|
virStrToLong_i(mode, NULL, 0, &m) < 0) {
|
||||||
|
vshError(ctl, _("Invalid mode: %s"), mode);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virTypedParamsAddInt(¶ms, &nparams, &maxparams,
|
||||||
|
VIR_DOMAIN_NUMA_MODE, m) < 0)
|
||||||
|
goto save_error;
|
||||||
}
|
}
|
||||||
if (mode)
|
|
||||||
nparams++;
|
|
||||||
|
|
||||||
if (nparams == 0) {
|
if (nparams == 0) {
|
||||||
/* get the number of numa parameters */
|
/* get the number of numa parameters */
|
||||||
@ -7381,56 +7396,23 @@ cmdNumatune(vshControl * ctl, const vshCmd * cmd)
|
|||||||
VIR_FREE(str);
|
VIR_FREE(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = true;
|
|
||||||
} else {
|
} else {
|
||||||
/* set the numa parameters */
|
|
||||||
params = vshCalloc(ctl, nparams, sizeof(*params));
|
|
||||||
|
|
||||||
for (i = 0; i < nparams; i++) {
|
|
||||||
temp = ¶ms[i];
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Some magic here, this is used to fill the params structure with
|
|
||||||
* the valid arguments passed, after filling the particular
|
|
||||||
* argument we purposely make them 0, so on the next pass it goes
|
|
||||||
* to the next valid argument and so on.
|
|
||||||
*/
|
|
||||||
if (mode) {
|
|
||||||
/* Accept string or integer, in case server
|
|
||||||
* understands newer integer than what strings we were
|
|
||||||
* compiled with */
|
|
||||||
if ((temp->value.i =
|
|
||||||
virDomainNumatuneMemModeTypeFromString(mode)) < 0 &&
|
|
||||||
virStrToLong_i(mode, NULL, 0, &temp->value.i) < 0) {
|
|
||||||
vshError(ctl, _("Invalid mode: %s"), mode);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (!virStrcpy(temp->field, VIR_DOMAIN_NUMA_MODE,
|
|
||||||
sizeof(temp->field)))
|
|
||||||
goto cleanup;
|
|
||||||
temp->type = VIR_TYPED_PARAM_INT;
|
|
||||||
mode = NULL;
|
|
||||||
} else if (nodeset) {
|
|
||||||
temp->value.s = vshStrdup(ctl, nodeset);
|
|
||||||
temp->type = VIR_TYPED_PARAM_STRING;
|
|
||||||
if (!virStrcpy(temp->field, VIR_DOMAIN_NUMA_NODESET,
|
|
||||||
sizeof(temp->field)))
|
|
||||||
goto cleanup;
|
|
||||||
nodeset = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (virDomainSetNumaParameters(dom, params, nparams, flags) != 0)
|
if (virDomainSetNumaParameters(dom, params, nparams, flags) != 0)
|
||||||
vshError(ctl, "%s", _("Unable to change numa parameters"));
|
goto error;
|
||||||
else
|
|
||||||
ret = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = true;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virTypedParameterArrayClear(params, nparams);
|
virTypedParamsFree(params, nparams);
|
||||||
VIR_FREE(params);
|
|
||||||
virDomainFree(dom);
|
virDomainFree(dom);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
save_error:
|
||||||
|
vshSaveLibvirtError();
|
||||||
|
error:
|
||||||
|
vshError(ctl, "%s", _("Unable to change numa parameters"));
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user