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

209 lines
6.9 KiB
Diff

From af26c5b793fcd0206a105e75c6583ddfe57557c2 Mon Sep 17 00:00:00 2001
Message-Id: <af26c5b793fcd0206a105e75c6583ddfe57557c2@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:44 +0200
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceWeight
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 8f50f9ca24596c838082c7d8da4ffe7104d22b23)
Conflicts:
src/util/vircgroup.c - missing commit 34e9c29357
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <1ad5f481f00748a6808760b50f4d1d0116191073.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/util/vircgroup.c | 36 +++-----------------------
src/util/vircgroupbackend.h | 12 +++++++++
src/util/vircgrouppriv.h | 6 +++++
src/util/vircgroupv1.c | 50 +++++++++++++++++++++++++++++++++++++
4 files changed, 71 insertions(+), 33 deletions(-)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index fd39144ed2..83ceb3a9cb 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -498,7 +498,7 @@ virCgroupGetValueStr(virCgroupPtr group,
}
-static int
+int
virCgroupGetValueForBlkDev(virCgroupPtr group,
int controller,
const char *key,
@@ -1501,19 +1501,7 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group,
const char *path,
unsigned int weight)
{
- VIR_AUTOFREE(char *) str = NULL;
- VIR_AUTOFREE(char *) blkstr = NULL;
-
- if (!(blkstr = virCgroupGetBlockDevString(path)))
- return -1;
-
- if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
- return -1;
-
- return virCgroupSetValueStr(group,
- VIR_CGROUP_CONTROLLER_BLKIO,
- "blkio.weight_device",
- str);
+ VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWeight, -1, path, weight);
}
/**
@@ -1665,25 +1653,7 @@ virCgroupGetBlkioDeviceWeight(virCgroupPtr group,
const char *path,
unsigned int *weight)
{
- VIR_AUTOFREE(char *) str = NULL;
-
- if (virCgroupGetValueForBlkDev(group,
- VIR_CGROUP_CONTROLLER_BLKIO,
- "blkio.weight_device",
- path,
- &str) < 0)
- return -1;
-
- if (!str) {
- *weight = 0;
- } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unable to parse '%s' as an integer"),
- str);
- return -1;
- }
-
- return 0;
+ VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceWeight, -1, path, weight);
}
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index e16d631a0f..aef2a87c61 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -160,6 +160,16 @@ typedef int
long long *requests_read,
long long *requests_write);
+typedef int
+(*virCgroupSetBlkioDeviceWeightCB)(virCgroupPtr group,
+ const char *path,
+ unsigned int weight);
+
+typedef int
+(*virCgroupGetBlkioDeviceWeightCB)(virCgroupPtr group,
+ const char *path,
+ unsigned int *weight);
+
struct _virCgroupBackend {
virCgroupBackendType type;
@@ -188,6 +198,8 @@ struct _virCgroupBackend {
virCgroupGetBlkioWeightCB getBlkioWeight;
virCgroupGetBlkioIoServicedCB getBlkioIoServiced;
virCgroupGetBlkioIoDeviceServicedCB getBlkioIoDeviceServiced;
+ virCgroupSetBlkioDeviceWeightCB setBlkioDeviceWeight;
+ virCgroupGetBlkioDeviceWeightCB getBlkioDeviceWeight;
};
typedef struct _virCgroupBackend virCgroupBackend;
typedef virCgroupBackend *virCgroupBackendPtr;
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
index 525c288a9a..3a968c1ce2 100644
--- a/src/util/vircgrouppriv.h
+++ b/src/util/vircgrouppriv.h
@@ -82,6 +82,12 @@ int virCgroupPartitionEscape(char **path);
char *virCgroupGetBlockDevString(const char *path);
+int virCgroupGetValueForBlkDev(virCgroupPtr group,
+ int controller,
+ const char *key,
+ const char *path,
+ char **value);
+
int virCgroupNewPartition(const char *path,
bool create,
int controllers,
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 79c4812aef..1e5f38a2ee 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -1138,6 +1138,54 @@ virCgroupV1GetBlkioIoDeviceServiced(virCgroupPtr group,
}
+static int
+virCgroupV1SetBlkioDeviceWeight(virCgroupPtr group,
+ const char *path,
+ unsigned int weight)
+{
+ VIR_AUTOFREE(char *) str = NULL;
+ VIR_AUTOFREE(char *) blkstr = NULL;
+
+ if (!(blkstr = virCgroupGetBlockDevString(path)))
+ return -1;
+
+ if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
+ return -1;
+
+ return virCgroupSetValueStr(group,
+ VIR_CGROUP_CONTROLLER_BLKIO,
+ "blkio.weight_device",
+ str);
+}
+
+
+static int
+virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group,
+ const char *path,
+ unsigned int *weight)
+{
+ VIR_AUTOFREE(char *) str = NULL;
+
+ if (virCgroupGetValueForBlkDev(group,
+ VIR_CGROUP_CONTROLLER_BLKIO,
+ "blkio.weight_device",
+ path,
+ &str) < 0)
+ return -1;
+
+ if (!str) {
+ *weight = 0;
+ } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unable to parse '%s' as an integer"),
+ str);
+ return -1;
+ }
+
+ return 0;
+}
+
+
virCgroupBackend virCgroupV1Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V1,
@@ -1164,6 +1212,8 @@ virCgroupBackend virCgroupV1Backend = {
.getBlkioWeight = virCgroupV1GetBlkioWeight,
.getBlkioIoServiced = virCgroupV1GetBlkioIoServiced,
.getBlkioIoDeviceServiced = virCgroupV1GetBlkioIoDeviceServiced,
+ .setBlkioDeviceWeight = virCgroupV1SetBlkioDeviceWeight,
+ .getBlkioDeviceWeight = virCgroupV1GetBlkioDeviceWeight,
};
--
2.22.0