mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
virsh: Use virTypedParams* APIs in blkdeviotune
This commit is contained in:
parent
54dd75fd97
commit
a8fca0da06
@ -1043,9 +1043,9 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
|
|||||||
{
|
{
|
||||||
virDomainPtr dom = NULL;
|
virDomainPtr dom = NULL;
|
||||||
const char *name, *disk;
|
const char *name, *disk;
|
||||||
unsigned long long total_bytes_sec = 0, read_bytes_sec = 0, write_bytes_sec = 0;
|
unsigned long long value;
|
||||||
unsigned long long total_iops_sec = 0, read_iops_sec = 0, write_iops_sec = 0;
|
|
||||||
int nparams = 0;
|
int nparams = 0;
|
||||||
|
int maxparams = 0;
|
||||||
virTypedParameterPtr params = NULL;
|
virTypedParameterPtr params = NULL;
|
||||||
unsigned int flags = 0, i = 0;
|
unsigned int flags = 0, i = 0;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
@ -1073,62 +1073,61 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptString(cmd, "device", &disk) < 0)
|
if (vshCommandOptString(cmd, "device", &disk) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((rv = vshCommandOptULongLong(cmd, "total-bytes-sec",
|
if ((rv = vshCommandOptULongLong(cmd, "total-bytes-sec", &value)) < 0) {
|
||||||
&total_bytes_sec)) < 0) {
|
goto interror;
|
||||||
vshError(ctl, "%s",
|
|
||||||
_("Unable to parse integer parameter"));
|
|
||||||
goto cleanup;
|
|
||||||
} else if (rv > 0) {
|
} else if (rv > 0) {
|
||||||
nparams++;
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
||||||
|
VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC,
|
||||||
|
value) < 0)
|
||||||
|
goto save_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rv = vshCommandOptULongLong(cmd, "read-bytes-sec",
|
if ((rv = vshCommandOptULongLong(cmd, "read-bytes-sec", &value)) < 0) {
|
||||||
&read_bytes_sec)) < 0) {
|
goto interror;
|
||||||
vshError(ctl, "%s",
|
|
||||||
_("Unable to parse integer parameter"));
|
|
||||||
goto cleanup;
|
|
||||||
} else if (rv > 0) {
|
} else if (rv > 0) {
|
||||||
nparams++;
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
||||||
|
VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC,
|
||||||
|
value) < 0)
|
||||||
|
goto save_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rv = vshCommandOptULongLong(cmd, "write-bytes-sec",
|
if ((rv = vshCommandOptULongLong(cmd, "write-bytes-sec", &value)) < 0) {
|
||||||
&write_bytes_sec)) < 0) {
|
goto interror;
|
||||||
vshError(ctl, "%s",
|
|
||||||
_("Unable to parse integer parameter"));
|
|
||||||
goto cleanup;
|
|
||||||
} else if (rv > 0) {
|
} else if (rv > 0) {
|
||||||
nparams++;
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
||||||
|
VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC,
|
||||||
|
value) < 0)
|
||||||
|
goto save_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rv = vshCommandOptULongLong(cmd, "total-iops-sec",
|
if ((rv = vshCommandOptULongLong(cmd, "total-iops-sec", &value)) < 0) {
|
||||||
&total_iops_sec)) < 0) {
|
goto interror;
|
||||||
vshError(ctl, "%s",
|
|
||||||
_("Unable to parse integer parameter"));
|
|
||||||
goto cleanup;
|
|
||||||
} else if (rv > 0) {
|
} else if (rv > 0) {
|
||||||
nparams++;
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
||||||
|
VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC,
|
||||||
|
value) < 0)
|
||||||
|
goto save_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rv = vshCommandOptULongLong(cmd, "read-iops-sec",
|
if ((rv = vshCommandOptULongLong(cmd, "read-iops-sec", &value)) < 0) {
|
||||||
&read_iops_sec)) < 0) {
|
goto interror;
|
||||||
vshError(ctl, "%s",
|
|
||||||
_("Unable to parse integer parameter"));
|
|
||||||
goto cleanup;
|
|
||||||
} else if (rv > 0) {
|
} else if (rv > 0) {
|
||||||
nparams++;
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
||||||
|
VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC,
|
||||||
|
value) < 0)
|
||||||
|
goto save_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rv = vshCommandOptULongLong(cmd, "write-iops-sec",
|
if ((rv = vshCommandOptULongLong(cmd, "write-iops-sec", &value)) < 0) {
|
||||||
&write_iops_sec)) < 0) {
|
goto interror;
|
||||||
vshError(ctl, "%s",
|
|
||||||
_("Unable to parse integer parameter"));
|
|
||||||
goto cleanup;
|
|
||||||
} else if (rv > 0) {
|
} else if (rv > 0) {
|
||||||
nparams++;
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
||||||
|
VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC,
|
||||||
|
value) < 0)
|
||||||
|
goto save_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nparams == 0) {
|
if (nparams == 0) {
|
||||||
|
|
||||||
if (virDomainGetBlockIoTune(dom, NULL, NULL, &nparams, flags) != 0) {
|
if (virDomainGetBlockIoTune(dom, NULL, NULL, &nparams, flags) != 0) {
|
||||||
vshError(ctl, "%s",
|
vshError(ctl, "%s",
|
||||||
_("Unable to get number of block I/O throttle parameters"));
|
_("Unable to get number of block I/O throttle parameters"));
|
||||||
@ -1153,56 +1152,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
|
|||||||
vshPrint(ctl, "%-15s: %s\n", params[i].field, str);
|
vshPrint(ctl, "%-15s: %s\n", params[i].field, str);
|
||||||
VIR_FREE(str);
|
VIR_FREE(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = true;
|
|
||||||
goto cleanup;
|
|
||||||
} else {
|
} else {
|
||||||
/* Set the block I/O throttle, match by opt since parameters can be 0 */
|
|
||||||
params = vshCalloc(ctl, nparams, sizeof(*params));
|
|
||||||
i = 0;
|
|
||||||
|
|
||||||
if (i < nparams && vshCommandOptBool(cmd, "total-bytes-sec") &&
|
|
||||||
virTypedParameterAssign(¶ms[i++],
|
|
||||||
VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC,
|
|
||||||
VIR_TYPED_PARAM_ULLONG,
|
|
||||||
total_bytes_sec) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (i < nparams && vshCommandOptBool(cmd, "read-bytes-sec") &&
|
|
||||||
virTypedParameterAssign(¶ms[i++],
|
|
||||||
VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC,
|
|
||||||
VIR_TYPED_PARAM_ULLONG,
|
|
||||||
read_bytes_sec) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (i < nparams && vshCommandOptBool(cmd, "write-bytes-sec") &&
|
|
||||||
virTypedParameterAssign(¶ms[i++],
|
|
||||||
VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC,
|
|
||||||
VIR_TYPED_PARAM_ULLONG,
|
|
||||||
write_bytes_sec) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (i < nparams && vshCommandOptBool(cmd, "total-iops-sec") &&
|
|
||||||
virTypedParameterAssign(¶ms[i++],
|
|
||||||
VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC,
|
|
||||||
VIR_TYPED_PARAM_ULLONG,
|
|
||||||
total_iops_sec) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (i < nparams && vshCommandOptBool(cmd, "read-iops-sec") &&
|
|
||||||
virTypedParameterAssign(¶ms[i++],
|
|
||||||
VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC,
|
|
||||||
VIR_TYPED_PARAM_ULLONG,
|
|
||||||
read_iops_sec) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (i < nparams && vshCommandOptBool(cmd, "write-iops-sec") &&
|
|
||||||
virTypedParameterAssign(¶ms[i++],
|
|
||||||
VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC,
|
|
||||||
VIR_TYPED_PARAM_ULLONG,
|
|
||||||
write_iops_sec) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (virDomainSetBlockIoTune(dom, disk, params, nparams, flags) < 0)
|
if (virDomainSetBlockIoTune(dom, disk, params, nparams, flags) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -1210,13 +1160,19 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
|
|||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(params);
|
virTypedParamsFree(params, nparams);
|
||||||
virDomainFree(dom);
|
virDomainFree(dom);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
save_error:
|
||||||
|
vshSaveLibvirtError();
|
||||||
error:
|
error:
|
||||||
vshError(ctl, "%s", _("Unable to change block I/O throttle"));
|
vshError(ctl, "%s", _("Unable to change block I/O throttle"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
interror:
|
||||||
|
vshError(ctl, "%s", _("Unable to parse integer parameter"));
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user