From 83b13b08025476233d7acc7d37297abda861be32 Mon Sep 17 00:00:00 2001 Message-Id: <83b13b08025476233d7acc7d37297abda861be32@dist-git> From: Pavel Hrdina Date: Mon, 1 Jul 2019 17:06:16 +0200 Subject: [PATCH] vircgroup: introduce virCgroupAddThread MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Once we introduce cgroup v2 support we need to handle processes and threads differently. Reviewed-by: Fabiano Fidêncio Reviewed-by: Ján Tomko Signed-off-by: Pavel Hrdina (cherry picked from commit 7b526ea57c8ca02e49f6a8cc71a6910f56803bde) Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297 Signed-off-by: Pavel Hrdina Message-Id: Reviewed-by: Ján Tomko --- src/libvirt_private.syms | 1 + src/qemu/qemu_process.c | 2 +- src/util/vircgroup.c | 32 ++++++++++++++++++++++++++++++++ src/util/vircgroup.h | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 5dd24e2e66..f8c1a0df16 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1515,6 +1515,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 c21586fa12..0cd61f02bb 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2538,7 +2538,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 5aa8596b9c..f08fe3600e 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1164,6 +1164,10 @@ typedef enum { /* Same as VIR_CGROUP_TASK_PROCESS but it also adds the task to systemd * named controller. */ VIR_CGROUP_TASK_SYSTEMD = 1 << 1, + + /* Moves only specific thread into cgroup except to systemd + * named controller. */ + VIR_CGROUP_TASK_THREAD = 1 << 2, } virCgroupTaskFlags; @@ -1232,6 +1236,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) @@ -4233,6 +4255,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.22.0