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

Method initialize

pkg/cgroups/cgroups.go:293–333  ·  view source on GitHub ↗

initialize initializes the specified hierarchy

()

Source from the content-addressed store, hash-verified

291
292// initialize initializes the specified hierarchy
293func (c *CgroupControl) initialize() (err error) {
294 createdSoFar := map[string]controllerHandler{}
295 defer func() {
296 if err != nil {
297 for name, ctr := range createdSoFar {
298 if err := ctr.Destroy(c); err != nil {
299 logrus.Warningf("error cleaning up controller %s for %s", name, c.path)
300 }
301 }
302 }
303 }()
304 if c.cgroup2 {
305 if err := createCgroupv2Path(filepath.Join(cgroupRoot, c.path)); err != nil {
306 return errors.Wrapf(err, "error creating cgroup path %s", c.path)
307 }
308 }
309 for name, handler := range handlers {
310 created, err := handler.Create(c)
311 if err != nil {
312 return err
313 }
314 if created {
315 createdSoFar[name] = handler
316 }
317 }
318
319 if !c.cgroup2 {
320 // We won't need to do this for cgroup v2
321 for _, ctr := range c.additionalControllers {
322 if ctr.symlink {
323 continue
324 }
325 path := c.getCgroupv1Path(ctr.name)
326 if err := os.MkdirAll(path, 0755); err != nil {
327 return errors.Wrapf(err, "error creating cgroup path for %s", ctr.name)
328 }
329 }
330 }
331
332 return nil
333}
334
335func (c *CgroupControl) createCgroupDirectory(controller string) (bool, error) {
336 cPath := c.getCgroupv1Path(controller)

Callers 1

NewFunction · 0.95

Calls 4

getCgroupv1PathMethod · 0.95
createCgroupv2PathFunction · 0.85
DestroyMethod · 0.65
CreateMethod · 0.65

Tested by

no test coverage detected