render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c480ed
From 83b13b08025476233d7acc7d37297abda861be32 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <83b13b08025476233d7acc7d37297abda861be32@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:06:16 +0200
c480ed
Subject: [PATCH] vircgroup: introduce virCgroupAddThread
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
Once we introduce cgroup v2 support we need to handle processes and
c480ed
threads differently.
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 7b526ea57c8ca02e49f6a8cc71a6910f56803bde)
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: <ed2085fc086090e3865b08758e973e0eedd78a4d.1561993099.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/libvirt_private.syms |  1 +
c480ed
 src/qemu/qemu_process.c  |  2 +-
c480ed
 src/util/vircgroup.c     | 32 ++++++++++++++++++++++++++++++++
c480ed
 src/util/vircgroup.h     |  1 +
c480ed
 4 files changed, 35 insertions(+), 1 deletion(-)
c480ed
c480ed
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
c480ed
index 5dd24e2e66..f8c1a0df16 100644
c480ed
--- a/src/libvirt_private.syms
c480ed
+++ b/src/libvirt_private.syms
c480ed
@@ -1515,6 +1515,7 @@ virBufferVasprintf;
c480ed
 # util/vircgroup.h
c480ed
 virCgroupAddMachineProcess;
c480ed
 virCgroupAddProcess;
c480ed
+virCgroupAddThread;
c480ed
 virCgroupAllowAllDevices;
c480ed
 virCgroupAllowDevice;
c480ed
 virCgroupAllowDevicePath;
c480ed
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
c480ed
index c21586fa12..0cd61f02bb 100644
c480ed
--- a/src/qemu/qemu_process.c
c480ed
+++ b/src/qemu/qemu_process.c
c480ed
@@ -2538,7 +2538,7 @@ qemuProcessSetupPid(virDomainObjPtr vm,
c480ed
             goto cleanup;
c480ed
 
c480ed
         /* Move the thread to the sub dir */
c480ed
-        if (virCgroupAddProcess(cgroup, pid) < 0)
c480ed
+        if (virCgroupAddThread(cgroup, pid) < 0)
c480ed
             goto cleanup;
c480ed
 
c480ed
     }
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index 5aa8596b9c..f08fe3600e 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -1164,6 +1164,10 @@ typedef enum {
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
+
c480ed
+    /* Moves only specific thread into cgroup except to systemd
c480ed
+     * named controller. */
c480ed
+    VIR_CGROUP_TASK_THREAD = 1 << 2,
c480ed
 } virCgroupTaskFlags;
c480ed
 
c480ed
 
c480ed
@@ -1232,6 +1236,24 @@ virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid)
c480ed
                                     VIR_CGROUP_TASK_SYSTEMD);
c480ed
 }
c480ed
 
c480ed
+/**
c480ed
+ * virCgroupAddThread:
c480ed
+ *
c480ed
+ * @group: The cgroup to add a thread to
c480ed
+ * @pid: The pid of the thread to add
c480ed
+ *
c480ed
+ * Will add the thread to all controllers, except the
c480ed
+ * systemd unit controller.
c480ed
+ *
c480ed
+ * Returns: 0 on success, -1 on error
c480ed
+ */
c480ed
+int
c480ed
+virCgroupAddThread(virCgroupPtr group,
c480ed
+                   pid_t pid)
c480ed
+{
c480ed
+    return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_THREAD);
c480ed
+}
c480ed
+
c480ed
 
c480ed
 static int
c480ed
 virCgroupSetPartitionSuffix(const char *path, char **res)
c480ed
@@ -4233,6 +4255,16 @@ virCgroupAddMachineProcess(virCgroupPtr group ATTRIBUTE_UNUSED,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+int
c480ed
+virCgroupAddThread(virCgroupPtr group ATTRIBUTE_UNUSED,
c480ed
+                   pid_t pid ATTRIBUTE_UNUSED)
c480ed
+{
c480ed
+    virReportSystemError(ENXIO, "%s",
c480ed
+                         _("Control groups not supported on this platform"));
c480ed
+    return -1;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 int
c480ed
 virCgroupGetBlkioIoServiced(virCgroupPtr group ATTRIBUTE_UNUSED,
c480ed
                             long long *bytes_read ATTRIBUTE_UNUSED,
c480ed
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
c480ed
index bbd4c2ed57..1f676f21c3 100644
c480ed
--- a/src/util/vircgroup.h
c480ed
+++ b/src/util/vircgroup.h
c480ed
@@ -120,6 +120,7 @@ int virCgroupPathOfController(virCgroupPtr group,
c480ed
 
c480ed
 int virCgroupAddProcess(virCgroupPtr group, pid_t pid);
c480ed
 int virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid);
c480ed
+int virCgroupAddThread(virCgroupPtr group, pid_t pid);
c480ed
 
c480ed
 int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight);
c480ed
 int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight);
c480ed
-- 
c480ed
2.22.0
c480ed