MCPcopy
hub / github.com/opencontainers/runc / mountCgroupV1

Function mountCgroupV1

libcontainer/rootfs_linux.go:326–397  ·  view source on GitHub ↗
(m mountEntry, c *mountConfig)

Source from the content-addressed store, hash-verified

324}
325
326func mountCgroupV1(m mountEntry, c *mountConfig) error {
327 binds, err := getCgroupMounts(m.Mount)
328 if err != nil {
329 return err
330 }
331 var merged []string
332 for _, b := range binds {
333 ss := filepath.Base(b.Destination)
334 if strings.Contains(ss, ",") {
335 merged = append(merged, ss)
336 }
337 }
338 tmpfs := &configs.Mount{
339 Source: "tmpfs",
340 Device: "tmpfs",
341 Destination: m.Destination,
342 Flags: defaultMountFlags,
343 Data: "mode=755",
344 PropagationFlags: m.PropagationFlags,
345 }
346
347 if err := mountToRootfs(c, mountEntry{Mount: tmpfs}); err != nil {
348 return err
349 }
350
351 for _, b := range binds {
352 if c.cgroupns {
353 // We just created the tmpfs, and so we can just use filepath.Join
354 // here (not to mention we want to make sure we create the path
355 // inside the tmpfs, so we don't want to resolve symlinks).
356 subsystemName := filepath.Base(b.Destination)
357 subsystemDir, err := pathrs.MkdirAllInRoot(c.root, b.Destination, 0o755)
358 if err != nil {
359 return err
360 }
361 defer subsystemDir.Close()
362 if err := utils.WithProcfdFile(subsystemDir, func(dstFd string) error {
363 flags := defaultMountFlags
364 if m.Flags&unix.MS_RDONLY != 0 {
365 flags = flags | unix.MS_RDONLY
366 }
367 var (
368 source = "cgroup"
369 data = subsystemName
370 )
371 if data == "systemd" {
372 data = cgroups.CgroupNamePrefix + data
373 source = "systemd"
374 }
375 return mountViaFds(source, nil, b.Destination, dstFd, "cgroup", uintptr(flags), data)
376 }); err != nil {
377 return err
378 }
379 } else {
380 if err := mountToRootfs(c, mountEntry{Mount: b}); err != nil {
381 return err
382 }
383 }

Callers 1

mountToRootfsFunction · 0.85

Calls 8

MkdirAllInRootFunction · 0.92
WithProcfdFileFunction · 0.92
SymlinkInRootFunction · 0.92
getCgroupMountsFunction · 0.85
mountToRootfsFunction · 0.85
mountViaFdsFunction · 0.85
ContainsMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…