|
Pablo Greco |
40546a |
From 785b8c27bef20182789d1715d0b3c1d3fe28a9f9 Mon Sep 17 00:00:00 2001
|
|
Pablo Greco |
40546a |
Message-Id: <785b8c27bef20182789d1715d0b3c1d3fe28a9f9@dist-git>
|
|
Pablo Greco |
40546a |
From: Pavel Hrdina <phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
Date: Tue, 2 Jul 2019 15:13:27 +0200
|
|
Pablo Greco |
40546a |
Subject: [PATCH] util: vircgroupv2: add support for BFQ files
|
|
Pablo Greco |
40546a |
MIME-Version: 1.0
|
|
Pablo Greco |
40546a |
Content-Type: text/plain; charset=UTF-8
|
|
Pablo Greco |
40546a |
Content-Transfer-Encoding: 8bit
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
In kernel 4.12 there was introduced new BFQ scheduler and in kernel
|
|
Pablo Greco |
40546a |
5.0 the old CFQ scheduler was removed. This has an implication on
|
|
Pablo Greco |
40546a |
the cgroups file names.
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
If the CFQ controller is enabled we use one file:
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
io.weight
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
The new BFQ controller expose one file with different name:
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
io.bfq.weight
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Except for different name they have different syntax.
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
io.weight:
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
default $val
|
|
Pablo Greco |
40546a |
major:minor $val
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
io.bfq.weight:
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
$val
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
The difference is that BFQ doesn't support per-device weight.
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
Pablo Greco |
40546a |
(cherry picked from commit 7e8a1a6e21cee67f6fa5bd2126ec17f96e5857d6)
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1658890
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
Message-Id: <d41b50b6f3d3ef064b7f3274c762a7c41bf8e1ec.1562073117.git.phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
Pablo Greco |
40546a |
---
|
|
Pablo Greco |
40546a |
src/util/vircgroupv2.c | 101 +++++++++++++++++++++++++++++++----------
|
|
Pablo Greco |
40546a |
1 file changed, 78 insertions(+), 23 deletions(-)
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
|
|
Pablo Greco |
40546a |
index e9bb331dd4..b4e90ed46d 100644
|
|
Pablo Greco |
40546a |
--- a/src/util/vircgroupv2.c
|
|
Pablo Greco |
40546a |
+++ b/src/util/vircgroupv2.c
|
|
Pablo Greco |
40546a |
@@ -591,15 +591,35 @@ static int
|
|
Pablo Greco |
40546a |
virCgroupV2SetBlkioWeight(virCgroupPtr group,
|
|
Pablo Greco |
40546a |
unsigned int weight)
|
|
Pablo Greco |
40546a |
{
|
|
Pablo Greco |
40546a |
+ VIR_AUTOFREE(char *) path = NULL;
|
|
Pablo Greco |
40546a |
VIR_AUTOFREE(char *) value = NULL;
|
|
Pablo Greco |
40546a |
+ const char *format = "%u";
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
- if (virAsprintf(&value, "default %u", weight) < 0)
|
|
Pablo Greco |
40546a |
+ if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
|
|
Pablo Greco |
40546a |
+ "io.bfq.weight", &path) < 0) {
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (!virFileExists(path)) {
|
|
Pablo Greco |
40546a |
+ VIR_FREE(path);
|
|
Pablo Greco |
40546a |
+ format = "default %u";
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
|
|
Pablo Greco |
40546a |
+ "io.weight", &path) < 0) {
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (!virFileExists(path)) {
|
|
Pablo Greco |
40546a |
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
Pablo Greco |
40546a |
+ _("blkio weight is valid only for bfq or cfq scheduler"));
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virAsprintf(&value, format, weight) < 0)
|
|
Pablo Greco |
40546a |
return -1;
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
- return virCgroupSetValueStr(group,
|
|
Pablo Greco |
40546a |
- VIR_CGROUP_CONTROLLER_BLKIO,
|
|
Pablo Greco |
40546a |
- "io.weight",
|
|
Pablo Greco |
40546a |
- value);
|
|
Pablo Greco |
40546a |
+ return virCgroupSetValueRaw(path, value);
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
@@ -607,20 +627,38 @@ static int
|
|
Pablo Greco |
40546a |
virCgroupV2GetBlkioWeight(virCgroupPtr group,
|
|
Pablo Greco |
40546a |
unsigned int *weight)
|
|
Pablo Greco |
40546a |
{
|
|
Pablo Greco |
40546a |
+ VIR_AUTOFREE(char *) path = NULL;
|
|
Pablo Greco |
40546a |
VIR_AUTOFREE(char *) value = NULL;
|
|
Pablo Greco |
40546a |
char *tmp;
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
- if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO,
|
|
Pablo Greco |
40546a |
- "io.weight", &value) < 0) {
|
|
Pablo Greco |
40546a |
+ if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
|
|
Pablo Greco |
40546a |
+ "io.bfq.weight", &path) < 0) {
|
|
Pablo Greco |
40546a |
return -1;
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
- if (!(tmp = strstr(value, "default "))) {
|
|
Pablo Greco |
40546a |
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
Pablo Greco |
40546a |
- _("Cannot find default io weight."));
|
|
Pablo Greco |
40546a |
+ if (!virFileExists(path)) {
|
|
Pablo Greco |
40546a |
+ VIR_FREE(path);
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
|
|
Pablo Greco |
40546a |
+ "io.weight", &path) < 0) {
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (!virFileExists(path)) {
|
|
Pablo Greco |
40546a |
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
Pablo Greco |
40546a |
+ _("blkio weight is valid only for bfq or cfq scheduler"));
|
|
Pablo Greco |
40546a |
return -1;
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
- tmp += strlen("default ");
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virCgroupGetValueRaw(path, &value) < 0)
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if ((tmp = strstr(value, "default "))) {
|
|
Pablo Greco |
40546a |
+ tmp += strlen("default ");
|
|
Pablo Greco |
40546a |
+ } else {
|
|
Pablo Greco |
40546a |
+ tmp = value;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
if (virStrToLong_ui(tmp, NULL, 10, weight) < 0) {
|
|
Pablo Greco |
40546a |
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
Pablo Greco |
40546a |
@@ -762,41 +800,58 @@ virCgroupV2GetBlkioIoDeviceServiced(virCgroupPtr group,
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
static int
|
|
Pablo Greco |
40546a |
virCgroupV2SetBlkioDeviceWeight(virCgroupPtr group,
|
|
Pablo Greco |
40546a |
- const char *path,
|
|
Pablo Greco |
40546a |
+ const char *devPath,
|
|
Pablo Greco |
40546a |
unsigned int weight)
|
|
Pablo Greco |
40546a |
{
|
|
Pablo Greco |
40546a |
+ VIR_AUTOFREE(char *) path = NULL;
|
|
Pablo Greco |
40546a |
VIR_AUTOFREE(char *) str = NULL;
|
|
Pablo Greco |
40546a |
VIR_AUTOFREE(char *) blkstr = NULL;
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
- if (!(blkstr = virCgroupGetBlockDevString(path)))
|
|
Pablo Greco |
40546a |
+ if (!(blkstr = virCgroupGetBlockDevString(devPath)))
|
|
Pablo Greco |
40546a |
return -1;
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
|
|
Pablo Greco |
40546a |
return -1;
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
- return virCgroupSetValueStr(group,
|
|
Pablo Greco |
40546a |
- VIR_CGROUP_CONTROLLER_BLKIO,
|
|
Pablo Greco |
40546a |
- "io.weight",
|
|
Pablo Greco |
40546a |
- str);
|
|
Pablo Greco |
40546a |
+ if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
|
|
Pablo Greco |
40546a |
+ "io.weight", &path) < 0) {
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (!virFileExists(path)) {
|
|
Pablo Greco |
40546a |
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
Pablo Greco |
40546a |
+ _("blkio device weight is valid only for cfq scheduler"));
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ return virCgroupSetValueRaw(path, str);
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
static int
|
|
Pablo Greco |
40546a |
virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group,
|
|
Pablo Greco |
40546a |
- const char *path,
|
|
Pablo Greco |
40546a |
+ const char *devPath,
|
|
Pablo Greco |
40546a |
unsigned int *weight)
|
|
Pablo Greco |
40546a |
{
|
|
Pablo Greco |
40546a |
+ VIR_AUTOFREE(char *) path = NULL;
|
|
Pablo Greco |
40546a |
VIR_AUTOFREE(char *) str = NULL;
|
|
Pablo Greco |
40546a |
VIR_AUTOFREE(char *) value = NULL;
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
- if (virCgroupGetValueStr(group,
|
|
Pablo Greco |
40546a |
- VIR_CGROUP_CONTROLLER_BLKIO,
|
|
Pablo Greco |
40546a |
- "io.weight",
|
|
Pablo Greco |
40546a |
- &value) < 0) {
|
|
Pablo Greco |
40546a |
+ if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
|
|
Pablo Greco |
40546a |
+ "io.weight", &path) < 0) {
|
|
Pablo Greco |
40546a |
return -1;
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
- if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
|
|
Pablo Greco |
40546a |
+ if (!virFileExists(path)) {
|
|
Pablo Greco |
40546a |
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
Pablo Greco |
40546a |
+ _("blkio device weight is valid only for cfq scheduler"));
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virCgroupGetValueRaw(path, &value) < 0)
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virCgroupGetValueForBlkDev(value, devPath, &str) < 0)
|
|
Pablo Greco |
40546a |
return -1;
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
if (!str) {
|
|
Pablo Greco |
40546a |
--
|
|
Pablo Greco |
40546a |
2.22.0
|
|
Pablo Greco |
40546a |
|