#
import consts
+import copy
from controller import Controller
from enum import Enum
import multiprocessing as mp
import time
import utils
+class CgroupMount(object):
+ def __init__(self, mount_line):
+ entries = mount_line.split()
+
+ if entries[2] == "cgroup":
+ self.version = CgroupVersion.CGROUP_V1
+ elif entries[2] == "cgroup2":
+ self.version = CgroupVersion.CGROUP_V2
+ else:
+ raise ValueError("Unknown cgroup version")
+
+ self.mount_point = entries[1]
+
+ 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"
+
+ def __str__(self):
+ out_str = "CgroupMount"
+ out_str += "\n\tMount Point = {}".format(self.mount_point)
+ out_str += "\n\tCgroup Version = {}".format(self.version)
+ if self.controller is not None:
+ out_str += "\n\tController = {}".format(self.controller)
+
+ return out_str
+
class CgroupVersion(Enum):
CGROUP_UNK = 0
CGROUP_V1 = 1
raise re
return ret
+
+ @staticmethod
+ def get_cgroup_mounts(config, expand_v2_mounts=True):
+ mount_list = list()
+
+ with open('/proc/mounts') as mntf:
+ for line in mntf.readlines():
+ entry = line.split()
+
+ if entry[0] != "cgroup" and entry[0] != "cgroup2":
+ continue
+
+ mount = CgroupMount(line)
+
+ if mount.version == CgroupVersion.CGROUP_V1 or \
+ expand_v2_mounts == False:
+ mount_list.append(mount)
+ continue
+
+ with open(os.path.join(mount.mount_point,
+ "cgroup.controllers")) as ctrlf:
+ for line in ctrlf.readlines():
+ for ctrl in line.split():
+ mount_copy = copy.deepcopy(mount)
+ mount_copy.controller = ctrl
+ mount_list.append(mount_copy)
+
+ return mount_list