]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vircgroup: introduce virCgroupV2AddTask
authorPavel Hrdina <phrdina@redhat.com>
Fri, 17 Aug 2018 14:49:33 +0000 (16:49 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Fri, 5 Oct 2018 13:53:29 +0000 (15:53 +0200)
In cgroups v2 we need to handle threads and processes differently.
If you need to move a process you need to write its pid into
cgrou.procs file and it will move the process with all its threads
as well.  The whole process will be moved if you use tid of any thread.

In order to move only threads at first we need to create threaded group
and after that we can write the relevant thread tids into cgroup.threads
file.  Threads can be moved only into cgroups that are children of
cgroup of its process.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/util/vircgroupv2.c

index 8f8e3227c88c1291201b9292b307f135c1d6039f..4319ceb200d52c1addefcde085b352678f013e99 100644 (file)
@@ -431,6 +431,20 @@ virCgroupV2Remove(virCgroupPtr group)
 }
 
 
+static int
+virCgroupV2AddTask(virCgroupPtr group,
+                   pid_t pid,
+                   unsigned int flags)
+{
+    int controller = virCgroupV2GetAnyController(group);
+
+    if (flags & VIR_CGROUP_TASK_THREAD)
+        return virCgroupSetValueI64(group, controller, "cgroup.threads", pid);
+    else
+        return virCgroupSetValueI64(group, controller, "cgroup.procs", pid);
+}
+
+
 virCgroupBackend virCgroupV2Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
 
@@ -448,6 +462,7 @@ virCgroupBackend virCgroupV2Backend = {
     .pathOfController = virCgroupV2PathOfController,
     .makeGroup = virCgroupV2MakeGroup,
     .remove = virCgroupV2Remove,
+    .addTask = virCgroupV2AddTask,
 };