From 82c0f88acedf978cb81e5b193b8559a3ad33cc29 Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Fri, 3 Mar 2023 10:58:09 -0700 Subject: [PATCH] python: Add python bindings for cgroup_add_all_controllers() Add python bindings for adding all controllers to a cgroup instance via cgroup_add_all_controllers(). Signed-off-by: Tom Hromatka Reviewed-by: Kamalesh Babulal (cherry picked from commit 176c3ae82b8e5880e3baca15d7f2a26740bc8b17) --- src/python/cgroup.pxd | 1 + src/python/libcgroup.pyx | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/python/cgroup.pxd b/src/python/cgroup.pxd index b0106583..10775441 100644 --- a/src/python/cgroup.pxd +++ b/src/python/cgroup.pxd @@ -56,6 +56,7 @@ cdef extern from "libcgroup.h": void cgroup_free(cgroup **cg) cgroup_controller *cgroup_add_controller(cgroup *cg, const char *name) + int cgroup_add_all_controllers(cgroup *cg) cgroup_controller *cgroup_get_controller(cgroup *cg, const char *name) int cgroup_add_value_string(cgroup_controller *cgc, const char *name, diff --git a/src/python/libcgroup.pyx b/src/python/libcgroup.pyx index 239ae168..81456ace 100644 --- a/src/python/libcgroup.pyx +++ b/src/python/libcgroup.pyx @@ -130,6 +130,28 @@ cdef class Cgroup: self.controllers[ctrl_name] = Controller(ctrl_name) + def add_all_controllers(self): + """Add all enabled controllers to the Cgroup instance + + Description: + Adds all enabled controllers (i.e. all controllers in the cgroup's cgroup.controllers + file) to the Cgroup instance + + Note: + Reads from the cgroup sysfs + """ + ret = cgroup.cgroup_add_all_controllers(self._cgp) + if ret != 0: + raise RuntimeError("Failed to add all controllers to cgroup") + + ctrl_cnt = cgroup.cgroup_get_controller_count(self._cgp) + for i in range(0, ctrl_cnt): + ctrl_ptr = cgroup.cgroup_get_controller_by_index(self._cgp, i) + ctrl_name = cgroup.cgroup_get_controller_name(ctrl_ptr).decode('ascii') + self.controllers[ctrl_name] = Controller(ctrl_name) + + self._pythonize_cgroup() + def add_setting(self, setting_name, setting_value=None): """Add a setting to the Cgroup/Controller instance -- 2.47.2