]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
python: add support to list cgroup mount points
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 30 Mar 2022 06:19:14 +0000 (11:49 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 1 Apr 2022 14:30:04 +0000 (08:30 -0600)
Add support to the python bindings to list cgroup mount points.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/python/cgroup.pxd
src/python/libcgroup.pyx

index bbd30058ab3f518f544979bfe9c2484e5792317b..7edf6b860732d20cb7ab850b628887b34d412524 100644 (file)
@@ -51,4 +51,7 @@ cdef extern from "libcgroup.h":
     int cgroup_cgxset(const cgroup * const cg, cg_version_t version,
                       bint ignore_unmappable)
 
+    int cgroup_list_mount_points(const cg_version_t cgrp_version,
+                                 char ***mount_paths)
+
 # vim: set et ts=4 sw=4:
index 006fbb5d5290426ffc1f16ae79bf96b626a63d7a..e3e27d2641581127ab925e62de5b7ae47c77838f 100644 (file)
@@ -277,6 +277,29 @@ cdef class Cgroup:
         if ret != 0:
             raise RuntimeError("Failed to create cgroup: {}".format(ret))
 
+    def cgroup_list_mount_points(self, version):
+        """List cgroup mount points of the specified version
+
+        Arguments:
+        version - It specifies the cgroup version
+
+        Description:
+        Parse the /proc/mounts and list the cgroup mount points matching the
+        version
+        """
+        cdef char **a
+
+        mount_points = []
+        ret = cgroup.cgroup_list_mount_points(version, &a)
+        if ret is not 0:
+            raise RuntimeError("cgroup_list_mount_points failed: {}".format(ret));
+
+        i = 0
+        while a[i]:
+            mount_points.append(<str>(a[i]).decode("utf-8"))
+            i = i + 1
+        return mount_points
+
     def __dealloc__(self):
         cgroup.cgroup_free(&self._cgp);