render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c480ed
From eca0f75e6f67ec9e445b90685143992b6929cef0 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <eca0f75e6f67ec9e445b90685143992b6929cef0@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:07:36 +0200
c480ed
Subject: [PATCH] vircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceWriteIops
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 438587033bdaf714238a98703c9efc7b0dada51f)
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: <7937bd2aa5da315f8351e3f312f5aee71b682c30.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 8cecc43f76..1d25c0ae1f 100644
c480ed
--- a/src/util/vircgroupv2.c
c480ed
+++ b/src/util/vircgroupv2.c
c480ed
@@ -811,6 +811,74 @@ virCgroupV2GetBlkioDeviceReadIops(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV2SetBlkioDeviceWriteIops(virCgroupPtr group,
c480ed
+                                   const char *path,
c480ed
+                                   unsigned int wiops)
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 (wiops == 0) {
c480ed
+        if (virAsprintf(&str, "%swiops=max", blkstr) < 0)
c480ed
+            return -1;
c480ed
+    } else {
c480ed
+        if (virAsprintf(&str, "%swiops=%u", blkstr, wiops) < 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
+virCgroupV2GetBlkioDeviceWriteIops(virCgroupPtr group,
c480ed
+                                   const char *path,
c480ed
+                                   unsigned int *wiops)
c480ed
+{
c480ed
+    VIR_AUTOFREE(char *) str = NULL;
c480ed
+    const char *name = "wiops=";
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
+        *wiops = 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
+            *wiops = 0;
c480ed
+        } else if (virStrToLong_ui(tmp, NULL, 10, wiops) < 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
@@ -841,6 +909,8 @@ virCgroupBackend virCgroupV2Backend = {
c480ed
     .getBlkioDeviceWeight = virCgroupV2GetBlkioDeviceWeight,
c480ed
     .setBlkioDeviceReadIops = virCgroupV2SetBlkioDeviceReadIops,
c480ed
     .getBlkioDeviceReadIops = virCgroupV2GetBlkioDeviceReadIops,
c480ed
+    .setBlkioDeviceWriteIops = virCgroupV2SetBlkioDeviceWriteIops,
c480ed
+    .getBlkioDeviceWriteIops = virCgroupV2GetBlkioDeviceWriteIops,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed