render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c480ed
From abf2cfc52b828aa892b446385875381f735ff947 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <abf2cfc52b828aa892b446385875381f735ff947@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:07:32 +0200
c480ed
Subject: [PATCH] vircgroup: introduce virCgroupV2GetBlkioIoServiced
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 709260add941a247b3829cf940624333cb445bb7)
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: <f178386744bb4d74f41acecb82807d451c255fc9.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroupv2.c | 65 ++++++++++++++++++++++++++++++++++++++++++
c480ed
 1 file changed, 65 insertions(+)
c480ed
c480ed
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
c480ed
index f7863a5690..000fd4c747 100644
c480ed
--- a/src/util/vircgroupv2.c
c480ed
+++ b/src/util/vircgroupv2.c
c480ed
@@ -567,6 +567,70 @@ virCgroupV2GetBlkioWeight(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV2GetBlkioIoServiced(virCgroupPtr group,
c480ed
+                              long long *bytes_read,
c480ed
+                              long long *bytes_write,
c480ed
+                              long long *requests_read,
c480ed
+                              long long *requests_write)
c480ed
+{
c480ed
+    long long stats_val;
c480ed
+    VIR_AUTOFREE(char *) str1 = NULL;
c480ed
+    char *p1;
c480ed
+    size_t i;
c480ed
+
c480ed
+    const char *value_names[] = {
c480ed
+        "rbytes=",
c480ed
+        "wbytes=",
c480ed
+        "rios=",
c480ed
+        "wios=",
c480ed
+    };
c480ed
+    long long *value_ptrs[] = {
c480ed
+        bytes_read,
c480ed
+        bytes_write,
c480ed
+        requests_read,
c480ed
+        requests_write
c480ed
+    };
c480ed
+
c480ed
+    *bytes_read = 0;
c480ed
+    *bytes_write = 0;
c480ed
+    *requests_read = 0;
c480ed
+    *requests_write = 0;
c480ed
+
c480ed
+    if (virCgroupGetValueStr(group,
c480ed
+                             VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                             "io.stat", &str1) < 0) {
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    /* sum up all entries of the same kind, from all devices */
c480ed
+    for (i = 0; i < ARRAY_CARDINALITY(value_names); i++) {
c480ed
+        p1 = str1;
c480ed
+
c480ed
+        while ((p1 = strstr(p1, value_names[i]))) {
c480ed
+            p1 += strlen(value_names[i]);
c480ed
+            if (virStrToLong_ll(p1, &p1, 10, &stats_val) < 0) {
c480ed
+                virReportError(VIR_ERR_INTERNAL_ERROR,
c480ed
+                               _("Cannot parse byte '%s' stat '%s'"),
c480ed
+                               value_names[i], p1);
c480ed
+                return -1;
c480ed
+            }
c480ed
+
c480ed
+            if (stats_val < 0 ||
c480ed
+                (stats_val > 0 && *value_ptrs[i] > (LLONG_MAX - stats_val))) {
c480ed
+                virReportError(VIR_ERR_OVERFLOW,
c480ed
+                               _("Sum of byte '%s' stat overflows"),
c480ed
+                               value_names[i]);
c480ed
+                return -1;
c480ed
+            }
c480ed
+            *value_ptrs[i] += stats_val;
c480ed
+        }
c480ed
+    }
c480ed
+
c480ed
+    return 0;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 virCgroupBackend virCgroupV2Backend = {
c480ed
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
c480ed
 
c480ed
@@ -591,6 +655,7 @@ virCgroupBackend virCgroupV2Backend = {
c480ed
 
c480ed
     .setBlkioWeight = virCgroupV2SetBlkioWeight,
c480ed
     .getBlkioWeight = virCgroupV2GetBlkioWeight,
c480ed
+    .getBlkioIoServiced = virCgroupV2GetBlkioIoServiced,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed