1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 02:00:45 +00:00

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:
   <mountpoint>/<attribute_name>
instead of the (more recent) naming schema using:
   <mountpoint>/<contoller_name>.<attribute_name>

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 <patrick.bellasi@arm.com>
This commit is contained in:
Patrick Bellasi 2016-04-26 15:26:44 +01:00
parent 15f9c03b45
commit 658005a178

View File

@ -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
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()