render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Pablo Greco 40546a
From b5ce0e989440de2c3d4bfb8b325d85ca25ace4ca Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <b5ce0e989440de2c3d4bfb8b325d85ca25ace4ca@dist-git>
Pablo Greco 40546a
From: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Date: Mon, 1 Jul 2019 17:07:38 +0200
Pablo Greco 40546a
Subject: [PATCH] vircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceWriteBps
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 91756fb64a370e48a6bcdd1973126a8c7a36e4f7)
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: <3d70ebb985fa8132e45ba12bbb8e78ac80557a78.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 b303e9cb10..52d31925c2 100644
Pablo Greco 40546a
--- a/src/util/vircgroupv2.c
Pablo Greco 40546a
+++ b/src/util/vircgroupv2.c
Pablo Greco 40546a
@@ -947,6 +947,74 @@ virCgroupV2GetBlkioDeviceReadBps(virCgroupPtr group,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+virCgroupV2SetBlkioDeviceWriteBps(virCgroupPtr group,
Pablo Greco 40546a
+                                  const char *path,
Pablo Greco 40546a
+                                  unsigned long long wbps)
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 (wbps == 0) {
Pablo Greco 40546a
+        if (virAsprintf(&str, "%swbps=max", blkstr) < 0)
Pablo Greco 40546a
+            return -1;
Pablo Greco 40546a
+    } else {
Pablo Greco 40546a
+        if (virAsprintf(&str, "%swbps=%llu", blkstr, wbps) < 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
+virCgroupV2GetBlkioDeviceWriteBps(virCgroupPtr group,
Pablo Greco 40546a
+                                  const char *path,
Pablo Greco 40546a
+                                  unsigned long long *wbps)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    VIR_AUTOFREE(char *) str = NULL;
Pablo Greco 40546a
+    const char *name = "wbps=";
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
+        *wbps = 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
+            *wbps = 0;
Pablo Greco 40546a
+        } else if (virStrToLong_ull(tmp, NULL, 10, wbps) < 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
@@ -981,6 +1049,8 @@ virCgroupBackend virCgroupV2Backend = {
Pablo Greco 40546a
     .getBlkioDeviceWriteIops = virCgroupV2GetBlkioDeviceWriteIops,
Pablo Greco 40546a
     .setBlkioDeviceReadBps = virCgroupV2SetBlkioDeviceReadBps,
Pablo Greco 40546a
     .getBlkioDeviceReadBps = virCgroupV2GetBlkioDeviceReadBps,
Pablo Greco 40546a
+    .setBlkioDeviceWriteBps = virCgroupV2SetBlkioDeviceWriteBps,
Pablo Greco 40546a
+    .getBlkioDeviceWriteBps = virCgroupV2GetBlkioDeviceWriteBps,
Pablo Greco 40546a
 };
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a