MCPcopy Create free account
hub / github.com/containers/common / getAvailableControllers

Function getAvailableControllers

pkg/cgroups/cgroups.go:130–181  ·  view source on GitHub ↗

getAvailableControllers get the available controllers

(exclude map[string]controllerHandler, cgroup2 bool)

Source from the content-addressed store, hash-verified

128
129// getAvailableControllers get the available controllers
130func getAvailableControllers(exclude map[string]controllerHandler, cgroup2 bool) ([]controller, error) {
131 if cgroup2 {
132 controllers := []controller{}
133 controllersFile := cgroupRoot + "/cgroup.controllers"
134 // rootless cgroupv2: check available controllers for current user, systemd or servicescope will inherit
135 if unshare.IsRootless() {
136 userSlice, err := getCgroupPathForCurrentProcess()
137 if err != nil {
138 return controllers, err
139 }
140 // userSlice already contains '/' so not adding here
141 basePath := cgroupRoot + userSlice
142 controllersFile = fmt.Sprintf("%s/cgroup.controllers", basePath)
143 }
144 controllersFileBytes, err := ioutil.ReadFile(controllersFile)
145 if err != nil {
146 return nil, errors.Wrapf(err, "failed while reading controllers for cgroup v2 from %q", controllersFile)
147 }
148 for _, controllerName := range strings.Fields(string(controllersFileBytes)) {
149 c := controller{
150 name: controllerName,
151 symlink: false,
152 }
153 controllers = append(controllers, c)
154 }
155 return controllers, nil
156 }
157
158 subsystems, _ := cgroupV1GetAllSubsystems()
159 controllers := []controller{}
160 // cgroupv1 and rootless: No subsystem is available: delegation is unsafe.
161 if unshare.IsRootless() {
162 return controllers, nil
163 }
164
165 for _, name := range subsystems {
166 if _, found := exclude[name]; found {
167 continue
168 }
169 fileInfo, err := os.Stat(cgroupRoot + "/" + name)
170 if err != nil {
171 continue
172 }
173 c := controller{
174 name: name,
175 symlink: !fileInfo.IsDir(),
176 }
177 controllers = append(controllers, c)
178 }
179
180 return controllers, nil
181}
182
183// GetAvailableControllers get string:bool map of all the available controllers
184func GetAvailableControllers(exclude map[string]controllerHandler, cgroup2 bool) ([]string, error) {

Callers 3

GetAvailableControllersFunction · 0.85
NewFunction · 0.85
LoadFunction · 0.85

Calls 3

cgroupV1GetAllSubsystemsFunction · 0.85
StatMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…