1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-25 10:03:49 +03:00

util: vircgroupv2: add support for BFQ 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 one file:

    io.weight

The new BFQ controller expose one file with different name:

    io.bfq.weight

Except for different name they have different syntax.

io.weight:

    default $val
    major:minor $val

io.bfq.weight:

    $val

The difference is that BFQ 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:
Pavel Hrdina 2019-06-18 15:19:43 +02:00
parent 035ebe9390
commit 7e8a1a6e21

View File

@ -554,15 +554,35 @@ static int
virCgroupV2SetBlkioWeight(virCgroupPtr group, virCgroupV2SetBlkioWeight(virCgroupPtr group,
unsigned int weight) unsigned int weight)
{ {
VIR_AUTOFREE(char *) path = NULL;
VIR_AUTOFREE(char *) value = NULL; VIR_AUTOFREE(char *) value = NULL;
const char *format = "%u";
if (virAsprintf(&value, "default %u", weight) < 0) if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
"io.bfq.weight", &path) < 0) {
return -1;
}
if (!virFileExists(path)) {
VIR_FREE(path);
format = "default %u";
if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
"io.weight", &path) < 0) {
return -1;
}
}
if (!virFileExists(path)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("blkio weight is valid only for bfq or cfq scheduler"));
return -1;
}
if (virAsprintf(&value, format, weight) < 0)
return -1; return -1;
return virCgroupSetValueStr(group, return virCgroupSetValueRaw(path, value);
VIR_CGROUP_CONTROLLER_BLKIO,
"io.weight",
value);
} }
@ -570,20 +590,38 @@ static int
virCgroupV2GetBlkioWeight(virCgroupPtr group, virCgroupV2GetBlkioWeight(virCgroupPtr group,
unsigned int *weight) unsigned int *weight)
{ {
VIR_AUTOFREE(char *) path = NULL;
VIR_AUTOFREE(char *) value = NULL; VIR_AUTOFREE(char *) value = NULL;
char *tmp; char *tmp;
if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
"io.weight", &value) < 0) { "io.bfq.weight", &path) < 0) {
return -1; return -1;
} }
if (!(tmp = strstr(value, "default "))) { if (!virFileExists(path)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", VIR_FREE(path);
_("Cannot find default io weight."));
if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
"io.weight", &path) < 0) {
return -1;
}
}
if (!virFileExists(path)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("blkio weight is valid only for bfq or cfq scheduler"));
return -1; return -1;
} }
tmp += strlen("default ");
if (virCgroupGetValueRaw(path, &value) < 0)
return -1;
if ((tmp = strstr(value, "default "))) {
tmp += strlen("default ");
} else {
tmp = value;
}
if (virStrToLong_ui(tmp, NULL, 10, weight) < 0) { if (virStrToLong_ui(tmp, NULL, 10, weight) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
@ -725,41 +763,58 @@ virCgroupV2GetBlkioIoDeviceServiced(virCgroupPtr group,
static int static int
virCgroupV2SetBlkioDeviceWeight(virCgroupPtr group, virCgroupV2SetBlkioDeviceWeight(virCgroupPtr group,
const char *path, const char *devPath,
unsigned int weight) unsigned int weight)
{ {
VIR_AUTOFREE(char *) path = NULL;
VIR_AUTOFREE(char *) str = NULL; VIR_AUTOFREE(char *) str = NULL;
VIR_AUTOFREE(char *) blkstr = NULL; VIR_AUTOFREE(char *) blkstr = 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 (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
VIR_CGROUP_CONTROLLER_BLKIO, "io.weight", &path) < 0) {
"io.weight", 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
virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group, virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group,
const char *path, const char *devPath,
unsigned int *weight) unsigned int *weight)
{ {
VIR_AUTOFREE(char *) path = NULL;
VIR_AUTOFREE(char *) str = NULL; VIR_AUTOFREE(char *) str = NULL;
VIR_AUTOFREE(char *) value = NULL; VIR_AUTOFREE(char *) value = NULL;
if (virCgroupGetValueStr(group, if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
VIR_CGROUP_CONTROLLER_BLKIO, "io.weight", &path) < 0) {
"io.weight",
&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) {