mirror of https://gitee.com/openkylin/libvirt.git
util: vircgroupv1: add support for BFQ blkio files
In kernel 4.12 there was introduced new BFQ scheduler and in kernel 5.0 the old CFQ scheduler was removed. This has an implication on the cgroups file names. If the CFQ controller is enabled we use these two files: blkio.weight blkio.weight_device The new BFQ controller expose only one file with different name: blkio.bfq.weight The reason is that BFQ controller doesn't support per-device weight. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
c23829f18a
commit
035ebe9390
|
@ -949,10 +949,33 @@ static int
|
||||||
virCgroupV1SetBlkioWeight(virCgroupPtr group,
|
virCgroupV1SetBlkioWeight(virCgroupPtr group,
|
||||||
unsigned int weight)
|
unsigned int weight)
|
||||||
{
|
{
|
||||||
return virCgroupSetValueU64(group,
|
VIR_AUTOFREE(char *) path = NULL;
|
||||||
VIR_CGROUP_CONTROLLER_BLKIO,
|
VIR_AUTOFREE(char *) value = NULL;
|
||||||
"blkio.weight",
|
|
||||||
weight);
|
if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
|
||||||
|
"blkio.bfq.weight", &path) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!virFileExists(path)) {
|
||||||
|
VIR_FREE(path);
|
||||||
|
|
||||||
|
if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
|
||||||
|
"blkio.weight", &path) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!virFileExists(path)) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
|
_("blkio device weight is valid only for bfq or cfq scheduler"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virAsprintf(&value, "%u", weight) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return virCgroupSetValueRaw(path, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -960,14 +983,40 @@ static int
|
||||||
virCgroupV1GetBlkioWeight(virCgroupPtr group,
|
virCgroupV1GetBlkioWeight(virCgroupPtr group,
|
||||||
unsigned int *weight)
|
unsigned int *weight)
|
||||||
{
|
{
|
||||||
unsigned long long tmp;
|
VIR_AUTOFREE(char *) path = NULL;
|
||||||
int ret;
|
VIR_AUTOFREE(char *) value = NULL;
|
||||||
ret = virCgroupGetValueU64(group,
|
|
||||||
VIR_CGROUP_CONTROLLER_BLKIO,
|
if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
|
||||||
"blkio.weight", &tmp);
|
"blkio.bfq.weight", &path) < 0) {
|
||||||
if (ret == 0)
|
return -1;
|
||||||
*weight = tmp;
|
}
|
||||||
return ret;
|
|
||||||
|
if (!virFileExists(path)) {
|
||||||
|
VIR_FREE(path);
|
||||||
|
|
||||||
|
if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
|
||||||
|
"blkio.weight", &path) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!virFileExists(path)) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
|
_("blkio device weight is valid only for bfq or cfq scheduler"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virCgroupGetValueRaw(path, &value) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (virStrToLong_ui(value, NULL, 10, weight) < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Unable to parse '%s' as an integer"),
|
||||||
|
value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1156,41 +1205,58 @@ virCgroupV1GetBlkioIoDeviceServiced(virCgroupPtr group,
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virCgroupV1SetBlkioDeviceWeight(virCgroupPtr group,
|
virCgroupV1SetBlkioDeviceWeight(virCgroupPtr group,
|
||||||
const char *path,
|
const char *devPath,
|
||||||
unsigned int weight)
|
unsigned int weight)
|
||||||
{
|
{
|
||||||
VIR_AUTOFREE(char *) str = NULL;
|
VIR_AUTOFREE(char *) str = NULL;
|
||||||
VIR_AUTOFREE(char *) blkstr = NULL;
|
VIR_AUTOFREE(char *) blkstr = NULL;
|
||||||
|
VIR_AUTOFREE(char *) path = NULL;
|
||||||
|
|
||||||
if (!(blkstr = virCgroupGetBlockDevString(path)))
|
if (!(blkstr = virCgroupGetBlockDevString(devPath)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
|
if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return virCgroupSetValueStr(group,
|
if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
|
||||||
VIR_CGROUP_CONTROLLER_BLKIO,
|
"blkio.weight_device", &path) < 0) {
|
||||||
"blkio.weight_device",
|
return -1;
|
||||||
str);
|
}
|
||||||
|
|
||||||
|
if (!virFileExists(path)) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
|
_("blkio device weight is valid only for cfq scheduler"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return virCgroupSetValueRaw(path, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group,
|
virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group,
|
||||||
const char *path,
|
const char *devPath,
|
||||||
unsigned int *weight)
|
unsigned int *weight)
|
||||||
{
|
{
|
||||||
VIR_AUTOFREE(char *) str = NULL;
|
VIR_AUTOFREE(char *) str = NULL;
|
||||||
VIR_AUTOFREE(char *) value = NULL;
|
VIR_AUTOFREE(char *) value = NULL;
|
||||||
|
VIR_AUTOFREE(char *) path = NULL;
|
||||||
|
|
||||||
if (virCgroupGetValueStr(group,
|
if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
|
||||||
VIR_CGROUP_CONTROLLER_BLKIO,
|
"blkio.weight_device", &path) < 0) {
|
||||||
"blkio.weight_device",
|
|
||||||
&value) < 0) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
|
if (!virFileExists(path)) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
|
_("blkio device weight is valid only for cfq scheduler"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virCgroupGetValueRaw(path, &value) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (virCgroupGetValueForBlkDev(value, devPath, &str) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!str) {
|
if (!str) {
|
||||||
|
|
Loading…
Reference in New Issue