Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
src/util/vircgroup.c | 87 ++--------------------------------
src/util/vircgroupbackend.h | 8 ++++
src/util/vircgroupv1.c | 94 +++++++++++++++++++++++++++++++++++++
3 files changed, 105 insertions(+), 84 deletions(-)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index cb9f03d488..a9b67f7d53 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1313,90 +1313,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 2c42227297..90584947fd 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -137,6 +137,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;
@@ -163,6 +170,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 380a310589..4b9c03830c 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -956,6 +956,99 @@ 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, *p2;
+ 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,
@@ -980,6 +1073,7 @@ virCgroupBackend virCgroupV1Backend = {
.setBlkioWeight = virCgroupV1SetBlkioWeight,
.getBlkioWeight = virCgroupV1GetBlkioWeight,
+ .getBlkioIoServiced = virCgroupV1GetBlkioIoServiced,
};
--
2.17.1