From 39b7d11c4b75b3213054f7730887acca90f62969 Mon Sep 17 00:00:00 2001
Message-Id: <39b7d11c4b75b3213054f7730887acca90f62969@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:07:34 +0200
Subject: [PATCH] vircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceWeight
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 568f746eafce1194dc10cc91a41c91bf08fadd53)
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <5dd74b70bcec7b3cd7186b53e76857dcf1d21c6f.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/util/vircgroupv2.c | 51 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index fcf39406e1..86b3fc127a 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -694,6 +694,55 @@ virCgroupV2GetBlkioIoDeviceServiced(virCgroupPtr group,
}
+static int
+virCgroupV2SetBlkioDeviceWeight(virCgroupPtr group,
+ const char *path,
+ unsigned int weight)
+{
+ VIR_AUTOFREE(char *) str = NULL;
+ VIR_AUTOFREE(char *) blkstr = NULL;
+
+ if (!(blkstr = virCgroupGetBlockDevString(path)))
+ return -1;
+
+ if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
+ return -1;
+
+ return virCgroupSetValueStr(group,
+ VIR_CGROUP_CONTROLLER_BLKIO,
+ "io.weight",
+ str);
+}
+
+
+static int
+virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group,
+ const char *path,
+ unsigned int *weight)
+{
+ VIR_AUTOFREE(char *) str = NULL;
+
+ if (virCgroupGetValueForBlkDev(group,
+ VIR_CGROUP_CONTROLLER_BLKIO,
+ "io.weight",
+ path,
+ &str) < 0) {
+ return -1;
+ }
+
+ if (!str) {
+ *weight = 0;
+ } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unable to parse '%s' as an integer"),
+ str);
+ return -1;
+ }
+
+ return 0;
+}
+
+
virCgroupBackend virCgroupV2Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V2,
@@ -720,6 +769,8 @@ virCgroupBackend virCgroupV2Backend = {
.getBlkioWeight = virCgroupV2GetBlkioWeight,
.getBlkioIoServiced = virCgroupV2GetBlkioIoServiced,
.getBlkioIoDeviceServiced = virCgroupV2GetBlkioIoDeviceServiced,
+ .setBlkioDeviceWeight = virCgroupV2SetBlkioDeviceWeight,
+ .getBlkioDeviceWeight = virCgroupV2GetBlkioDeviceWeight,
};
--
2.22.0