From f95367f57f0c397be621d0480d830c736865f298 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 14 Apr 2014 00:02:01 +0000 Subject: [PATCH] Ignore not exist errors for joining default subsystems Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- cgroups/apply_raw.go | 26 +++++++++++++++++--------- cgroups/cgroups.go | 10 +++++++--- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/cgroups/apply_raw.go b/cgroups/apply_raw.go index 1700294..471d3fc 100644 --- a/cgroups/apply_raw.go +++ b/cgroups/apply_raw.go @@ -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 } @@ -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 @@ -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 { diff --git a/cgroups/cgroups.go b/cgroups/cgroups.go index 5fe1034..e5e8f82 100644 --- a/cgroups/cgroups.go +++ b/cgroups/cgroups.go @@ -2,7 +2,7 @@ package cgroups import ( "bufio" - "fmt" + "errors" "github.com/dotcloud/docker/pkg/mount" "io" "io/ioutil" @@ -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"` @@ -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. @@ -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 {