Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.
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
6 changes: 6 additions & 0 deletions cgroups/fs/apply_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions cgroups/fs/blkio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion cgroups/fs/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion cgroups/fs/cpuset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 5 additions & 1 deletion cgroups/fs/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions cgroups/fs/devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestDevicesSetAllow(t *testing.T) {
defer helper.cleanup()

helper.writeFileContents(map[string]string{
"device.deny": "a",
"devices.deny": "a",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch :) I've been meaning to const all these paths and use those consts.

})

helper.CgroupData.c.AllowAllDevices = false
Expand All @@ -35,8 +35,6 @@ func TestDevicesSetAllow(t *testing.T) {
t.Fatal(err)
}

// FIXME: this doesn't make sence, the file devices.allow under real cgroupfs
// is not allowed to read. Our test path don't have cgroupfs mounted.
value, err := getCgroupParamString(helper.CgroupPath, "devices.allow")
if err != nil {
t.Fatalf("Failed to parse devices.allow - %s", err)
Expand Down
8 changes: 6 additions & 2 deletions cgroups/fs/freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions cgroups/fs/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions cgroups/fs/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Creates a mock of the cgroup filesystem for the duration of the test.
package fs

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/docker/libcontainer/configs"
Expand All @@ -31,12 +31,12 @@ func NewCgroupTestUtil(subsystem string, t *testing.T) *cgroupTestUtil {
d := &data{
c: &configs.Cgroup{},
}
tempDir, err := ioutil.TempDir("", fmt.Sprintf("%s_cgroup_test", subsystem))
tempDir, err := ioutil.TempDir("", "cgroup_test")
if err != nil {
t.Fatal(err)
}
d.root = tempDir
testCgroupPath, err := d.path(subsystem)
testCgroupPath := filepath.Join(d.root, subsystem)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! This used to not be possible, thanks for the fix.

if err != nil {
t.Fatal(err)
}
Expand Down