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