From 658005a178202c691e9dec4dfc9a9e91ecb62420 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Tue, 26 Apr 2016 15:26:44 +0100 Subject: [PATCH] cgroups: properly format attributes path and check for being supported CGroups controller can be mounted by specifying a "noprefix" option, in which case attribute names are named as: / instead of the (more recent) naming schema using: /. For example, Android uses the old format for backward compatibility with user-space. Thus, it's possible in general to work on a target system where some controller are mounted "noprefix" while others not. This patchset adds a set of updates which allows to use the proper attributes naming schema based on how the controller has been mounted. This patch makes use of the Controller::_noprefix option to properly build the attribute path. It adds also a check which reports a more clear error in case an attribute is set which is not provided by the controller. Signed-off-by: Patrick Bellasi --- devlib/module/cgroups.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/devlib/module/cgroups.py b/devlib/module/cgroups.py index 5f87ee7..43d23bb 100644 --- a/devlib/module/cgroups.py +++ b/devlib/module/cgroups.py @@ -189,14 +189,25 @@ class CGroup(object): if isiterable(attrs[idx]): attrs[idx] = list_to_ranges(attrs[idx]) # Build attribute path - path = '{}.{}'.format(self.controller.kind, idx) - path = self.target.path.join(self.directory, path) + if self.controller._noprefix: + attr_name = '{}'.format(idx) + else: + attr_name = '{}.{}'.format(self.controller.kind, idx) + path = self.target.path.join(self.directory, attr_name) self.logger.debug('Set attribute [%s] to: %s"', path, attrs[idx]) # Set the attribute value - self.target.write_value(path, attrs[idx]) + try: + self.target.write_value(path, attrs[idx]) + except TargetError: + # Check if the error is due to a non-existing attribute + attrs = self.get() + if idx not in attrs: + raise ValueError('Controller [{}] does not provide attribute [{}]'\ + .format(self.controller.kind, attr_name)) + raise def get_tasks(self): task_ids = self.target.read_value(self.tasks_file).split()