render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Pablo Greco 40546a
From 3cb8992be4013fb3ae978c62f6a433080e74130a Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <3cb8992be4013fb3ae978c62f6a433080e74130a@dist-git>
Pablo Greco 40546a
From: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Date: Mon, 1 Jul 2019 17:06:42 +0200
Pablo Greco 40546a
Subject: [PATCH] vircgroup: extract virCgroupV1GetBlkioIoServiced
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
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Pablo Greco 40546a
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Pablo Greco 40546a
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
(cherry picked from commit 4baa08ace12d2db7e7023b2abe915360bc7dcddf)
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: <aa03ae2eef4e9a09d28562f7218c302ec095a912.1561993100.git.phrdina@redhat.com>
Pablo Greco 40546a
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Pablo Greco 40546a
---
Pablo Greco 40546a
 src/util/vircgroup.c        | 87 ++-------------------------------
Pablo Greco 40546a
 src/util/vircgroupbackend.h |  8 ++++
Pablo Greco 40546a
 src/util/vircgroupv1.c      | 95 +++++++++++++++++++++++++++++++++++++
Pablo Greco 40546a
 3 files changed, 106 insertions(+), 84 deletions(-)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
Pablo Greco 40546a
index d2ffa8aefe..8e46777920 100644
Pablo Greco 40546a
--- a/src/util/vircgroup.c
Pablo Greco 40546a
+++ b/src/util/vircgroup.c
Pablo Greco 40546a
@@ -1311,90 +1311,9 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group,
Pablo Greco 40546a
                             long long *requests_read,
Pablo Greco 40546a
                             long long *requests_write)
Pablo Greco 40546a
 {
Pablo Greco 40546a
-    long long stats_val;
Pablo Greco 40546a
-    VIR_AUTOFREE(char *) str1 = NULL;
Pablo Greco 40546a
-    VIR_AUTOFREE(char *) str2 = NULL;
Pablo Greco 40546a
-    char *p1 = NULL;
Pablo Greco 40546a
-    char *p2 = NULL;
Pablo Greco 40546a
-    size_t i;
Pablo Greco 40546a
-
Pablo Greco 40546a
-    const char *value_names[] = {
Pablo Greco 40546a
-        "Read ",
Pablo Greco 40546a
-        "Write "
Pablo Greco 40546a
-    };
Pablo Greco 40546a
-    long long *bytes_ptrs[] = {
Pablo Greco 40546a
-        bytes_read,
Pablo Greco 40546a
-        bytes_write
Pablo Greco 40546a
-    };
Pablo Greco 40546a
-    long long *requests_ptrs[] = {
Pablo Greco 40546a
-        requests_read,
Pablo Greco 40546a
-        requests_write
Pablo Greco 40546a
-    };
Pablo Greco 40546a
-
Pablo Greco 40546a
-    *bytes_read = 0;
Pablo Greco 40546a
-    *bytes_write = 0;
Pablo Greco 40546a
-    *requests_read = 0;
Pablo Greco 40546a
-    *requests_write = 0;
Pablo Greco 40546a
-
Pablo Greco 40546a
-    if (virCgroupGetValueStr(group,
Pablo Greco 40546a
-                             VIR_CGROUP_CONTROLLER_BLKIO,
Pablo Greco 40546a
-                             "blkio.throttle.io_service_bytes", &str1) < 0)
Pablo Greco 40546a
-        return -1;
Pablo Greco 40546a
-
Pablo Greco 40546a
-    if (virCgroupGetValueStr(group,
Pablo Greco 40546a
-                             VIR_CGROUP_CONTROLLER_BLKIO,
Pablo Greco 40546a
-                             "blkio.throttle.io_serviced", &str2) < 0)
Pablo Greco 40546a
-        return -1;
Pablo Greco 40546a
-
Pablo Greco 40546a
-    /* sum up all entries of the same kind, from all devices */
Pablo Greco 40546a
-    for (i = 0; i < ARRAY_CARDINALITY(value_names); i++) {
Pablo Greco 40546a
-        p1 = str1;
Pablo Greco 40546a
-        p2 = str2;
Pablo Greco 40546a
-
Pablo Greco 40546a
-        while ((p1 = strstr(p1, value_names[i]))) {
Pablo Greco 40546a
-            p1 += strlen(value_names[i]);
Pablo Greco 40546a
-            if (virStrToLong_ll(p1, &p1, 10, &stats_val) < 0) {
Pablo Greco 40546a
-                virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
-                               _("Cannot parse byte %sstat '%s'"),
Pablo Greco 40546a
-                               value_names[i],
Pablo Greco 40546a
-                               p1);
Pablo Greco 40546a
-                return -1;
Pablo Greco 40546a
-            }
Pablo Greco 40546a
-
Pablo Greco 40546a
-            if (stats_val < 0 ||
Pablo Greco 40546a
-                (stats_val > 0 && *bytes_ptrs[i] > (LLONG_MAX - stats_val)))
Pablo Greco 40546a
-            {
Pablo Greco 40546a
-                virReportError(VIR_ERR_OVERFLOW,
Pablo Greco 40546a
-                               _("Sum of byte %sstat overflows"),
Pablo Greco 40546a
-                               value_names[i]);
Pablo Greco 40546a
-                return -1;
Pablo Greco 40546a
-            }
Pablo Greco 40546a
-            *bytes_ptrs[i] += stats_val;
Pablo Greco 40546a
-        }
Pablo Greco 40546a
-
Pablo Greco 40546a
-        while ((p2 = strstr(p2, value_names[i]))) {
Pablo Greco 40546a
-            p2 += strlen(value_names[i]);
Pablo Greco 40546a
-            if (virStrToLong_ll(p2, &p2, 10, &stats_val) < 0) {
Pablo Greco 40546a
-                virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
-                               _("Cannot parse %srequest stat '%s'"),
Pablo Greco 40546a
-                               value_names[i],
Pablo Greco 40546a
-                               p2);
Pablo Greco 40546a
-                return -1;
Pablo Greco 40546a
-            }
Pablo Greco 40546a
-
Pablo Greco 40546a
-            if (stats_val < 0 ||
Pablo Greco 40546a
-                (stats_val > 0 && *requests_ptrs[i] > (LLONG_MAX - stats_val)))
Pablo Greco 40546a
-            {
Pablo Greco 40546a
-                virReportError(VIR_ERR_OVERFLOW,
Pablo Greco 40546a
-                               _("Sum of %srequest stat overflows"),
Pablo Greco 40546a
-                               value_names[i]);
Pablo Greco 40546a
-                return -1;
Pablo Greco 40546a
-            }
Pablo Greco 40546a
-            *requests_ptrs[i] += stats_val;
Pablo Greco 40546a
-        }
Pablo Greco 40546a
-    }
Pablo Greco 40546a
-
Pablo Greco 40546a
-    return 0;
Pablo Greco 40546a
+    VIR_CGROUP_BACKEND_CALL(group, getBlkioIoServiced, -1,
Pablo Greco 40546a
+                            bytes_read, bytes_write,
Pablo Greco 40546a
+                            requests_read, requests_write);
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
Pablo Greco 40546a
index ccce65f1e2..585a2eb353 100644
Pablo Greco 40546a
--- a/src/util/vircgroupbackend.h
Pablo Greco 40546a
+++ b/src/util/vircgroupbackend.h
Pablo Greco 40546a
@@ -145,6 +145,13 @@ typedef int
Pablo Greco 40546a
 (*virCgroupGetBlkioWeightCB)(virCgroupPtr group,
Pablo Greco 40546a
                              unsigned int *weight);
