From 41d9d2651301a237272b10cd89015a51b6267fdf Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Mon, 11 Jan 2016 16:12:51 -0500 Subject: [PATCH] Add support for just joining in apply using cgroup paths Signed-off-by: Mrunal Patel --- libcontainer/cgroups/fs/apply_raw.go | 21 +++++++++++++++++++ libcontainer/cgroups/systemd/apply_systemd.go | 20 ++++++++++++++++++ libcontainer/configs/cgroup_unix.go | 3 +++ 3 files changed, 44 insertions(+) diff --git a/libcontainer/cgroups/fs/apply_raw.go b/libcontainer/cgroups/fs/apply_raw.go index b6fcc90f..3d1569b3 100644 --- a/libcontainer/cgroups/fs/apply_raw.go +++ b/libcontainer/cgroups/fs/apply_raw.go @@ -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 { @@ -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 { diff --git a/libcontainer/cgroups/systemd/apply_systemd.go b/libcontainer/cgroups/systemd/apply_systemd.go index f8d3a955..0e399773 100644 --- a/libcontainer/cgroups/systemd/apply_systemd.go +++ b/libcontainer/cgroups/systemd/apply_systemd.go @@ -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 } @@ -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) diff --git a/libcontainer/configs/cgroup_unix.go b/libcontainer/configs/cgroup_unix.go index 24a325fe..24c523a6 100644 --- a/libcontainer/configs/cgroup_unix.go +++ b/libcontainer/configs/cgroup_unix.go @@ -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 }