Skip to content

Commit 2363d45

Browse files
CgroupsPath in runC
This sets up the cgroupsPath. If cgroupsPath is passed in, runC will check if the cgroup exists. If it exists, runC will just join the cgroup, and will not make any modifications to the cgroups. If it does not exist, runC will create the cgroup and join it. Signed-off-by: Abin Shahab <[email protected]>
1 parent 7767914 commit 2363d45

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

libcontainer/cgroups/fs/apply_raw.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func (m *Manager) Apply(pid int) (err error) {
122122
if err := sys.Apply(d); err != nil {
123123
return err
124124
}
125+
125126
// TODO: Apply should, ideally, be reentrant or be broken up into a separate
126127
// create and join phase so that the cgroup hierarchy for a container can be
127128
// created then join consists of writing the process pids to cgroup.procs
@@ -289,8 +290,14 @@ func (raw *cgroupData) join(subsystem string) (string, error) {
289290
if err != nil {
290291
return "", err
291292
}
292-
if err := os.MkdirAll(path, 0755); err != nil {
293-
return "", err
293+
_, err = os.Stat(path)
294+
if err != nil && os.IsNotExist(err) {
295+
if err := os.MkdirAll(path, 0755); err != nil {
296+
return "", err
297+
}
298+
} else if err == nil {
299+
//cgroup exists, therefore join only
300+
raw.config.ExternalCgroup = true
294301
}
295302
if err := writeFile(path, CgroupProcesses, strconv.Itoa(raw.pid)); err != nil {
296303
return "", err

libcontainer/cgroups/fs/devices.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ func (s *DevicesGroup) Apply(d *cgroupData) error {
3030
}
3131

3232
func (s *DevicesGroup) Set(path string, cgroup *configs.Cgroup) error {
33+
if cgroup.ExternalCgroup {
34+
return nil
35+
}
3336
if !cgroup.AllowAllDevices {
3437
if err := writeFile(path, "devices.deny", "a"); err != nil {
3538
return err

libcontainer/configs/cgroup_unix.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const (
1212

1313
type Cgroup struct {
1414
Name string `json:"name"`
15+
// indicates that this is an externally passed, fully created cgroup
16+
ExternalCgroup bool `json:"external_cgroup"`
1517

1618
// name of parent cgroup or slice
1719
Parent string `json:"parent"`

spec.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,9 @@ func createCgroupConfig(name string, spec *specs.LinuxRuntimeSpec, devices []*co
437437
if err != nil {
438438
return nil, err
439439
}
440+
if spec.Linux.CgroupsPath != "" {
441+
name = spec.Linux.CgroupsPath
442+
}
440443
c := &configs.Cgroup{
441444
Name: name,
442445
Parent: myCgroupPath,

0 commit comments

Comments
 (0)