Skip to content

Commit

Permalink
Merge pull request moby#5211 from crosbymichael/update-cgroup-defaults
Browse files Browse the repository at this point in the history
Ignore not exist errors for joining default subsystems
  • Loading branch information
unclejack committed Apr 15, 2014
2 parents 994b7ea + 184728e commit 80f6b01
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
26 changes: 17 additions & 9 deletions pkg/cgroups/apply_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (raw *rawCgroup) setupDevices(c *Cgroup, pid int) (err error) {

func (raw *rawCgroup) setupMemory(c *Cgroup, pid int) (err error) {
dir, err := raw.join("memory", pid)
// only return an error for memory if it was not specified
if err != nil && (c.Memory != 0 || c.MemorySwap != 0) {
return err
}
Expand All @@ -145,7 +146,6 @@ func (raw *rawCgroup) setupMemory(c *Cgroup, pid int) (err error) {
}()

if c.Memory != 0 || c.MemorySwap != 0 {

if c.Memory != 0 {
if err := writeFile(dir, "memory.limit_in_bytes", strconv.FormatInt(c.Memory, 10)); err != nil {
return err
Expand Down Expand Up @@ -202,26 +202,34 @@ func (raw *rawCgroup) setupCpuset(c *Cgroup, pid int) (err error) {

func (raw *rawCgroup) setupCpuacct(c *Cgroup, pid int) error {
// we just want to join this group even though we don't set anything
_, err := raw.join("cpuacct", pid)
return err
if _, err := raw.join("cpuacct", pid); err != nil && err != ErrNotFound {
return err
}
return nil
}

func (raw *rawCgroup) setupBlkio(c *Cgroup, pid int) error {
// we just want to join this group even though we don't set anything
_, err := raw.join("blkio", pid)
return err
if _, err := raw.join("blkio", pid); err != nil && err != ErrNotFound {
return err
}
return nil
}

func (raw *rawCgroup) setupPerfevent(c *Cgroup, pid int) error {
// we just want to join this group even though we don't set anything
_, err := raw.join("perf_event", pid)
return err
if _, err := raw.join("perf_event", pid); err != nil && err != ErrNotFound {
return err
}
return nil
}

func (raw *rawCgroup) setupFreezer(c *Cgroup, pid int) error {
// we just want to join this group even though we don't set anything
_, err := raw.join("freezer", pid)
return err
if _, err := raw.join("freezer", pid); err != nil && err != ErrNotFound {
return err
}
return nil
}

func (raw *rawCgroup) Cleanup() error {
Expand Down
10 changes: 7 additions & 3 deletions pkg/cgroups/cgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cgroups

import (
"bufio"
"fmt"
"errors"
"github.com/dotcloud/docker/pkg/mount"
"io"
"io/ioutil"
Expand All @@ -11,6 +11,10 @@ import (
"strings"
)

var (
ErrNotFound = errors.New("mountpoint not found")
)

type Cgroup struct {
Name string `json:"name,omitempty"`
Parent string `json:"parent,omitempty"`
Expand Down Expand Up @@ -44,7 +48,7 @@ func FindCgroupMountpoint(subsystem string) (string, error) {
}
}
}
return "", fmt.Errorf("cgroup mountpoint not found for %s", subsystem)
return "", ErrNotFound
}

// Returns the relative path to the cgroup docker is running in.
Expand Down Expand Up @@ -82,7 +86,7 @@ func parseCgroupFile(subsystem string, r io.Reader) (string, error) {
}
}
}
return "", fmt.Errorf("cgroup '%s' not found in /proc/self/cgroup", subsystem)
return "", ErrNotFound
}

func writeFile(dir, file, data string) error {
Expand Down

0 comments on commit 80f6b01

Please sign in to comment.