render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c480ed
From 7ca4f79d91300d6d6da1ac31d745852e35d4220f Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <7ca4f79d91300d6d6da1ac31d745852e35d4220f@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:07:37 +0200
c480ed
Subject: [PATCH] vircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceReadBps
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 353ce9453e836da1d42993e71c88011f8515e538)
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: <5fedf92d6740e387df3e88e3abf6b711d79f3dbe.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 1d25c0ae1f..b303e9cb10 100644
c480ed
--- a/src/util/vircgroupv2.c
c480ed
+++ b/src/util/vircgroupv2.c
c480ed
@@ -879,6 +879,74 @@ virCgroupV2GetBlkioDeviceWriteIops(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV2SetBlkioDeviceReadBps(virCgroupPtr group,
c480ed
+                                 const char *path,
c480ed
+                                 unsigned long long rbps)
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 (rbps == 0) {
c480ed
+        if (virAsprintf(&str, "%srbps=max", blkstr) < 0)
c480ed
+            return -1;
c480ed
+    } else {
c480ed
+        if (virAsprintf(&str, "%srbps=%llu", blkstr, rbps) < 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
+virCgroupV2GetBlkioDeviceReadBps(virCgroupPtr group,
c480ed
+                                 const char *path,
c480ed
+                                 unsigned long long *rbps)
c480ed
+{
c480ed
+    VIR_AUTOFREE(char *) str = NULL;
c480ed
+    const char *name = "rbps=";
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
+        *rbps = 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
+            *rbps = 0;
c480ed
+        } else if (virStrToLong_ull(tmp, NULL, 10, rbps) < 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
@@ -911,6 +979,8 @@ virCgroupBackend virCgroupV2Backend = {
c480ed
     .getBlkioDeviceReadIops = virCgroupV2GetBlkioDeviceReadIops,
c480ed
     .setBlkioDeviceWriteIops = virCgroupV2SetBlkioDeviceWriteIops,
c480ed
     .getBlkioDeviceWriteIops = virCgroupV2GetBlkioDeviceWriteIops,
c480ed
+    .setBlkioDeviceReadBps = virCgroupV2SetBlkioDeviceReadBps,
c480ed
+    .getBlkioDeviceReadBps = virCgroupV2GetBlkioDeviceReadBps,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed