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