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