Pablo Greco 40546a
 
Pablo Greco 40546a
+typedef int
Pablo Greco 40546a
+(*virCgroupGetBlkioIoServicedCB)(virCgroupPtr group,
Pablo Greco 40546a
+                                 long long *bytes_read,
Pablo Greco 40546a
+                                 long long *bytes_write,
Pablo Greco 40546a
+                                 long long *requests_read,
Pablo Greco 40546a
+                                 long long *requests_write);
Pablo Greco 40546a
+
Pablo Greco 40546a
 struct _virCgroupBackend {
Pablo Greco 40546a
     virCgroupBackendType type;
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -171,6 +178,7 @@ struct _virCgroupBackend {
Pablo Greco 40546a
     /* Optional cgroup controller specific callbacks. */
Pablo Greco 40546a
     virCgroupSetBlkioWeightCB setBlkioWeight;
Pablo Greco 40546a
     virCgroupGetBlkioWeightCB getBlkioWeight;
Pablo Greco 40546a
+    virCgroupGetBlkioIoServicedCB getBlkioIoServiced;
Pablo Greco 40546a
 };
Pablo Greco 40546a
 typedef struct _virCgroupBackend virCgroupBackend;
Pablo Greco 40546a
 typedef virCgroupBackend *virCgroupBackendPtr;
Pablo Greco 40546a
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
Pablo Greco 40546a
index d67b3164ce..1afdad4afc 100644
Pablo Greco 40546a
--- a/src/util/vircgroupv1.c
Pablo Greco 40546a
+++ b/src/util/vircgroupv1.c
Pablo Greco 40546a
@@ -955,6 +955,100 @@ virCgroupV1GetBlkioWeight(virCgroupPtr group,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+virCgroupV1GetBlkioIoServiced(virCgroupPtr group,
Pablo Greco 40546a
+                              long long *bytes_read,
Pablo Greco 40546a
+                              long long *bytes_write,
Pablo Greco 40546a
+                              long long *requests_read,
Pablo Greco 40546a
+                              long long *requests_write)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    long long stats_val;
Pablo Greco 40546a
+    VIR_AUTOFREE(char *) str1 = NULL;
Pablo Greco 40546a
+    VIR_AUTOFREE(char *) str2 = NULL;
Pablo Greco 40546a
+    char *p1 = NULL;
Pablo Greco 40546a
+    char *p2 = NULL;
Pablo Greco 40546a
+    size_t i;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    const char *value_names[] = {
Pablo Greco 40546a
+        "Read ",
Pablo Greco 40546a
+        "Write "
Pablo Greco 40546a
+    };
Pablo Greco 40546a
+    long long *bytes_ptrs[] = {
Pablo Greco 40546a
+        bytes_read,
Pablo Greco 40546a
+        bytes_write
Pablo Greco 40546a
+    };
Pablo Greco 40546a
+    long long *requests_ptrs[] = {
Pablo Greco 40546a
+        requests_read,
Pablo Greco 40546a
+        requests_write
Pablo Greco 40546a
+    };
Pablo Greco 40546a
+
Pablo Greco 40546a
+    *bytes_read = 0;
Pablo Greco 40546a
+    *bytes_write = 0;
Pablo Greco 40546a
+    *requests_read = 0;
Pablo Greco 40546a
+    *requests_write = 0;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (virCgroupGetValueStr(group,
Pablo Greco 40546a
+                             VIR_CGROUP_CONTROLLER_BLKIO,
Pablo Greco 40546a
+                             "blkio.throttle.io_service_bytes", &str1) < 0)
Pablo Greco 40546a
+        return -1;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (virCgroupGetValueStr(group,
Pablo Greco 40546a
+                             VIR_CGROUP_CONTROLLER_BLKIO,
Pablo Greco 40546a
+                             "blkio.throttle.io_serviced", &str2) < 0)
Pablo Greco 40546a
+        return -1;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    /* sum up all entries of the same kind, from all devices */
Pablo Greco 40546a
+    for (i = 0; i < ARRAY_CARDINALITY(value_names); i++) {
Pablo Greco 40546a
+        p1 = str1;
Pablo Greco 40546a
+        p2 = str2;
Pablo Greco 40546a
+
Pablo Greco 40546a
+        while ((p1 = strstr(p1, value_names[i]))) {
Pablo Greco 40546a
+            p1 += strlen(value_names[i]);
Pablo Greco 40546a
+            if (virStrToLong_ll(p1, &p1, 10, &stats_val) < 0) {
Pablo Greco 40546a
+                virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
+                               _("Cannot parse byte %sstat '%s'"),
Pablo Greco 40546a
+                               value_names[i],
Pablo Greco 40546a
+                               p1);
Pablo Greco 40546a
+                return -1;
Pablo Greco 40546a
+            }
Pablo Greco 40546a
+
Pablo Greco 40546a
+            if (stats_val < 0 ||
Pablo Greco 40546a
+                (stats_val > 0 && *bytes_ptrs[i] > (LLONG_MAX - stats_val)))
Pablo Greco 40546a
+            {
Pablo Greco 40546a
+                virReportError(VIR_ERR_OVERFLOW,
Pablo Greco 40546a
+                               _("Sum of byte %sstat overflows"),
Pablo Greco 40546a
+                               value_names[i]);
Pablo Greco 40546a
+                return -1;
Pablo Greco 40546a
+            }
Pablo Greco 40546a
+            *bytes_ptrs[i] += stats_val;
Pablo Greco 40546a
+        }
Pablo Greco 40546a
+
Pablo Greco 40546a
+        while ((p2 = strstr(p2, value_names[i]))) {
Pablo Greco 40546a
+            p2 += strlen(value_names[i]);
Pablo Greco 40546a
+            if (virStrToLong_ll(p2, &p2, 10, &stats_val) < 0) {
Pablo Greco 40546a
+                virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
+                               _("Cannot parse %srequest stat '%s'"),
Pablo Greco 40546a
+                               value_names[i],
Pablo Greco 40546a
+                               p2);
Pablo Greco 40546a
+                return -1;
Pablo Greco 40546a
+            }
Pablo Greco 40546a
+
Pablo Greco 40546a
+            if (stats_val < 0 ||
Pablo Greco 40546a
+                (stats_val > 0 && *requests_ptrs[i] > (LLONG_MAX - stats_val)))
Pablo Greco 40546a
+            {
Pablo Greco 40546a
+                virReportError(VIR_ERR_OVERFLOW,
Pablo Greco 40546a
+                               _("Sum of %srequest stat overflows"),
Pablo Greco 40546a
+                               value_names[i]);
Pablo Greco 40546a
+                return -1;
Pablo Greco 40546a
+            }
Pablo Greco 40546a
+            *requests_ptrs[i] += stats_val;
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 virCgroupV1Backend = {
Pablo Greco 40546a
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -979,6 +1073,7 @@ virCgroupBackend virCgroupV1Backend = {
Pablo Greco 40546a
 
Pablo Greco 40546a
     .setBlkioWeight = virCgroupV1SetBlkioWeight,
Pablo Greco 40546a
     .getBlkioWeight = virCgroupV1GetBlkioWeight,
Pablo Greco 40546a
+    .getBlkioIoServiced = virCgroupV1GetBlkioIoServiced,
Pablo Greco 40546a
 };
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a