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