Merge pull request #437 from hqhq/hq_fix_some_cgroups_issues

fix some cgroups issues
This commit is contained in:
Michael Crosby 2015-03-10 14:04:10 -07:00
commit 9387ebb6ba
9 changed files with 43 additions and 16 deletions

View File

@ -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)

View File

@ -17,9 +17,13 @@ type BlkioGroup struct {
func (s *BlkioGroup) Apply(d *data) error {
dir, err := d.join("blkio")
if err != nil && !cgroups.IsNotFound(err) {
if err != nil {
if cgroups.IsNotFound(err) {
return nil
} else {
return err
}
}
if err := s.Set(dir, d.c); err != nil {
return err

View File

@ -18,8 +18,12 @@ 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
}
}
if err := s.Set(dir, d.c); err != nil {
return err

View File

@ -17,8 +17,12 @@ type CpusetGroup struct {
func (s *CpusetGroup) Apply(d *data) error {
dir, err := d.path("cpuset")
if err != nil {
if cgroups.IsNotFound(err) {
return nil
} else {
return err
}
}
return s.ApplyDir(dir, d.c, d.pid)
}

View File

@ -11,8 +11,12 @@ 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
}
}
if err := s.Set(dir, d.c); err != nil {
return err

View File

@ -25,7 +25,7 @@ func TestDevicesSetAllow(t *testing.T) {
defer helper.cleanup()
helper.writeFileContents(map[string]string{
"device.deny": "a",
"devices.deny": "a",
})
helper.CgroupData.c.AllowAllDevices = false
@ -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)

View File

@ -13,9 +13,13 @@ type FreezerGroup struct {
func (s *FreezerGroup) Apply(d *data) error {
dir, err := d.join("freezer")
if err != nil && !cgroups.IsNotFound(err) {
if err != nil {
if cgroups.IsNotFound(err) {
return nil
} else {
return err
}
}
if err := s.Set(dir, d.c); err != nil {
return err

View File

@ -16,10 +16,13 @@ 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) {
if err != nil {
if cgroups.IsNotFound(err) {
return nil
} else {
return err
}
}
defer func() {
if err != nil {
os.RemoveAll(dir)

View File

@ -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"
@ -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)
if err != nil {
t.Fatal(err)
}