c313de
From 482d6964af9e1f8a4d52253e6474ce11f4a1ca5f Mon Sep 17 00:00:00 2001
c313de
Message-Id: <482d6964af9e1f8a4d52253e6474ce11f4a1ca5f@dist-git>
c313de
From: Pavel Hrdina <phrdina@redhat.com>
c313de
Date: Mon, 1 Jul 2019 17:06:15 +0200
c313de
Subject: [PATCH] vircgroup: introduce virCgroupTaskFlags
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
Use flags in virCgroupAddTaskInternal instead of boolean parameter.
c313de
Following patch will add new flag to indicate thread instead of process.
c313de
c313de
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c313de
(cherry picked from commit 36c5989c54cf335b365f4e179a4d7ab7d174bd6e)
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: <a2cf781e5090f8f3ba2aec04aadb80c957001f7c.1561993099.git.phrdina@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 src/util/vircgroup.c | 24 ++++++++++++++++++++----
c313de
 1 file changed, 20 insertions(+), 4 deletions(-)
c313de
c313de
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c313de
index cf510fb019..5aa8596b9c 100644
c313de
--- a/src/util/vircgroup.c
c313de
+++ b/src/util/vircgroup.c
c313de
@@ -1156,8 +1156,21 @@ virCgroupNew(pid_t pid,
c313de
 }
c313de
 
c313de
 
c313de
+typedef enum {
c313de
+    /* Adds a whole process with all threads to specific cgroup except
c313de
+     * to systemd named controller. */
c313de
+    VIR_CGROUP_TASK_PROCESS = 1 << 0,
c313de
+
c313de
+    /* Same as VIR_CGROUP_TASK_PROCESS but it also adds the task to systemd
c313de
+     * named controller. */
c313de
+    VIR_CGROUP_TASK_SYSTEMD = 1 << 1,
c313de
+} virCgroupTaskFlags;
c313de
+
c313de
+
c313de
 static int
c313de
-virCgroupAddTaskInternal(virCgroupPtr group, pid_t pid, bool withSystemd)
c313de
+virCgroupAddTaskInternal(virCgroupPtr group,
c313de
+                         pid_t pid,
c313de
+                         unsigned int flags)
c313de
 {
c313de
     int ret = -1;
c313de
     size_t i;
c313de
@@ -1170,7 +1183,8 @@ virCgroupAddTaskInternal(virCgroupPtr group, pid_t pid, bool withSystemd)
c313de
         /* We must never add tasks in systemd's hierarchy
c313de
          * unless we're intentionally trying to move a
c313de
          * task into a systemd machine scope */
c313de
-        if (i == VIR_CGROUP_CONTROLLER_SYSTEMD && !withSystemd)
c313de
+        if (i == VIR_CGROUP_CONTROLLER_SYSTEMD &&
c313de
+            !(flags & VIR_CGROUP_TASK_SYSTEMD))
c313de
             continue;
c313de
 
c313de
         if (virCgroupSetValueI64(group, i, "tasks", pid) < 0)
c313de
@@ -1196,7 +1210,7 @@ virCgroupAddTaskInternal(virCgroupPtr group, pid_t pid, bool withSystemd)
c313de
 int
c313de
 virCgroupAddProcess(virCgroupPtr group, pid_t pid)
c313de
 {
c313de
-    return virCgroupAddTaskInternal(group, pid, false);
c313de
+    return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_PROCESS);
c313de
 }
c313de
 
c313de
 /**
c313de
@@ -1213,7 +1227,9 @@ virCgroupAddProcess(virCgroupPtr group, pid_t pid)
c313de
 int
c313de
 virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid)
c313de
 {
c313de
-    return virCgroupAddTaskInternal(group, pid, true);
c313de
+    return virCgroupAddTaskInternal(group, pid,
c313de
+                                    VIR_CGROUP_TASK_PROCESS |
c313de
+                                    VIR_CGROUP_TASK_SYSTEMD);
c313de
 }
c313de
 
c313de
 
c313de
-- 
c313de
2.22.0
c313de