]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vircgroup: extract virCgroupV1GetBlkioIoServiced
authorPavel Hrdina <phrdina@redhat.com>
Fri, 17 Aug 2018 13:29:39 +0000 (15:29 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 25 Sep 2018 11:40:22 +0000 (13:40 +0200)
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/util/vircgroup.c
src/util/vircgroupbackend.h
src/util/vircgroupv1.c

index a1fc252d04dab212d52fac1de5b49bbfb88a1318..a9c0a4d3bed74d45cd98ee8fee102ed20aa42a0e 100644 (file)
@@ -1307,90 +1307,9 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group,
                             long long *requests_read,
                             long long *requests_write)
 {
-    long long stats_val;
-    VIR_AUTOFREE(char *) str1 = NULL;
-    VIR_AUTOFREE(char *) str2 = NULL;
-    char *p1 = NULL;
-    char *p2 = NULL;
-    size_t i;
-
-    const char *value_names[] = {
-        "Read ",
-        "Write "
-    };
-    long long *bytes_ptrs[] = {
-        bytes_read,
-        bytes_write
-    };
-    long long *requests_ptrs[] = {
-        requests_read,
-        requests_write
-    };
-
-    *bytes_read = 0;
-    *bytes_write = 0;
-    *requests_read = 0;
-    *requests_write = 0;
-
-    if (virCgroupGetValueStr(group,
-                             VIR_CGROUP_CONTROLLER_BLKIO,
-                             "blkio.throttle.io_service_bytes", &str1) < 0)
-        return -1;
-
-    if (virCgroupGetValueStr(group,
-                             VIR_CGROUP_CONTROLLER_BLKIO,
-                             "blkio.throttle.io_serviced", &str2) < 0)
-        return -1;
-
-    /* sum up all entries of the same kind, from all devices */
-    for (i = 0; i < ARRAY_CARDINALITY(value_names); i++) {
-        p1 = str1;
-        p2 = str2;
-
-        while ((p1 = strstr(p1, value_names[i]))) {
-            p1 += strlen(value_names[i]);
-            if (virStrToLong_ll(p1, &p1, 10, &stats_val) < 0) {
-                virReportError(VIR_ERR_INTERNAL_ERROR,
-                               _("Cannot parse byte %sstat '%s'"),
-                               value_names[i],
-                               p1);
-                return -1;
-            }
-
-            if (stats_val < 0 ||
-                (stats_val > 0 && *bytes_ptrs[i] > (LLONG_MAX - stats_val)))
-            {
-                virReportError(VIR_ERR_OVERFLOW,
-                               _("Sum of byte %sstat overflows"),
-                               value_names[i]);
-                return -1;
-            }
-            *bytes_ptrs[i] += stats_val;
-        }
-
-        while ((p2 = strstr(p2, value_names[i]))) {
-            p2 += strlen(value_names[i]);
-            if (virStrToLong_ll(p2, &p2, 10, &stats_val) < 0) {
-                virReportError(VIR_ERR_INTERNAL_ERROR,
-                               _("Cannot parse %srequest stat '%s'"),
-                               value_names[i],
-                               p2);
-                return -1;
-            }
-
-            if (stats_val < 0 ||
-                (stats_val > 0 && *requests_ptrs[i] > (LLONG_MAX - stats_val)))
-            {
-                virReportError(VIR_ERR_OVERFLOW,
-                               _("Sum of %srequest stat overflows"),
-                               value_names[i]);
-                return -1;
-            }
-            *requests_ptrs[i] += stats_val;
-        }
-    }
-
-    return 0;
+    VIR_CGROUP_BACKEND_CALL(group, getBlkioIoServiced, -1,
+                            bytes_read, bytes_write,
+                            requests_read, requests_write);
 }
 
 
index ccce65f1e26a1789457a64504b5e761c13fde502..585a2eb353a10ebb6b4fb23441edd06588eb6bc3 100644 (file)
@@ -145,6 +145,13 @@ typedef int
 (*virCgroupGetBlkioWeightCB)(virCgroupPtr group,
                              unsigned int *weight);
 
