Blob Blame History Raw
From 7ca4f79d91300d6d6da1ac31d745852e35d4220f Mon Sep 17 00:00:00 2001
Message-Id: <7ca4f79d91300d6d6da1ac31d745852e35d4220f@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:07:37 +0200
Subject: [PATCH] vircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceReadBps
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 353ce9453e836da1d42993e71c88011f8515e538)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <5fedf92d6740e387df3e88e3abf6b711d79f3dbe.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 1d25c0ae1f..b303e9cb10 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -879,6 +879,74 @@ virCgroupV2GetBlkioDeviceWriteIops(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV2SetBlkioDeviceReadBps(virCgroupPtr group,
+                                 const char *path,
+                                 unsigned long long rbps)
+{
+    VIR_AUTOFREE(char *) str = NULL;
+    VIR_AUTOFREE(char *) blkstr = NULL;
+
+    if (!(blkstr = virCgroupGetBlockDevString(path)))
+        return -1;
+
+    if (rbps == 0) {
+        if (virAsprintf(&str, "%srbps=max", blkstr) < 0)
+            return -1;
+    } else {
+        if (virAsprintf(&str, "%srbps=%llu", blkstr, rbps) < 0)
+            return -1;
+    }
+
+    return virCgroupSetValueStr(group,
+                                VIR_CGROUP_CONTROLLER_BLKIO,
+                                "io.max",
+                                str);
+}
+
+
+static int
+virCgroupV2GetBlkioDeviceReadBps(virCgroupPtr group,
+                                 const char *path,
+                                 unsigned long long *rbps)
+{
+    VIR_AUTOFREE(char *) str = NULL;
+    const char *name = "rbps=";
+    char *tmp;
+
+    if (virCgroupGetValueForBlkDev(group,
+                                   VIR_CGROUP_CONTROLLER_BLKIO,
+                                   "io.max",
+                                   path,
+                                   &str) < 0) {
+        return -1;
+    }
+
+    if (!str) {
+        *rbps = 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)) {
+            *rbps = 0;
+        } else if (virStrToLong_ull(tmp, NULL, 10, rbps) < 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,
 
@@ -911,6 +979,8 @@ virCgroupBackend virCgroupV2Backend = {
     .getBlkioDeviceReadIops = virCgroupV2GetBlkioDeviceReadIops,
     .setBlkioDeviceWriteIops = virCgroupV2SetBlkioDeviceWriteIops,
     .getBlkioDeviceWriteIops = virCgroupV2GetBlkioDeviceWriteIops,
+    .setBlkioDeviceReadBps = virCgroupV2SetBlkioDeviceReadBps,
+    .getBlkioDeviceReadBps = virCgroupV2GetBlkioDeviceReadBps,
 };
 
 
-- 
2.22.0