From a6c731357b9c74e5cc298f04267312ad3bb635fa Mon Sep 17 00:00:00 2001 Message-Id: From: Pavel Hrdina Date: Tue, 2 Jul 2019 15:13:26 +0200 Subject: [PATCH] util: vircgroupv1: add support for BFQ blkio files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ján Tomko (cherry picked from commit 035ebe9390a630964f391816f05c9cc7792212ad) Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1658890 Signed-off-by: Pavel Hrdina Message-Id: Reviewed-by: Ján Tomko --- src/util/vircgroupv1.c | 114 ++++++++++++++++++++++++++++++++--------- 1 file changed, 90 insertions(+), 24 deletions(-) diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index e51db6ee1f..a7d6c92e4c 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -949,10 +949,33 @@ static int virCgroupV1SetBlkioWeight(virCgroupPtr group, unsigned int weight) { - return virCgroupSetValueU64(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.weight", - weight); + VIR_AUTOFREE(char *) path = NULL; + VIR_AUTOFREE(char *) value = NULL; + + 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, unsigned int *weight) { - unsigned long long tmp; - int ret; - ret = virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.weight", &tmp); - if (ret == 0) - *weight = tmp; - return ret; + VIR_AUTOFREE(char *) path = NULL; + VIR_AUTOFREE(char *) value = NULL; + + 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 (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 virCgroupV1SetBlkioDeviceWeight(virCgroupPtr group, - const char *path, + const char *devPath, unsigned int weight) { VIR_AUTOFREE(char *) str = NULL; VIR_AUTOFREE(char *) blkstr = NULL; + VIR_AUTOFREE(char *) path = NULL; - if (!(blkstr = virCgroupGetBlockDevString(path))) + if (!(blkstr = virCgroupGetBlockDevString(devPath))) return -1; if (virAsprintf(&str, "%s%d", blkstr, weight) < 0) return -1; - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.weight_device", - str); + if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.weight_device", &path) < 0) { + return -1; + } + + 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 virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group, - const char *path, + const char *devPath, unsigned int *weight) { VIR_AUTOFREE(char *) str = NULL; VIR_AUTOFREE(char *) value = NULL; + VIR_AUTOFREE(char *) path = NULL; - if (virCgroupGetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.weight_device", - &value) < 0) { + if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.weight_device", &path) < 0) { 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; if (!str) { -- 2.22.0