summaryrefslogtreecommitdiff
path: root/src/util/vircgroupv1.c
diff options
context:
space:
mode:
authorPavel Hrdina <phrdina@redhat.com>2021-02-05 16:17:35 +0100
committerPavel Hrdina <phrdina@redhat.com>2021-02-10 13:37:12 +0100
commit9c1693eff427661616ce1bd2795688f87288a412 (patch)
treead511f508aa0acc9d49d50c2a226a8394217d0fa /src/util/vircgroupv1.c
parentd3fb774b1ed548c0338b3338a87094dafea32aa2 (diff)
downloadlibvirt-9c1693eff427661616ce1bd2795688f87288a412.tar.gz
vircgroup: use DBus call to systemd for some APIs
When running on host with systemd we register VMs with machined. In this case systemd creates the root VM cgroup for us. This has some implications where one of them is that systemd owns all files inside the root VM cgroup and we should not touch them. If we change any value in file that systemd knows about it will be changed to what systemd thinks it should be when executing `systemctl daemon-reload`. These are the APIs that we need to call using systemd because they set limits that are proportional to sibling cgroups. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Diffstat (limited to 'src/util/vircgroupv1.c')
-rw-r--r--src/util/vircgroupv1.c48
1 files changed, 34 insertions, 14 deletions
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 2b4d625c35..edb2c23bbc 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -946,7 +946,6 @@ virCgroupV1SetBlkioWeight(virCgroupPtr group,
unsigned int weight)
{
g_autofree char *path = NULL;
- g_autofree char *value = NULL;
if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.bfq.weight", &path) < 0) {
@@ -968,9 +967,15 @@ virCgroupV1SetBlkioWeight(virCgroupPtr group,
return -1;
}
- value = g_strdup_printf("%u", weight);
+ if (group->unitName) {
+ GVariant *value = g_variant_new("t", weight);
+
+ return virCgroupSetValueDBus(group->unitName, "BlockIOWeight", value);
+ } else {
+ g_autofree char *value = g_strdup_printf("%u", weight);
- return virCgroupSetValueRaw(path, value);
+ return virCgroupSetValueRaw(path, value);
+ }
}
@@ -1203,15 +1208,8 @@ virCgroupV1SetBlkioDeviceWeight(virCgroupPtr group,
const char *devPath,
unsigned int weight)
{
- g_autofree char *str = NULL;
- g_autofree char *blkstr = NULL;
g_autofree char *path = NULL;
- if (!(blkstr = virCgroupGetBlockDevString(devPath)))
- return -1;
-
- str = g_strdup_printf("%s%d", blkstr, weight);
-
if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.weight_device", &path) < 0) {
return -1;
@@ -1223,7 +1221,23 @@ virCgroupV1SetBlkioDeviceWeight(virCgroupPtr group,
return -1;
}
- return virCgroupSetValueRaw(path, str);
+ if (group->unitName) {
+ GVariant *value = NULL;
+
+ value = g_variant_new_parsed("[(%s, uint64 %u)]", path, weight);
+
+ return virCgroupSetValueDBus(group->unitName, "BlockIODeviceWeight", value);
+ } else {
+ g_autofree char *str = NULL;
+ g_autofree char *blkstr = NULL;
+
+ if (!(blkstr = virCgroupGetBlockDevString(devPath)))
+ return -1;
+
+ str = g_strdup_printf("%s%d", blkstr, weight);
+
+ return virCgroupSetValueRaw(path, str);
+ }
}
@@ -1862,9 +1876,15 @@ static int
virCgroupV1SetCpuShares(virCgroupPtr group,
unsigned long long shares)
{
- return virCgroupSetValueU64(group,
- VIR_CGROUP_CONTROLLER_CPU,
- "cpu.shares", shares);
+ if (group->unitName) {
+ GVariant *value = g_variant_new("t", shares);
+
+ return virCgroupSetValueDBus(group->unitName, "CPUShares", value);
+ } else {
+ return virCgroupSetValueU64(group,
+ VIR_CGROUP_CONTROLLER_CPU,
+ "cpu.shares", shares);
+ }
}