render / rpms / libvirt

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