From: Kamalesh Babulal Date: Tue, 25 Apr 2023 13:01:55 +0000 (+0530) Subject: ftests: cgroup: add support to pass pid for systemd scope X-Git-Tag: v3.1.0~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5176e6139348e8abb8549d2dc71fc444631f024f;p=thirdparty%2Flibcgroup.git ftests: cgroup: add support to pass pid for systemd scope Add support to pass a task pid, while creating systemd slice/scope, this helps the users to specify the task they wish to run instead of the default idle_thread in the transient scope. Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/tests/ftests/cgroup.py b/tests/ftests/cgroup.py index b08d1f9f..e8436f5b 100644 --- a/tests/ftests/cgroup.py +++ b/tests/ftests/cgroup.py @@ -127,7 +127,8 @@ class Cgroup(object): def create(config, controller_list, cgname, user_name=None, group_name=None, dperm=None, fperm=None, tperm=None, tasks_user_name=None, tasks_group_name=None, cghelp=False, - ignore_systemd=False, create_scope=False, set_default_scope=False): + ignore_systemd=False, create_scope=False, set_default_scope=False, + scope_pid=-1): if isinstance(controller_list, str): controller_list = [controller_list] @@ -174,6 +175,12 @@ class Cgroup(object): if set_default_scope: cmd.append('-S') + # -p requires -c to be provided, but this is too checked in libcgroup itself + + if scope_pid > 1: + cmd.append('-p') + cmd.append('{}'.format(scope_pid)) + if controller_list: controllers_and_path = '{}:{}'.format( ','.join(controller_list), cgname) @@ -200,9 +207,10 @@ class Cgroup(object): # True if the cgroup exists, False otherwise @staticmethod def create_and_validate(config, ctrl_name, cgroup_name, ignore_systemd=False, - create_scope=False, set_default_scope=False): + create_scope=False, set_default_scope=False, scope_pid=-1): Cgroup.create(config, ctrl_name, cgroup_name, ignore_systemd=ignore_systemd, - create_scope=create_scope, set_default_scope=set_default_scope) + create_scope=create_scope, set_default_scope=set_default_scope, + scope_pid=scope_pid) return Cgroup.exists(config, ctrl_name, cgroup_name, ignore_systemd=ignore_systemd) @staticmethod