113 lines
3.5 KiB
Diff
113 lines
3.5 KiB
Diff
From 87e723cfed87955b7d23e0d2ea7bac61b57daf21 Mon Sep 17 00:00:00 2001
|
|
Message-Id: <87e723cfed87955b7d23e0d2ea7bac61b57daf21@dist-git>
|
|
From: Pavel Hrdina <phrdina@redhat.com>
|
|
Date: Mon, 1 Jul 2019 17:07:35 +0200
|
|
Subject: [PATCH] vircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceReadIops
|
|
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 862f630825a74a2605fca52bb66d8f04edefa75b)
|
|
|
|
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
|
|
|
|
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
Message-Id: <4afdb39491c625603a7b9963648d20148477cc33.1561993100.git.phrdina@redhat.com>
|
|
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
---
|
|
src/util/vircgroupv2.c | 70 ++++++++++++++++++++++++++++++++++++++++++
|
|
1 file changed, 70 insertions(+)
|
|
|
|
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
|
|
index 86b3fc127a..8cecc43f76 100644
|
|
--- a/src/util/vircgroupv2.c
|
|
+++ b/src/util/vircgroupv2.c
|
|
@@ -743,6 +743,74 @@ virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group,
|
|
}
|
|
|
|
|
|
+static int
|
|
+virCgroupV2SetBlkioDeviceReadIops(virCgroupPtr group,
|
|
+ const char *path,
|
|
+ unsigned int riops)
|
|
+{
|
|
+ VIR_AUTOFREE(char *) str = NULL;
|
|
+ VIR_AUTOFREE(char *) blkstr = NULL;
|
|
+
|
|
+ if (!(blkstr = virCgroupGetBlockDevString(path)))
|
|
+ return -1;
|
|
+
|
|
+ if (riops == 0) {
|
|
+ if (virAsprintf(&str, "%sriops=max", blkstr) < 0)
|
|
+ return -1;
|
|
+ } else {
|
|
+ if (virAsprintf(&str, "%sriops=%u", blkstr, riops) < 0)
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ return virCgroupSetValueStr(group,
|
|
+ VIR_CGROUP_CONTROLLER_BLKIO,
|
|
+ "io.max",
|
|
+ str);
|
|
+}
|
|
+
|
|
+
|
|
+static int
|
|
+virCgroupV2GetBlkioDeviceReadIops(virCgroupPtr group,
|
|
+ const char *path,
|
|
+ unsigned int *riops)
|
|
+{
|
|
+ VIR_AUTOFREE(char *) str = NULL;
|
|
+ const char *name = "riops=";
|
|
+ char *tmp;
|
|
+
|
|
+ if (virCgroupGetValueForBlkDev(group,
|
|
+ VIR_CGROUP_CONTROLLER_BLKIO,
|
|
+ "io.max",
|
|
+ path,
|
|
+ &str) < 0) {
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ if (!str) {
|
|
+ *riops = 0;
|
|
+ } else {
|
|
+ if (!(tmp = strstr(str, name))) {
|
|
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
+ _("Unable to find '%s' limit for block device '%s'"),
|
|
+ name, path);
|
|
+ return -1;
|
|
+ }
|
|
+ tmp += strlen(name);
|
|
+
|
|
+ if (STREQLEN(tmp, "max", 3)) {
|
|
+ *riops = 0;
|
|
+ } else if (virStrToLong_ui(tmp, NULL, 10, riops) < 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,
|
|
|
|
@@ -771,6 +839,8 @@ virCgroupBackend virCgroupV2Backend = {
|
|
.getBlkioIoDeviceServiced = virCgroupV2GetBlkioIoDeviceServiced,
|
|
.setBlkioDeviceWeight = virCgroupV2SetBlkioDeviceWeight,
|
|
.getBlkioDeviceWeight = virCgroupV2GetBlkioDeviceWeight,
|
|
+ .setBlkioDeviceReadIops = virCgroupV2SetBlkioDeviceReadIops,
|
|
+ .getBlkioDeviceReadIops = virCgroupV2GetBlkioDeviceReadIops,
|
|
};
|
|
|
|
|
|
--
|
|
2.22.0
|
|
|