render / rpms / libvirt

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