On Tue, Sep 18, 2018 at 2:17 PM, Pavel Hrdina <phrdina@redhat.com> wrote:
Once we introduce cgroup v2 support we need to handle processes and
threads differently.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
 
---
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_process.c  |  2 +-
 src/util/vircgroup.c     | 29 +++++++++++++++++++++++++++++
 src/util/vircgroup.h     |  1 +
 4 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index eac66b0174..ad7ce57b65 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1500,6 +1500,7 @@ virBufferVasprintf;
 # util/vircgroup.h
 virCgroupAddMachineProcess;
 virCgroupAddProcess;
+virCgroupAddThread;
 virCgroupAllowAllDevices;
 virCgroupAllowDevice;
 virCgroupAllowDevicePath;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 249dac39f2..00dcd5b580 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2549,7 +2549,7 @@ qemuProcessSetupPid(virDomainObjPtr vm,
             goto cleanup;

         /* Move the thread to the sub dir */
-        if (virCgroupAddProcess(cgroup, pid) < 0)
+        if (virCgroupAddThread(cgroup, pid) < 0)
             goto cleanup;

     }
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 1d361762c5..3211f63cb1 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1159,6 +1159,7 @@ virCgroupNew(pid_t pid,
 typedef enum {
     VIR_CGROUP_TASK_PROCESS = 0,
     VIR_CGROUP_TASK_SYSTEMD = 1 << 0,
+    VIR_CGROUP_TASK_THREAD = 1 << 1,
 } virCgroupTaskFlags;


@@ -1227,6 +1228,24 @@ virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid)
                                     VIR_CGROUP_TASK_SYSTEMD);
 }

+/**
+ * virCgroupAddThread:
+ *
+ * @group: The cgroup to add a thread to
+ * @pid: The pid of the thread to add
+ *
+ * Will add the thread to all controllers, except the
+ * systemd unit controller.
+ *
+ * Returns: 0 on success, -1 on error
+ */
+int
+virCgroupAddThread(virCgroupPtr group,
+                   pid_t pid)
+{
+    return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_THREAD);
+}
+

 static int
 virCgroupSetPartitionSuffix(const char *path, char **res)
@@ -4228,6 +4247,16 @@ virCgroupAddMachineProcess(virCgroupPtr group ATTRIBUTE_UNUSED,
 }


+int
+virCgroupAddThread(virCgroupPtr group ATTRIBUTE_UNUSED,
+                   pid_t pid ATTRIBUTE_UNUSED)
+{
+    virReportSystemError(ENXIO, "%s",
+                         _("Control groups not supported on this platform"));
+    return -1;
+}
+
+
 int
 virCgroupGetBlkioIoServiced(virCgroupPtr group ATTRIBUTE_UNUSED,
                             long long *bytes_read ATTRIBUTE_UNUSED,
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
index bbd4c2ed57..1f676f21c3 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -120,6 +120,7 @@ int virCgroupPathOfController(virCgroupPtr group,

 int virCgroupAddProcess(virCgroupPtr group, pid_t pid);
 int virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid);
+int virCgroupAddThread(virCgroupPtr group, pid_t pid);

 int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight);
 int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight);
--
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list