render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 482d6964af9e1f8a4d52253e6474ce11f4a1ca5f Mon Sep 17 00:00:00 2001
Message-Id: <482d6964af9e1f8a4d52253e6474ce11f4a1ca5f@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:15 +0200
Subject: [PATCH] vircgroup: introduce virCgroupTaskFlags
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Use flags in virCgroupAddTaskInternal instead of boolean parameter.
Following patch will add new flag to indicate thread instead of process.

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 36c5989c54cf335b365f4e179a4d7ab7d174bd6e)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <a2cf781e5090f8f3ba2aec04aadb80c957001f7c.1561993099.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircgroup.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index cf510fb019..5aa8596b9c 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1156,8 +1156,21 @@ virCgroupNew(pid_t pid,
 }
 
 
+typedef enum {
+    /* Adds a whole process with all threads to specific cgroup except
+     * to systemd named controller. */
+    VIR_CGROUP_TASK_PROCESS = 1 << 0,
+
+    /* Same as VIR_CGROUP_TASK_PROCESS but it also adds the task to systemd
+     * named controller. */
+    VIR_CGROUP_TASK_SYSTEMD = 1 << 1,
+} virCgroupTaskFlags;
+
+
 static int
-virCgroupAddTaskInternal(virCgroupPtr group, pid_t pid, bool withSystemd)
+virCgroupAddTaskInternal(virCgroupPtr group,
+                         pid_t pid,
+                         unsigned int flags)
 {
     int ret = -1;
     size_t i;
@@ -1170,7 +1183,8 @@ virCgroupAddTaskInternal(virCgroupPtr group, pid_t pid, bool withSystemd)
         /* We must never add tasks in systemd's hierarchy
          * unless we're intentionally trying to move a
          * task into a systemd machine scope */
-        if (i == VIR_CGROUP_CONTROLLER_SYSTEMD && !withSystemd)
+        if (i == VIR_CGROUP_CONTROLLER_SYSTEMD &&
+            !(flags & VIR_CGROUP_TASK_SYSTEMD))
             continue;
 
         if (virCgroupSetValueI64(group, i, "tasks", pid) < 0)
@@ -1196,7 +1210,7 @@ virCgroupAddTaskInternal(virCgroupPtr group, pid_t pid, bool withSystemd)
 int
 virCgroupAddProcess(virCgroupPtr group, pid_t pid)
 {
-    return virCgroupAddTaskInternal(group, pid, false);
+    return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_PROCESS);
 }
 
 /**
@@ -1213,7 +1227,9 @@ virCgroupAddProcess(virCgroupPtr group, pid_t pid)
 int
 virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid)
 {
-    return virCgroupAddTaskInternal(group, pid, true);
+    return virCgroupAddTaskInternal(group, pid,
+                                    VIR_CGROUP_TASK_PROCESS |
+                                    VIR_CGROUP_TASK_SYSTEMD);
 }
 
 
-- 
2.22.0