libvirt/SOURCES/libvirt-vircgroup-extract-v...

266 lines
8.7 KiB
Diff

From 3cb8992be4013fb3ae978c62f6a433080e74130a Mon Sep 17 00:00:00 2001
Message-Id: <3cb8992be4013fb3ae978c62f6a433080e74130a@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:42 +0200
Subject: [PATCH] vircgroup: extract virCgroupV1GetBlkioIoServiced
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 4baa08ace12d2db7e7023b2abe915360bc7dcddf)
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <aa03ae2eef4e9a09d28562f7218c302ec095a912.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/util/vircgroup.c | 87 ++-------------------------------
src/util/vircgroupbackend.h | 8 ++++
src/util/vircgroupv1.c | 95 +++++++++++++++++++++++++++++++++++++
3 files changed, 106 insertions(+), 84 deletions(-)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index d2ffa8aefe..8e46777920 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1311,90 +1311,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);
}
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index ccce65f1e2..585a2eb353 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -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;
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index d67b3164ce..1afdad4afc 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -955,6 +955,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,
@@ -979,6 +1073,7 @@ virCgroupBackend virCgroupV1Backend = {
.setBlkioWeight = virCgroupV1SetBlkioWeight,
.getBlkioWeight = virCgroupV1GetBlkioWeight,
+ .getBlkioIoServiced = virCgroupV1GetBlkioIoServiced,
};
--
2.22.0