libvirt/SOURCES/libvirt-util-vircgroupv2-add-support-for-BFQ-files.patch
2021-10-08 13:11:16 +00:00

212 lines
6.5 KiB
Diff

From 785b8c27bef20182789d1715d0b3c1d3fe28a9f9 Mon Sep 17 00:00:00 2001
Message-Id: <785b8c27bef20182789d1715d0b3c1d3fe28a9f9@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Tue, 2 Jul 2019 15:13:27 +0200
Subject: [PATCH] util: vircgroupv2: add support for BFQ 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 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>
(cherry picked from commit 7e8a1a6e21cee67f6fa5bd2126ec17f96e5857d6)
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1658890
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <d41b50b6f3d3ef064b7f3274c762a7c41bf8e1ec.1562073117.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/util/vircgroupv2.c | 101 +++++++++++++++++++++++++++++++----------
1 file changed, 78 insertions(+), 23 deletions(-)
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index e9bb331dd4..b4e90ed46d 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -591,15 +591,35 @@ static int
virCgroupV2SetBlkioWeight(virCgroupPtr group,
unsigned int weight)
{
+ VIR_AUTOFREE(char *) path = 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 virCgroupSetValueStr(group,
- VIR_CGROUP_CONTROLLER_BLKIO,
- "io.weight",
- value);
+ return virCgroupSetValueRaw(path, value);
}
@@ -607,20 +627,38 @@ static int
virCgroupV2GetBlkioWeight(virCgroupPtr group,
unsigned int *weight)
{
+ VIR_AUTOFREE(char *) path = NULL;
VIR_AUTOFREE(char *) value = NULL;
char *tmp;
- if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO,
- "io.weight", &value) < 0) {
+ if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
+ "io.bfq.weight", &path) < 0) {
return -1;
}
- if (!(tmp = strstr(value, "default "))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Cannot find default io weight."));
+ if (!virFileExists(path)) {
+ VIR_FREE(path);
+
+ 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;
}
- 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) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -762,41 +800,58 @@ virCgroupV2GetBlkioIoDeviceServiced(virCgroupPtr group,
static int
virCgroupV2SetBlkioDeviceWeight(virCgroupPtr group,
- const char *path,
+ const char *devPath,
unsigned int weight)
{
+ VIR_AUTOFREE(char *) path = NULL;
VIR_AUTOFREE(char *) str = NULL;
VIR_AUTOFREE(char *) blkstr = 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,
- "io.weight",
- str);
+ if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
+ "io.weight", &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
virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group,
- const char *path,
+ const char *devPath,
unsigned int *weight)
{
+ VIR_AUTOFREE(char *) path = NULL;
VIR_AUTOFREE(char *) str = NULL;
VIR_AUTOFREE(char *) value = NULL;
- if (virCgroupGetValueStr(group,
- VIR_CGROUP_CONTROLLER_BLKIO,
- "io.weight",
- &value) < 0) {
+ if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
+ "io.weight", &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