|
|
c480ed |
From 0418e750369292b3bb7a855b998344042a87622c Mon Sep 17 00:00:00 2001
|
|
|
c480ed |
Message-Id: <0418e750369292b3bb7a855b998344042a87622c@dist-git>
|
|
|
c480ed |
From: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c480ed |
Date: Mon, 1 Jul 2019 17:06:43 +0200
|
|
|
c480ed |
Subject: [PATCH] vircgroup: extract virCgroupV1GetBlkioIoDeviceServiced
|
|
|
c480ed |
MIME-Version: 1.0
|
|
|
c480ed |
Content-Type: text/plain; charset=UTF-8
|
|
|
c480ed |
Content-Transfer-Encoding: 8bit
|
|
|
c480ed |
|
|
|
c480ed |
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
|
|
|
c480ed |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
c480ed |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c480ed |
(cherry picked from commit 44809a28ecfe6f79d18abb55685024128228c7ad)
|
|
|
c480ed |
|
|
|
c480ed |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
|
|
|
c480ed |
|
|
|
c480ed |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c480ed |
Message-Id: <faf6e33b119a729cb9afc63f7446ccb5fcecfb04.1561993100.git.phrdina@redhat.com>
|
|
|
c480ed |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
c480ed |
---
|
|
|
c480ed |
src/util/vircgroup.c | 83 ++--------------------------------
|
|
|
c480ed |
src/util/vircgroupbackend.h | 9 ++++
|
|
|
c480ed |
src/util/vircgrouppriv.h | 2 +
|
|
|
c480ed |
src/util/vircgroupv1.c | 90 +++++++++++++++++++++++++++++++++++++
|
|
|
c480ed |
4 files changed, 105 insertions(+), 79 deletions(-)
|
|
|
c480ed |
|
|
|
c480ed |
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
|
|
|
c480ed |
index 8e46777920..fd39144ed2 100644
|
|
|
c480ed |
--- a/src/util/vircgroup.c
|
|
|
c480ed |
+++ b/src/util/vircgroup.c
|
|
|
c480ed |
@@ -409,7 +409,7 @@ virCgroupDetect(virCgroupPtr group,
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
-static char *
|
|
|
c480ed |
+char *
|
|
|
c480ed |
virCgroupGetBlockDevString(const char *path)
|
|
|
c480ed |
{
|
|
|
c480ed |
char *ret = NULL;
|
|
|
c480ed |
@@ -1337,84 +1337,9 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group,
|
|
|
c480ed |
long long *requests_read,
|
|
|
c480ed |
long long *requests_write)
|
|
|
c480ed |
{
|
|
|
c480ed |
- VIR_AUTOFREE(char *) str1 = NULL;
|
|
|
c480ed |
- VIR_AUTOFREE(char *) str2 = NULL;
|
|
|
c480ed |
- VIR_AUTOFREE(char *) str3 = NULL;
|
|
|
c480ed |
- char *p1 = NULL;
|
|
|
c480ed |
- char *p2 = NULL;
|
|
|
c480ed |
- size_t i;
|
|
|
c480ed |
-
|
|
|
c480ed |
- const char *value_names[] = {
|
|
|
c480ed |
- "Read ",
|
|
|
c480ed |
- "Write "
|
|
|
c480ed |
- };
|
|
|
c480ed |
- long long *bytes_ptrs[] = {
|
|
|
c480ed |
- bytes_read,
|
|
|
c480ed |
- bytes_write
|
|
|
c480ed |
- };
|
|
|
c480ed |
- long long *requests_ptrs[] = {
|
|
|
c480ed |
- requests_read,
|
|
|
c480ed |
- requests_write
|
|
|
c480ed |
- };
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (virCgroupGetValueStr(group,
|
|
|
c480ed |
- VIR_CGROUP_CONTROLLER_BLKIO,
|
|
|
c480ed |
- "blkio.throttle.io_service_bytes", &str1) < 0)
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (virCgroupGetValueStr(group,
|
|
|
c480ed |
- VIR_CGROUP_CONTROLLER_BLKIO,
|
|
|
c480ed |
- "blkio.throttle.io_serviced", &str2) < 0)
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (!(str3 = virCgroupGetBlockDevString(path)))
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (!(p1 = strstr(str1, str3))) {
|
|
|
c480ed |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c480ed |
- _("Cannot find byte stats for block device '%s'"),
|
|
|
c480ed |
- str3);
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
- }
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (!(p2 = strstr(str2, str3))) {
|
|
|
c480ed |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c480ed |
- _("Cannot find request stats for block device '%s'"),
|
|
|
c480ed |
- str3);
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
- }
|
|
|
c480ed |
-
|
|
|
c480ed |
- for (i = 0; i < ARRAY_CARDINALITY(value_names); i++) {
|
|
|
c480ed |
- if (!(p1 = strstr(p1, value_names[i]))) {
|
|
|
c480ed |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c480ed |
- _("Cannot find byte %sstats for block device '%s'"),
|
|
|
c480ed |
- value_names[i], str3);
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
- }
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (virStrToLong_ll(p1 + strlen(value_names[i]), &p1, 10, bytes_ptrs[i]) < 0) {
|
|
|
c480ed |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c480ed |
- _("Cannot parse %sstat '%s'"),
|
|
|
c480ed |
- value_names[i], p1 + strlen(value_names[i]));
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
- }
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (!(p2 = strstr(p2, value_names[i]))) {
|
|
|
c480ed |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c480ed |
- _("Cannot find request %sstats for block device '%s'"),
|
|
|
c480ed |
- value_names[i], str3);
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
- }
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (virStrToLong_ll(p2 + strlen(value_names[i]), &p2, 10, requests_ptrs[i]) < 0) {
|
|
|
c480ed |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c480ed |
- _("Cannot parse %sstat '%s'"),
|
|
|
c480ed |
- value_names[i], p2 + strlen(value_names[i]));
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
- }
|
|
|
c480ed |
- }
|
|
|
c480ed |
-
|
|
|
c480ed |
- return 0;
|
|
|
c480ed |
+ VIR_CGROUP_BACKEND_CALL(group, getBlkioIoDeviceServiced, -1,
|
|
|
c480ed |
+ path, bytes_read, bytes_write,
|
|
|
c480ed |
+ requests_read, requests_write);
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
|
|
|
c480ed |
index 585a2eb353..e16d631a0f 100644
|
|
|
c480ed |
--- a/src/util/vircgroupbackend.h
|
|
|
c480ed |
+++ b/src/util/vircgroupbackend.h
|
|
|
c480ed |
@@ -152,6 +152,14 @@ typedef int
|
|
|
c480ed |
long long *requests_read,
|
|
|
c480ed |
long long *requests_write);
|
|
|
c480ed |
|
|
|
c480ed |
+typedef int
|
|
|
c480ed |
+(*virCgroupGetBlkioIoDeviceServicedCB)(virCgroupPtr group,
|
|
|
c480ed |
+ const char *path,
|
|
|
c480ed |
+ long long *bytes_read,
|
|
|
c480ed |
+ long long *bytes_write,
|
|
|
c480ed |
+ long long *requests_read,
|
|
|
c480ed |
+ long long *requests_write);
|
|
|
c480ed |
+
|
|
|
c480ed |
struct _virCgroupBackend {
|
|
|
c480ed |
virCgroupBackendType type;
|
|
|
c480ed |
|
|
|
c480ed |
@@ -179,6 +187,7 @@ struct _virCgroupBackend {
|
|
|
c480ed |
virCgroupSetBlkioWeightCB setBlkioWeight;
|
|
|
c480ed |
virCgroupGetBlkioWeightCB getBlkioWeight;
|
|
|
c480ed |
virCgroupGetBlkioIoServicedCB getBlkioIoServiced;
|
|
|
c480ed |
+ virCgroupGetBlkioIoDeviceServicedCB getBlkioIoDeviceServiced;
|
|
|
c480ed |
};
|
|
|
c480ed |
typedef struct _virCgroupBackend virCgroupBackend;
|
|
|
c480ed |
typedef virCgroupBackend *virCgroupBackendPtr;
|
|
|
c480ed |
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
|
|
|
c480ed |
index 01714370be..525c288a9a 100644
|
|
|
c480ed |
--- a/src/util/vircgrouppriv.h
|
|
|
c480ed |
+++ b/src/util/vircgrouppriv.h
|
|
|
c480ed |
@@ -80,6 +80,8 @@ int virCgroupSetValueI64(virCgroupPtr group,
|
|
|
c480ed |
|
|
|
c480ed |
int virCgroupPartitionEscape(char **path);
|
|
|
c480ed |
|
|
|
c480ed |
+char *virCgroupGetBlockDevString(const char *path);
|
|
|
c480ed |
+
|
|
|
c480ed |
int virCgroupNewPartition(const char *path,
|
|
|
c480ed |
bool create,
|
|
|
c480ed |
int controllers,
|
|
|
c480ed |
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
|
|
|
c480ed |
index 1afdad4afc..79c4812aef 100644
|
|
|
c480ed |
--- a/src/util/vircgroupv1.c
|
|
|
c480ed |
+++ b/src/util/vircgroupv1.c
|
|
|
c480ed |
@@ -1049,6 +1049,95 @@ virCgroupV1GetBlkioIoServiced(virCgroupPtr group,
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
+static int
|
|
|
c480ed |
+virCgroupV1GetBlkioIoDeviceServiced(virCgroupPtr group,
|
|
|
c480ed |
+ const char *path,
|
|
|
c480ed |
+ long long *bytes_read,
|
|
|
c480ed |
+ long long *bytes_write,
|
|
|
c480ed |
+ long long *requests_read,
|
|
|
c480ed |
+ long long *requests_write)
|
|
|
c480ed |
+{
|
|
|
c480ed |
+ VIR_AUTOFREE(char *) str1 = NULL;
|
|
|
c480ed |
+ VIR_AUTOFREE(char *) str2 = NULL;
|
|
|
c480ed |
+ VIR_AUTOFREE(char *) str3 = NULL;
|
|
|
c480ed |
+ char *p1 = NULL;
|
|
|
c480ed |
+ char *p2 = NULL;
|
|
|
c480ed |
+ size_t i;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ const char *value_names[] = {
|
|
|
c480ed |
+ "Read ",
|
|
|
c480ed |
+ "Write "
|
|
|
c480ed |
+ };
|
|
|
c480ed |
+ long long *bytes_ptrs[] = {
|
|
|
c480ed |
+ bytes_read,
|
|
|
c480ed |
+ bytes_write
|
|
|
c480ed |
+ };
|
|
|
c480ed |
+ long long *requests_ptrs[] = {
|
|
|
c480ed |
+ requests_read,
|
|
|
c480ed |
+ requests_write
|
|
|
c480ed |
+ };
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virCgroupGetValueStr(group,
|
|
|
c480ed |
+ VIR_CGROUP_CONTROLLER_BLKIO,
|
|
|
c480ed |
+ "blkio.throttle.io_service_bytes", &str1) < 0)
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virCgroupGetValueStr(group,
|
|
|
c480ed |
+ VIR_CGROUP_CONTROLLER_BLKIO,
|
|
|
c480ed |
+ "blkio.throttle.io_serviced", &str2) < 0)
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (!(str3 = virCgroupGetBlockDevString(path)))
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (!(p1 = strstr(str1, str3))) {
|
|
|
c480ed |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c480ed |
+ _("Cannot find byte stats for block device '%s'"),
|
|
|
c480ed |
+ str3);
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (!(p2 = strstr(str2, str3))) {
|
|
|
c480ed |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c480ed |
+ _("Cannot find request stats for block device '%s'"),
|
|
|
c480ed |
+ str3);
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ for (i = 0; i < ARRAY_CARDINALITY(value_names); i++) {
|
|
|
c480ed |
+ if (!(p1 = strstr(p1, value_names[i]))) {
|
|
|
c480ed |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c480ed |
+ _("Cannot find byte %sstats for block device '%s'"),
|
|
|
c480ed |
+ value_names[i], str3);
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virStrToLong_ll(p1 + strlen(value_names[i]), &p1, 10, bytes_ptrs[i]) < 0) {
|
|
|
c480ed |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c480ed |
+ _("Cannot parse %sstat '%s'"),
|
|
|
c480ed |
+ value_names[i], p1 + strlen(value_names[i]));
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (!(p2 = strstr(p2, value_names[i]))) {
|
|
|
c480ed |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c480ed |
+ _("Cannot find request %sstats for block device '%s'"),
|
|
|
c480ed |
+ value_names[i], str3);
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virStrToLong_ll(p2 + strlen(value_names[i]), &p2, 10, requests_ptrs[i]) < 0) {
|
|
|
c480ed |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c480ed |
+ _("Cannot parse %sstat '%s'"),
|
|
|
c480ed |
+ value_names[i], p2 + strlen(value_names[i]));
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ return 0;
|
|
|
c480ed |
+}
|
|
|
c480ed |
+
|
|
|
c480ed |
+
|
|
|
c480ed |
virCgroupBackend virCgroupV1Backend = {
|
|
|
c480ed |
.type = VIR_CGROUP_BACKEND_TYPE_V1,
|
|
|
c480ed |
|
|
|
c480ed |
@@ -1074,6 +1163,7 @@ virCgroupBackend virCgroupV1Backend = {
|
|
|
c480ed |
.setBlkioWeight = virCgroupV1SetBlkioWeight,
|
|
|
c480ed |
.getBlkioWeight = virCgroupV1GetBlkioWeight,
|
|
|
c480ed |
.getBlkioIoServiced = virCgroupV1GetBlkioIoServiced,
|
|
|
c480ed |
+ .getBlkioIoDeviceServiced = virCgroupV1GetBlkioIoDeviceServiced,
|
|
|
c480ed |
};
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
--
|
|
|
c480ed |
2.22.0
|
|
|
c480ed |
|