libvirt/SOURCES/libvirt-vircgroup-extract-virCgroupV1GetBlkioIoDeviceServiced.patch
2021-09-10 11:57:18 +00:00

279 lines
9.4 KiB
Diff

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