From c212ef21466bb3d8ff5633f3a5bc53777be2b63a Mon Sep 17 00:00:00 2001 From: Javi Merino Date: Mon, 4 Nov 2019 16:20:50 +0000 Subject: [PATCH] module/cgroups: Really move all tasks in Controller.move_all_tasks_to() The docstring of Controller.move_all_tasks_to() says that the function moves all the tasks to the "dest" cgroup. However, it iterates over self._cgroups, which is a dictionary that is lazily populated when you call Controller.cgroup(). For example, this doesn't work: cpuset_cg = target.cgroups.controller("cpuset") cpuset_cg.move_all_tasks_to("top-app") Because you haven't populated self._cgroups yet. You need to manually populate the dictionary with something like: for group in cpuset_cg.list_all(): cpuset_cg.cgroup(group) before you can use move_all_tasks_to(). Iterate through self.list_all() instead of self._cgroups to really move all tasks to to the destination directory. Controller.move_tasks() has a try-except block to get the cgroups of the source and destination groups. Controller.cgroup() caches the groups in self._cgroups and populates it if it hasn't been already. Simplify move_tasks() and let it deal with source and dest cgroups that exist but the controller hasn't loaded yet. --- devlib/module/cgroups.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/devlib/module/cgroups.py b/devlib/module/cgroups.py index 3651755..ecf4d4f 100644 --- a/devlib/module/cgroups.py +++ b/devlib/module/cgroups.py @@ -124,11 +124,10 @@ class Controller(object): def move_tasks(self, source, dest, exclude=None): if exclude is None: exclude = [] - try: - srcg = self._cgroups[source] - dstg = self._cgroups[dest] - except KeyError as e: - raise ValueError('Unknown group: {}'.format(e)) + + srcg = self.cgroup(source) + dstg = self.cgroup(dest) + self.target._execute_util( # pylint: disable=protected-access 'cgroups_tasks_move {} {} \'{}\''.format( srcg.directory, dstg.directory, exclude), @@ -169,7 +168,7 @@ class Controller(object): self.logger.debug(' excluding tasks which name matches:') self.logger.debug(' %s', ', '.join(exclude)) - for cgroup in self._cgroups: + for cgroup in self.list_all(): if cgroup != dest: self.move_tasks(cgroup, dest, grep_filters)