From fc3981ea5c10fb21cae6d6a8e78755be5b169999 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 23 Mar 2015 12:14:03 -0700 Subject: [PATCH 1/2] Revert "cgroups: only return path when subsystem really mounted" This reverts commit 606d9064b0a6abd82da3731fda9f1558ec1f153c. Signed-off-by: Michael Crosby --- cgroups/fs/apply_raw.go | 6 ------ cgroups/fs/blkio.go | 8 ++------ cgroups/fs/cpu.go | 6 +----- cgroups/fs/devices.go | 6 +----- cgroups/fs/freezer.go | 8 ++------ cgroups/fs/memory.go | 9 +++------ 6 files changed, 9 insertions(+), 34 deletions(-) diff --git a/cgroups/fs/apply_raw.go b/cgroups/fs/apply_raw.go index 5cb8467c..2fc95421 100644 --- a/cgroups/fs/apply_raw.go +++ b/cgroups/fs/apply_raw.go @@ -235,12 +235,6 @@ 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) { return filepath.Join(raw.root, subsystem, raw.cgroup), nil diff --git a/cgroups/fs/blkio.go b/cgroups/fs/blkio.go index 01da5d7f..8e132643 100644 --- a/cgroups/fs/blkio.go +++ b/cgroups/fs/blkio.go @@ -17,12 +17,8 @@ type BlkioGroup struct { func (s *BlkioGroup) Apply(d *data) error { dir, err := d.join("blkio") - if err != nil { - if cgroups.IsNotFound(err) { - return nil - } else { - return err - } + if err != nil && !cgroups.IsNotFound(err) { + return err } if err := s.Set(dir, d.c); err != nil { diff --git a/cgroups/fs/cpu.go b/cgroups/fs/cpu.go index 42386fd8..1fbf7b15 100644 --- a/cgroups/fs/cpu.go +++ b/cgroups/fs/cpu.go @@ -18,11 +18,7 @@ func (s *CpuGroup) Apply(d *data) error { // on a container basis dir, err := d.join("cpu") if err != nil { - if cgroups.IsNotFound(err) { - return nil - } else { - return err - } + return err } if err := s.Set(dir, d.c); err != nil { diff --git a/cgroups/fs/devices.go b/cgroups/fs/devices.go index fab8323e..16e00b1c 100644 --- a/cgroups/fs/devices.go +++ b/cgroups/fs/devices.go @@ -11,11 +11,7 @@ type DevicesGroup struct { func (s *DevicesGroup) Apply(d *data) error { dir, err := d.join("devices") if err != nil { - if cgroups.IsNotFound(err) { - return nil - } else { - return err - } + return err } if err := s.Set(dir, d.c); err != nil { diff --git a/cgroups/fs/freezer.go b/cgroups/fs/freezer.go index 5e08e053..fc8241d1 100644 --- a/cgroups/fs/freezer.go +++ b/cgroups/fs/freezer.go @@ -13,12 +13,8 @@ type FreezerGroup struct { func (s *FreezerGroup) Apply(d *data) error { dir, err := d.join("freezer") - if err != nil { - if cgroups.IsNotFound(err) { - return nil - } else { - return err - } + if err != nil && !cgroups.IsNotFound(err) { + return err } if err := s.Set(dir, d.c); err != nil { diff --git a/cgroups/fs/memory.go b/cgroups/fs/memory.go index 68e930fd..b99f8168 100644 --- a/cgroups/fs/memory.go +++ b/cgroups/fs/memory.go @@ -16,12 +16,9 @@ type MemoryGroup struct { func (s *MemoryGroup) Apply(d *data) error { dir, err := d.join("memory") - if err != nil { - if cgroups.IsNotFound(err) { - return nil - } else { - return err - } + // 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 } defer func() { if err != nil { From c5eef904604b7e22083927bb99ea0c196d4cb8b9 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 23 Mar 2015 12:20:18 -0700 Subject: [PATCH 2/2] Add back check for mountpoint to return consistent error Adding this check here allows a nice error displaying that the specified cgroup subsystem is not mounted. Signed-off-by: Michael Crosby --- cgroups/fs/apply_raw.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cgroups/fs/apply_raw.go b/cgroups/fs/apply_raw.go index 2fc95421..5cb8467c 100644 --- a/cgroups/fs/apply_raw.go +++ b/cgroups/fs/apply_raw.go @@ -235,6 +235,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) { return filepath.Join(raw.root, subsystem, raw.cgroup), nil