[PATCH 7/9] vircgroup: add controller mask to virCgroupAddTask

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a way to exclude controllers from virCgroupAddTask. In a cgroup
hierarchy the parent might have controllers just to allow children
cgroups to inherit them, not necessarily to put any tasks in them.

Signed-off-by: Henning Schild <henning.schild@xxxxxxxxxxx>
---
 src/lxc/lxc_cgroup.c     | 2 +-
 src/lxc/lxc_controller.c | 4 ++--
 src/qemu/qemu_cgroup.c   | 8 ++++----
 src/qemu/qemu_driver.c   | 2 +-
 src/util/vircgroup.c     | 8 ++++++--
 src/util/vircgroup.h     | 2 +-
 6 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index 609e9ea..9b91dd2 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -504,7 +504,7 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def,
                             &cgroup) < 0)
         goto cleanup;
 
-    if (virCgroupAddTask(cgroup, initpid) < 0) {
+    if (virCgroupAddTask(cgroup, initpid, -1) < 0) {
         virErrorPtr saved = virSaveLastError();
         virCgroupRemove(cgroup);
         virCgroupFree(&cgroup);
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 438103a..b1fe8fa 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -863,12 +863,12 @@ static int virLXCControllerSetupCgroupLimits(virLXCControllerPtr ctrl)
                                             ctrl->nicindexes)))
         goto cleanup;
 
-    if (virCgroupAddTask(ctrl->cgroup, getpid()) < 0)
+    if (virCgroupAddTask(ctrl->cgroup, getpid(), -1) < 0)
         goto cleanup;
 
     /* Add all qemu-nbd tasks to the cgroup */
     for (i = 0; i < ctrl->nnbdpids; i++) {
-        if (virCgroupAddTask(ctrl->cgroup, ctrl->nbdpids[i]) < 0)
+        if (virCgroupAddTask(ctrl->cgroup, ctrl->nbdpids[i], -1) < 0)
             goto cleanup;
     }
 
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index d410a66..41a583c 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -789,7 +789,7 @@ qemuInitCgroup(virQEMUDriverPtr driver,
         goto cleanup;
     }
 
-    if (virCgroupAddTask(priv->cgroup, vm->pid) < 0) {
+    if (virCgroupAddTask(priv->cgroup, vm->pid, -1) < 0) {
         virErrorPtr saved = virSaveLastError();
         virCgroupRemove(priv->cgroup);
         virCgroupFree(&priv->cgroup);
@@ -1096,7 +1096,7 @@ qemuSetupCgroupForVcpu(virDomainObjPtr vm)
 
         /* move the thread for vcpu to sub dir */
         if (virCgroupAddTask(cgroup_vcpu,
-                             qemuDomainGetVcpuPid(vm, i)) < 0)
+                             qemuDomainGetVcpuPid(vm, i), -1) < 0)
             goto cleanup;
 
     }
@@ -1145,7 +1145,7 @@ qemuSetupCgroupForEmulator(virDomainObjPtr vm)
                            true, &cgroup_emulator) < 0)
         goto cleanup;
 
-    if (virCgroupAddTask(cgroup_emulator, vm->pid) < 0)
+    if (virCgroupAddTask(cgroup_emulator, vm->pid, -1) < 0)
        goto cleanup;
 
     if (def->cputune.emulatorpin)
@@ -1255,7 +1255,7 @@ qemuSetupCgroupForIOThreads(virDomainObjPtr vm)
 
         /* move the thread for iothread to sub dir */
         if (virCgroupAddTask(cgroup_iothread,
-                             def->iothreadids[i]->thread_id) < 0)
+                             def->iothreadids[i]->thread_id, -1) < 0)
             goto cleanup;
 
         virCgroupFree(&cgroup_iothread);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8ccf68b..c0b840b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4583,7 +4583,7 @@ qemuDomainAddCgroupForThread(virCgroupPtr cgroup,
         goto error;
 
     /* Add pid/thread to the cgroup */
-    rv = virCgroupAddTask(new_cgroup, pid);
+    rv = virCgroupAddTask(new_cgroup, pid, -1);
     if (rv < 0) {
         virCgroupRemove(new_cgroup);
         goto error;
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index c31c83b..bbc88f3 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1142,16 +1142,19 @@ virCgroupNew(pid_t pid,
  *
  * @group: The cgroup to add a task to
  * @pid: The pid of the task to add
+ * @controllers: mask of controllers to operate on
  *
  * Returns: 0 on success, -1 on error
  */
 int
-virCgroupAddTask(virCgroupPtr group, pid_t pid)
+virCgroupAddTask(virCgroupPtr group, pid_t pid, int controllers)
 {
     int ret = -1;
     size_t i;
 
     for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
+        if (((controllers & (1 << i)) == 0))
+            continue;
         /* Skip over controllers not mounted */
         if (!group->controllers[i].mountPoint)
             continue;
@@ -4197,7 +4200,8 @@ virCgroupPathOfController(virCgroupPtr group ATTRIBUTE_UNUSED,
 
 int
 virCgroupAddTask(virCgroupPtr group ATTRIBUTE_UNUSED,
-                 pid_t pid ATTRIBUTE_UNUSED)
+                 pid_t pid ATTRIBUTE_UNUSED,
+                 int controllers ATTRIBUTE_UNUSED)
 {
     virReportSystemError(ENXIO, "%s",
                          _("Control groups not supported on this platform"));
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
index 0286d56..d9c5100 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -132,7 +132,7 @@ int virCgroupPathOfController(virCgroupPtr group,
                               const char *key,
                               char **path);
 
-int virCgroupAddTask(virCgroupPtr group, pid_t pid);
+int virCgroupAddTask(virCgroupPtr group, pid_t pid, int controllers);
 
 int virCgroupAddTaskController(virCgroupPtr group,
                                pid_t pid,
-- 
2.4.10

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]