render / rpms / libvirt

Forked from rpms/libvirt 4 months ago
Clone
c313de
From cb154a1d153edf2c399493a4336aebdccdc628f5 Mon Sep 17 00:00:00 2001
c313de
Message-Id: <cb154a1d153edf2c399493a4336aebdccdc628f5@dist-git>
c313de
From: Pavel Hrdina <phrdina@redhat.com>
c313de
Date: Mon, 1 Jul 2019 17:07:27 +0200
c313de
Subject: [PATCH] vircgroup: introduce virCgroupV2AddTask
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
In cgroups v2 we need to handle threads and processes differently.
c313de
If you need to move a process you need to write its pid into
c313de
cgrou.procs file and it will move the process with all its threads
c313de
as well.  The whole process will be moved if you use tid of any thread.
c313de
c313de
In order to move only threads at first we need to create threaded group
c313de
and after that we can write the relevant thread tids into cgroup.threads
c313de
file.  Threads can be moved only into cgroups that are children of
c313de
cgroup of its process.
c313de
c313de
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c313de
(cherry picked from commit 48572f8825f2bbd7dabb5afb34efbf7afa2f7302)
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: <d6fb582c80903fc7725e2dd15165bd167c916f04.1561993100.git.phrdina@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 src/util/vircgroupv2.c | 15 +++++++++++++++
c313de
 1 file changed, 15 insertions(+)
c313de
c313de
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
c313de
index b5fad47ca0..6ffb5ce786 100644
c313de
--- a/src/util/vircgroupv2.c
c313de
+++ b/src/util/vircgroupv2.c
c313de
@@ -432,6 +432,20 @@ virCgroupV2Remove(virCgroupPtr group)
c313de
 }
c313de
 
c313de
 
c313de
+static int
c313de
+virCgroupV2AddTask(virCgroupPtr group,
c313de
+                   pid_t pid,
c313de
+                   unsigned int flags)
c313de
+{
c313de
+    int controller = virCgroupV2GetAnyController(group);
c313de
+
c313de
+    if (flags & VIR_CGROUP_TASK_THREAD)
c313de
+        return virCgroupSetValueI64(group, controller, "cgroup.threads", pid);
c313de
+    else
c313de
+        return virCgroupSetValueI64(group, controller, "cgroup.procs", pid);
c313de
+}
c313de
+
c313de
+
c313de
 virCgroupBackend virCgroupV2Backend = {
c313de
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
c313de
 
c313de
@@ -449,6 +463,7 @@ virCgroupBackend virCgroupV2Backend = {
c313de
     .pathOfController = virCgroupV2PathOfController,
c313de
     .makeGroup = virCgroupV2MakeGroup,
c313de
     .remove = virCgroupV2Remove,
c313de
+    .addTask = virCgroupV2AddTask,
c313de
 };
c313de
 
c313de
 
c313de
-- 
c313de
2.22.0
c313de