]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
ftests/cgroup.py: add support to list shared mount point
authorTom Hromatka <tom.hromatka@oracle.com>
Fri, 13 Jan 2023 20:41:32 +0000 (13:41 -0700)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 13 Jan 2023 20:41:32 +0000 (13:41 -0700)
Cgroup::get_cgroup_mounts(), could create a list of mount points and in
the case of shared mount points such as cpu,cpuacct in the cgroup v1. It
would only add a mount point for the last of the two controllers listed
as the mount point, for example:
cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpu,cpuacct 0 0

mount list will look over cpu controller.  Add support to recognize and
add both controllers to the list of mount points.

Reported-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
tests/ftests/cgroup.py

index 49ac3945f9189a403412dee0d140fc59eaba82ef..d5fd1d00d9a8fe2f44e6a9afe17408e57c214ae6 100644 (file)
@@ -20,7 +20,7 @@ import os
 
 
 class CgroupMount(object):
-    def __init__(self, mount_line):
+    def __init__(self, mount_line, controller=None):
         entries = mount_line.split()
 
         if entries[2] == 'cgroup':
@@ -32,14 +32,17 @@ class CgroupMount(object):
 
         self.mount_point = entries[1]
 
-        self.controller = None
-        if self.version == CgroupVersion.CGROUP_V1:
-            self.controller = entries[3].split(',')[-1]
+        if controller:
+            self.controller = controller
+        else:
+            self.controller = None
+            if self.version == CgroupVersion.CGROUP_V1:
+                self.controller = entries[3].split(',')[-1]
 
-            if self.controller == 'clone_children':
-                # the cpuset controller may append this option to the end
-                # rather than the controller name like all other controllers
-                self.controller = 'cpuset'
+                if self.controller == 'clone_children':
+                    # the cpuset controller may append this option to the end
+                    # rather than the controller name like all other controllers
+                    self.controller = 'cpuset'
 
     def __str__(self):
         out_str = 'CgroupMount'
@@ -835,6 +838,13 @@ class Cgroup(object):
                 if mount.version == CgroupVersion.CGROUP_V1 or \
                    expand_v2_mounts is False:
                     mount_list.append(mount)
+
+                    if entry[1].find(',') > 0:
+                        # multiple controllers are mounted together.  Also add the
+                        # first controller to the mount_list
+                        controller = os.path.basename(entry[1].split(',')[0])
+                        mount = CgroupMount(line, controller=controller)
+                        mount_list.append(mount)
                     continue
 
                 with open(os.path.join(mount.mount_point,