Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions libcontainer/cgroups/fs/apply_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,29 @@ func (m *Manager) Apply(pid int) (err error) {
return nil
}

var c = m.Cgroups

d, err := getCgroupData(m.Cgroups, pid)
if err != nil {
return err
}

if c.Paths != nil {
paths := make(map[string]string)
for name, path := range c.Paths {
_, err := d.path(name)
if err != nil {
if cgroups.IsNotFound(err) {
continue
}
return err
}
paths[name] = path
}
m.Paths = paths
return cgroups.EnterPid(m.Paths, pid)
}

paths := make(map[string]string)
defer func() {
if err != nil {
Expand Down Expand Up @@ -138,6 +156,9 @@ func (m *Manager) Apply(pid int) (err error) {
}

func (m *Manager) Destroy() error {
if m.Cgroups.Paths != nil {
return nil
}
m.mu.Lock()
defer m.mu.Unlock()
if err := cgroups.RemovePaths(m.Paths); err != nil {
Expand Down
20 changes: 20 additions & 0 deletions libcontainer/cgroups/systemd/apply_systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,23 @@ func (m *Manager) Apply(pid int) error {
properties []systemdDbus.Property
)

if c.Paths != nil {
paths := make(map[string]string)
for name, path := range c.Paths {
_, err := getSubsystemPath(m.Cgroups, name)
if err != nil {
// Don't fail if a cgroup hierarchy was not found, just skip this subsystem
if cgroups.IsNotFound(err) {
continue
}
return err
}
paths[name] = path
}
m.Paths = paths
return cgroups.EnterPid(m.Paths, pid)
}

if c.Parent != "" {
slice = c.Parent
}
Expand Down Expand Up @@ -286,6 +303,9 @@ func (m *Manager) Apply(pid int) error {
}

func (m *Manager) Destroy() error {
if m.Cgroups.Paths != nil {
return nil
}
m.mu.Lock()
defer m.mu.Unlock()
theConn.StopUnit(getUnitName(m.Cgroups), "replace", nil)
Expand Down
3 changes: 3 additions & 0 deletions libcontainer/configs/cgroup_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ type Cgroup struct {
// ScopePrefix decribes prefix for the scope name
ScopePrefix string `json:"scope_prefix"`

// Paths represent the cgroups paths to join
Paths map[string]string

// Resources contains various cgroups settings to apply
*Resources
}
Expand Down