From 84e2a17200ddef957477df486c938412b0ed0ce4 Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Fri, 27 Jan 2023 13:42:45 -0700 Subject: [PATCH] python: Add python bindings for cgroup_create_scope2() Add python bindings to create a systemd scope via cgroup_create_scope2(). Signed-off-by: Tom Hromatka Reviewed-by: Kamalesh Babulal --- src/python/cgroup.pxd | 3 +++ src/python/libcgroup.pyx | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/python/cgroup.pxd b/src/python/cgroup.pxd index b5e679b1..0f6e5502 100644 --- a/src/python/cgroup.pxd +++ b/src/python/cgroup.pxd @@ -98,4 +98,7 @@ cdef extern from "libcgroup.h": void cgroup_set_permissions(cgroup *cgroup, mode_t control_dperm, mode_t control_fperm, mode_t task_fperm) + int cgroup_create_scope2(cgroup *cgroup, int ignore_ownership, + const cgroup_systemd_scope_opts * const opts) + # vim: set et ts=4 sw=4: diff --git a/src/python/libcgroup.pyx b/src/python/libcgroup.pyx index 78f2612d..ff4525c9 100644 --- a/src/python/libcgroup.pyx +++ b/src/python/libcgroup.pyx @@ -470,6 +470,41 @@ cdef class Cgroup: cgroup.cgroup_set_permissions(self._cgp, dmode, cmode, tmode) + def create_scope2(self, ignore_ownership=True, delegated=True, + systemd_mode=SystemdMode.CGROUP_SYSTEMD_MODE_FAIL, pid=None): + """Create a systemd scope using the cgroup instance + + Arguments: + ignore_ownership - if true, do not modify the owning user/group for the cgroup directory + and control files + delegated - if true, then systemd will not manage the cgroup aspects of the scope. It + is up to the user to manage the cgroup settings + systemd_mode - setting to tell systemd how to handle creation of this scope and + resolve conflicts if the scope and/or slice exist + pid - pid of the process to place in the scope. If None is provided, libcgroup will + place a dummy process in the scope + + Description: + Create a systemd scope using the cgroup instance in this class. If delegated is true, + then systemd will not manage the cgroup aspects of the scope. + """ + cdef cgroup.cgroup_systemd_scope_opts opts + + if delegated: + opts.delegated = 1 + else: + opts.delegated = 0 + + opts.mode = systemd_mode + if pid: + opts.pid = pid + else: + opts.pid = -1 + + ret = cgroup.cgroup_create_scope2(self._cgp, ignore_ownership, &opts) + if ret is not 0: + raise RuntimeError("cgroup_create_scope2 failed: {}".format(ret)) + def __dealloc__(self): cgroup.cgroup_free(&self._cgp); -- 2.47.3