+typedef int
+(*virCgroupGetBlkioIoServicedCB)(virCgroupPtr group,
+                                 long long *bytes_read,
+                                 long long *bytes_write,
+                                 long long *requests_read,
+                                 long long *requests_write);
+
 struct _virCgroupBackend {
     virCgroupBackendType type;
 
@@ -171,6 +178,7 @@ struct _virCgroupBackend {
     /* Optional cgroup controller specific callbacks. */
     virCgroupSetBlkioWeightCB setBlkioWeight;
     virCgroupGetBlkioWeightCB getBlkioWeight;
+    virCgroupGetBlkioIoServicedCB getBlkioIoServiced;
 };
 typedef struct _virCgroupBackend virCgroupBackend;
 typedef virCgroupBackend *virCgroupBackendPtr;
index 862c009ccd4c38f2b938ae1b2937f6e95a5ad7ce..70a6fc5d8334bd1cf4033d52f3c887e4cd0a4cca 100644 (file)
@@ -954,6 +954,100 @@ virCgroupV1GetBlkioWeight(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV1GetBlkioIoServiced(virCgroupPtr group,
+                              long long *bytes_read,
+                              long long *bytes_write,
+                              long long *requests_read,
+                              long long *requests_write)
+{
+    long long stats_val;
+    VIR_AUTOFREE(char *) str1 = NULL;
+    VIR_AUTOFREE(char *) str2 = NULL;
+    char *p1 = NULL;
+    char *p2 = NULL;
+    size_t i;
+
+    const char *value_names[] = {
+        "Read ",
+        "Write "
+    };
+    long long *bytes_ptrs[] = {
+        bytes_read,
+        bytes_write
+    };
+    long long *requests_ptrs[] = {
+        requests_read,
+        requests_write
+    };
+
+    *bytes_read = 0;
+    *bytes_write = 0;
+    *requests_read = 0;
+    *requests_write = 0;
+
+    if (virCgroupGetValueStr(group,
+                             VIR_CGROUP_CONTROLLER_BLKIO,
+                             "blkio.throttle.io_service_bytes", &str1) < 0)
+        return -1;
+
+    if (virCgroupGetValueStr(group,
+                             VIR_CGROUP_CONTROLLER_BLKIO,
+                             "blkio.throttle.io_serviced", &str2) < 0)
+        return -1;
+
+    /* sum up all entries of the same kind, from all devices */
+    for (i = 0; i < ARRAY_CARDINALITY(value_names); i++) {
+        p1 = str1;
+        p2 = str2;
+
+        while ((p1 = strstr(p1, value_names[i]))) {
+            p1 += strlen(value_names[i]);
+            if (virStrToLong_ll(p1, &p1, 10, &stats_val) < 0) {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("Cannot parse byte %sstat '%s'"),
+                               value_names[i],
+                               p1);
+                return -1;
+            }
+
+            if (stats_val < 0 ||
+                (stats_val > 0 && *bytes_ptrs[i] > (LLONG_MAX - stats_val)))
+            {
+                virReportError(VIR_ERR_OVERFLOW,
+                               _("Sum of byte %sstat overflows"),
+                               value_names[i]);
+                return -1;
+            }
+            *bytes_ptrs[i] += stats_val;
+        }
+
+        while ((p2 = strstr(p2, value_names[i]))) {
+            p2 += strlen(value_names[i]);
+            if (virStrToLong_ll(p2, &p2, 10, &stats_val) < 0) {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("Cannot parse %srequest stat '%s'"),
+                               value_names[i],
+                               p2);
+                return -1;
+            }
+
+            if (stats_val < 0 ||
+                (stats_val > 0 && *requests_ptrs[i] > (LLONG_MAX - stats_val)))
+            {
+                virReportError(VIR_ERR_OVERFLOW,
+                               _("Sum of %srequest stat overflows"),
+                               value_names[i]);
+                return -1;
+            }
+            *requests_ptrs[i] += stats_val;
+        }
+    }
+
+    return 0;
+}
+
+
 virCgroupBackend virCgroupV1Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
 
@@ -978,6 +1072,7 @@ virCgroupBackend virCgroupV1Backend = {
 
     .setBlkioWeight = virCgroupV1SetBlkioWeight,
     .getBlkioWeight = virCgroupV1GetBlkioWeight,
+    .getBlkioIoServiced = virCgroupV1GetBlkioIoServiced,
 };