libvirt/SOURCES/libvirt-vircgroup-extract-virCgroupV1-Set-Get-BlkioWeight.patch
2021-09-10 11:57:18 +00:00

151 lines
4.8 KiB
Diff

From 7fae41a63cd97501e3a4bf8fade48949d754f738 Mon Sep 17 00:00:00 2001
Message-Id: <7fae41a63cd97501e3a4bf8fade48949d754f738@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:41 +0200
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)BlkioWeight
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 c57b0be0cc200abb21cbe0473d96f447fd37b27d)
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <23b514919f71ed2a44c04d7f62a031c4edc14365.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/util/vircgroup.c | 14 ++------------
src/util/vircgroupbackend.h | 20 ++++++++++++++++++++
src/util/vircgroupv1.c | 29 +++++++++++++++++++++++++++++
3 files changed, 51 insertions(+), 12 deletions(-)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index e57aecb08a..d2ffa8aefe 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1510,10 +1510,7 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group,
int
virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight)
{
- return virCgroupSetValueU64(group,
- VIR_CGROUP_CONTROLLER_BLKIO,
- "blkio.weight",
- weight);
+ VIR_CGROUP_BACKEND_CALL(group, setBlkioWeight, -1, weight);
}
@@ -1528,14 +1525,7 @@ virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight)
int
virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight)
{
- unsigned long long tmp;
- int ret;
- ret = virCgroupGetValueU64(group,
- VIR_CGROUP_CONTROLLER_BLKIO,
- "blkio.weight", &tmp);
- if (ret == 0)
- *weight = tmp;
- return ret;
+ VIR_CGROUP_BACKEND_CALL(group, getBlkioWeight, -1, weight);
}
/**
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index 74af796c2f..ccce65f1e2 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -137,6 +137,14 @@ typedef int
gid_t gid,
int controllers);
+typedef int
+(*virCgroupSetBlkioWeightCB)(virCgroupPtr group,
+ unsigned int weight);
+
+typedef int
+(*virCgroupGetBlkioWeightCB)(virCgroupPtr group,
+ unsigned int *weight);
+
struct _virCgroupBackend {
virCgroupBackendType type;
@@ -159,6 +167,10 @@ struct _virCgroupBackend {
virCgroupHasEmptyTasksCB hasEmptyTasks;
virCgroupBindMountCB bindMount;
virCgroupSetOwnerCB setOwner;
+
+ /* Optional cgroup controller specific callbacks. */
+ virCgroupSetBlkioWeightCB setBlkioWeight;
+ virCgroupGetBlkioWeightCB getBlkioWeight;
};
typedef struct _virCgroupBackend virCgroupBackend;
typedef virCgroupBackend *virCgroupBackendPtr;
@@ -169,4 +181,12 @@ virCgroupBackendRegister(virCgroupBackendPtr backend);
virCgroupBackendPtr *
virCgroupBackendGetAll(void);
+# define VIR_CGROUP_BACKEND_CALL(group, func, ret, ...) \
+ if (!group->backend->func) { \
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED, \
+ _("operation '%s' not supported"), #func); \
+ return ret; \
+ } \
+ return group->backend->func(group, ##__VA_ARGS__);
+
#endif /* __VIR_CGROUP_BACKEND_H__ */
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index c1e2583912..d67b3164ce 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -929,6 +929,32 @@ virCgroupV1SetOwner(virCgroupPtr cgroup,
}
+static int
+virCgroupV1SetBlkioWeight(virCgroupPtr group,
+ unsigned int weight)
+{
+ return virCgroupSetValueU64(group,
+ VIR_CGROUP_CONTROLLER_BLKIO,
+ "blkio.weight",
+ weight);
+}
+
+
+static int
+virCgroupV1GetBlkioWeight(virCgroupPtr group,
+ unsigned int *weight)
+{
+ unsigned long long tmp;
+ int ret;
+ ret = virCgroupGetValueU64(group,
+ VIR_CGROUP_CONTROLLER_BLKIO,
+ "blkio.weight", &tmp);
+ if (ret == 0)
+ *weight = tmp;
+ return ret;
+}
+
+
virCgroupBackend virCgroupV1Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V1,
@@ -950,6 +976,9 @@ virCgroupBackend virCgroupV1Backend = {
.hasEmptyTasks = virCgroupV1HasEmptyTasks,
.bindMount = virCgroupV1BindMount,
.setOwner = virCgroupV1SetOwner,
+
+ .setBlkioWeight = virCgroupV1SetBlkioWeight,
+ .getBlkioWeight = virCgroupV1GetBlkioWeight,
};
--
2.22.0