]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
python: Add python bindings for cgroup_create_scope2()
authorTom Hromatka <tom.hromatka@oracle.com>
Fri, 27 Jan 2023 21:09:56 +0000 (14:09 -0700)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 27 Jan 2023 21:09:56 +0000 (14:09 -0700)
Add python bindings to create a systemd scope via
cgroup_create_scope2().

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit 84e2a17200ddef957477df486c938412b0ed0ce4)

src/python/cgroup.pxd
src/python/libcgroup.pyx

index b5e679b1946583d5d52c374b9e1b492d6fe43866..0f6e5502f9961f4cd55c42e55b27f9449522dd27 100644 (file)
@@ -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:
index 78f2612d6836493c0a134c207e988f3b66b7b4d1..ff4525c9f32601703b8348bfe98c4ad464ad62f3 100644 (file)
@@ -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);