Ignore not exist errors for joining default subsystems
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
b0481297a1
commit
f95367f57f
2 changed files with 24 additions and 12 deletions
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue