|
|
397dc2 |
From 41a7547b32786b1a84c8ee7bad0c4cf9559ea4b9 Mon Sep 17 00:00:00 2001
|
|
|
397dc2 |
Message-Id: <41a7547b32786b1a84c8ee7bad0c4cf9559ea4b9@dist-git>
|
|
|
397dc2 |
From: Pavel Hrdina <phrdina@redhat.com>
|
|
|
397dc2 |
Date: Fri, 19 Feb 2021 13:33:57 +0100
|
|
|
397dc2 |
Subject: [PATCH] vircgroupv2: move task into cgroup before enabling
|
|
|
397dc2 |
controllers
|
|
|
397dc2 |
MIME-Version: 1.0
|
|
|
397dc2 |
Content-Type: text/plain; charset=UTF-8
|
|
|
397dc2 |
Content-Transfer-Encoding: 8bit
|
|
|
397dc2 |
|
|
|
397dc2 |
When we create a new child cgroup and the parent cgroup has any process
|
|
|
397dc2 |
attached to it enabling controllers for the child cgroup fails with
|
|
|
397dc2 |
error. We need to move the process into the child cgroup first before
|
|
|
397dc2 |
enabling any controllers.
|
|
|
397dc2 |
|
|
|
397dc2 |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
397dc2 |
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
397dc2 |
(cherry picked from commit 382fa15cde538cba3888a89b301fd3d9a0ce69ea)
|
|
|
397dc2 |
|
|
|
397dc2 |
Conflicts:
|
|
|
397dc2 |
src/util/vircgroup.c
|
|
|
397dc2 |
- missing upstream g_autofree rewrite
|
|
|
397dc2 |
|
|
|
397dc2 |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1798463
|
|
|
397dc2 |
|
|
|
397dc2 |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
397dc2 |
Message-Id: <85d34403caacb571cb78539d5c4f56eee9484d57.1613737828.git.phrdina@redhat.com>
|
|
|
397dc2 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
397dc2 |
---
|
|
|
397dc2 |
src/util/vircgroup.c | 13 +++++++------
|
|
|
397dc2 |
src/util/vircgroupbackend.h | 1 +
|
|
|
397dc2 |
src/util/vircgroupv1.c | 1 +
|
|
|
397dc2 |
src/util/vircgroupv2.c | 13 +++++++++++++
|
|
|
397dc2 |
4 files changed, 22 insertions(+), 6 deletions(-)
|
|
|
397dc2 |
|
|
|
397dc2 |
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
|
|
|
397dc2 |
index 10b934291c..8f5bcd94f4 100644
|
|
|
397dc2 |
--- a/src/util/vircgroup.c
|
|
|
397dc2 |
+++ b/src/util/vircgroup.c
|
|
|
397dc2 |
@@ -622,13 +622,14 @@ static int
|
|
|
397dc2 |
virCgroupMakeGroup(virCgroupPtr parent,
|
|
|
397dc2 |
virCgroupPtr group,
|
|
|
397dc2 |
bool create,
|
|
|
397dc2 |
+ pid_t pid,
|
|
|
397dc2 |
unsigned int flags)
|
|
|
397dc2 |
{
|
|
|
397dc2 |
size_t i;
|
|
|
397dc2 |
|
|
|
397dc2 |
for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
|
|
|
397dc2 |
if (group->backends[i] &&
|
|
|
397dc2 |
- group->backends[i]->makeGroup(parent, group, create, flags) < 0) {
|
|
|
397dc2 |
+ group->backends[i]->makeGroup(parent, group, create, pid, flags) < 0) {
|
|
|
397dc2 |
virCgroupRemove(group);
|
|
|
397dc2 |
return -1;
|
|
|
397dc2 |
}
|
|
|
397dc2 |
@@ -857,8 +858,8 @@ virCgroupNewPartition(const char *path,
|
|
|
397dc2 |
goto cleanup;
|
|
|
397dc2 |
|
|
|
397dc2 |
if (parent) {
|
|
|
397dc2 |
- if (virCgroupMakeGroup(parent, *group, create, VIR_CGROUP_NONE) < 0)
|
|
|
397dc2 |
- goto cleanup;
|
|
|
397dc2 |
+ if (virCgroupMakeGroup(parent, *group, create, -1, VIR_CGROUP_NONE) < 0)
|
|
|
397dc2 |
+ return -1;
|
|
|
397dc2 |
}
|
|
|
397dc2 |
|
|
|
397dc2 |
ret = 0;
|
|
|
397dc2 |
@@ -924,7 +925,7 @@ virCgroupNewDomainPartition(virCgroupPtr partition,
|
|
|
397dc2 |
* a group for driver, is to avoid overhead to track
|
|
|
397dc2 |
* cumulative usage that we don't need.
|
|
|
397dc2 |
*/
|
|
|
397dc2 |
- if (virCgroupMakeGroup(partition, *group, create,
|
|
|
397dc2 |
+ if (virCgroupMakeGroup(partition, *group, create, -1,
|
|
|
397dc2 |
VIR_CGROUP_MEM_HIERACHY) < 0) {
|
|
|
397dc2 |
virCgroupFree(group);
|
|
|
397dc2 |
return -1;
|
|
|
397dc2 |
@@ -978,7 +979,7 @@ virCgroupNewThread(virCgroupPtr domain,
|
|
|
397dc2 |
if (virCgroupNew(-1, name, domain, controllers, group) < 0)
|
|
|
397dc2 |
return -1;
|
|
|
397dc2 |
|
|
|
397dc2 |
- if (virCgroupMakeGroup(domain, *group, create, VIR_CGROUP_THREAD) < 0) {
|
|
|
397dc2 |
+ if (virCgroupMakeGroup(domain, *group, create, -1, VIR_CGROUP_THREAD) < 0) {
|
|
|
397dc2 |
virCgroupFree(group);
|
|
|
397dc2 |
return -1;
|
|
|
397dc2 |
}
|
|
|
397dc2 |
@@ -1065,7 +1066,7 @@ virCgroupEnableMissingControllers(char *path,
|
|
|
397dc2 |
&tmp) < 0)
|
|
|
397dc2 |
goto cleanup;
|
|
|
397dc2 |
|
|
|
397dc2 |
- if (virCgroupMakeGroup(parent, tmp, true, VIR_CGROUP_SYSTEMD) < 0) {
|
|
|
397dc2 |
+ if (virCgroupMakeGroup(parent, tmp, true, -1, VIR_CGROUP_SYSTEMD) < 0) {
|
|
|
397dc2 |
virCgroupFree(&tmp);
|
|
|
397dc2 |
goto cleanup;
|
|
|
397dc2 |
}
|
|
|
397dc2 |
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
|
|
|
397dc2 |
index e12a2e8b9d..ac7b3ae517 100644
|
|
|
397dc2 |
--- a/src/util/vircgroupbackend.h
|
|
|
397dc2 |
+++ b/src/util/vircgroupbackend.h
|
|
|
397dc2 |
@@ -119,6 +119,7 @@ typedef int
|
|
|
397dc2 |
(*virCgroupMakeGroupCB)(virCgroupPtr parent,
|
|
|
397dc2 |
virCgroupPtr group,
|
|
|
397dc2 |
bool create,
|
|
|
397dc2 |
+ pid_t pid,
|
|
|
397dc2 |
unsigned int flags);
|
|
|
397dc2 |
|
|
|
397dc2 |
typedef int
|
|
|
397dc2 |
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
|
|
|
397dc2 |
index 09165ece4d..eb2b611cee 100644
|
|
|
397dc2 |
--- a/src/util/vircgroupv1.c
|
|
|
397dc2 |
+++ b/src/util/vircgroupv1.c
|
|
|
397dc2 |
@@ -601,6 +601,7 @@ static int
|
|
|
397dc2 |
virCgroupV1MakeGroup(virCgroupPtr parent,
|
|
|
397dc2 |
virCgroupPtr group,
|
|
|
397dc2 |
bool create,
|
|
|
397dc2 |
+ pid_t pid G_GNUC_UNUSED,
|
|
|
397dc2 |
unsigned int flags)
|
|
|
397dc2 |
{
|
|
|
397dc2 |
size_t i;
|
|
|
397dc2 |
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
|
|
|
397dc2 |
index 8fe4894a9e..5e19ed8332 100644
|
|
|
397dc2 |
--- a/src/util/vircgroupv2.c
|
|
|
397dc2 |
+++ b/src/util/vircgroupv2.c
|
|
|
397dc2 |
@@ -398,10 +398,17 @@ virCgroupV2EnableController(virCgroupPtr group,
|
|
|
397dc2 |
}
|
|
|
397dc2 |
|
|
|
397dc2 |
|
|
|
397dc2 |
+static int
|
|
|
397dc2 |
+virCgroupV2AddTask(virCgroupPtr group,
|
|
|
397dc2 |
+ pid_t pid,
|
|
|
397dc2 |
+ unsigned int flags);
|
|
|
397dc2 |
+
|
|
|
397dc2 |
+
|
|
|
397dc2 |
static int
|
|
|
397dc2 |
virCgroupV2MakeGroup(virCgroupPtr parent,
|
|
|
397dc2 |
virCgroupPtr group,
|
|
|
397dc2 |
bool create,
|
|
|
397dc2 |
+ pid_t pid,
|
|
|
397dc2 |
unsigned int flags)
|
|
|
397dc2 |
{
|
|
|
397dc2 |
g_autofree char *path = NULL;
|
|
|
397dc2 |
@@ -449,6 +456,12 @@ virCgroupV2MakeGroup(virCgroupPtr parent,
|
|
|
397dc2 |
}
|
|
|
397dc2 |
} else {
|
|
|
397dc2 |
size_t i;
|
|
|
397dc2 |
+
|
|
|
397dc2 |
+ if (pid > 0) {
|
|
|
397dc2 |
+ if (virCgroupV2AddTask(group, pid, VIR_CGROUP_TASK_PROCESS) < 0)
|
|
|
397dc2 |
+ return -1;
|
|
|
397dc2 |
+ }
|
|
|
397dc2 |
+
|
|
|
397dc2 |
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
|
|
|
397dc2 |
int rc;
|
|
|
397dc2 |
|
|
|
397dc2 |
--
|
|
|
397dc2 |
2.30.0
|
|
|
397dc2 |
|