diff --git a/cgroups/fs/apply_raw.go b/cgroups/fs/apply_raw.go index 3a06e6b917e..7dc245595f8 100644 --- a/cgroups/fs/apply_raw.go +++ b/cgroups/fs/apply_raw.go @@ -229,6 +229,12 @@ func (raw *data) parent(subsystem string) (string, error) { } func (raw *data) path(subsystem string) (string, error) { + _, err := cgroups.FindCgroupMountpoint(subsystem) + // If we didn't mount the subsystem, there is no point we make the path. + if err != nil { + return "", err + } + // If the cgroup name/path is absolute do not look relative to the cgroup of the init process. if filepath.IsAbs(raw.cgroup) { path := filepath.Join(raw.root, subsystem, raw.cgroup) diff --git a/cgroups/fs/blkio.go b/cgroups/fs/blkio.go index 8e132643bb9..01da5d7fc7e 100644 --- a/cgroups/fs/blkio.go +++ b/cgroups/fs/blkio.go @@ -17,8 +17,12 @@ type BlkioGroup struct { func (s *BlkioGroup) Apply(d *data) error { dir, err := d.join("blkio") - if err != nil && !cgroups.IsNotFound(err) { - return err + if err != nil { + if cgroups.IsNotFound(err) { + return nil + } else { + return err + } } if err := s.Set(dir, d.c); err != nil { diff --git a/cgroups/fs/cpu.go b/cgroups/fs/cpu.go index 1fbf7b15409..42386fd847b 100644 --- a/cgroups/fs/cpu.go +++ b/cgroups/fs/cpu.go @@ -18,7 +18,11 @@ func (s *CpuGroup) Apply(d *data) error { // on a container basis dir, err := d.join("cpu") if err != nil { - return err + if cgroups.IsNotFound(err) { + return nil + } else { + return err + } } if err := s.Set(dir, d.c); err != nil { diff --git a/cgroups/fs/cpuset.go b/cgroups/fs/cpuset.go index 3ed2f67d59f..75f38cd26b2 100644 --- a/cgroups/fs/cpuset.go +++ b/cgroups/fs/cpuset.go @@ -17,7 +17,11 @@ type CpusetGroup struct { func (s *CpusetGroup) Apply(d *data) error { dir, err := d.path("cpuset") if err != nil { - return err + if cgroups.IsNotFound(err) { + return nil + } else { + return err + } } return s.ApplyDir(dir, d.c, d.pid) } diff --git a/cgroups/fs/devices.go b/cgroups/fs/devices.go index 16e00b1c73b..fab8323e93d 100644 --- a/cgroups/fs/devices.go +++ b/cgroups/fs/devices.go @@ -11,7 +11,11 @@ type DevicesGroup struct { func (s *DevicesGroup) Apply(d *data) error { dir, err := d.join("devices") if err != nil { - return err + if cgroups.IsNotFound(err) { + return nil + } else { + return err + } } if err := s.Set(dir, d.c); err != nil { diff --git a/cgroups/fs/freezer.go b/cgroups/fs/freezer.go index fc8241d1bfd..5e08e05302b 100644 --- a/cgroups/fs/freezer.go +++ b/cgroups/fs/freezer.go @@ -13,8 +13,12 @@ type FreezerGroup struct { func (s *FreezerGroup) Apply(d *data) error { dir, err := d.join("freezer") - if err != nil && !cgroups.IsNotFound(err) { - return err + if err != nil { + if cgroups.IsNotFound(err) { + return nil + } else { + return err + } } if err := s.Set(dir, d.c); err != nil { diff --git a/cgroups/fs/memory.go b/cgroups/fs/memory.go index b99f81687a6..68e930fdc50 100644 --- a/cgroups/fs/memory.go +++ b/cgroups/fs/memory.go @@ -16,9 +16,12 @@ type MemoryGroup struct { func (s *MemoryGroup) Apply(d *data) error { dir, err := d.join("memory") - // only return an error for memory if it was specified - if err != nil && (d.c.Memory != 0 || d.c.MemoryReservation != 0 || d.c.MemorySwap != 0) { - return err + if err != nil { + if cgroups.IsNotFound(err) { + return nil + } else { + return err + } } defer func() { if err != nil {