mirror of https://github.com/docker/docs.git
Merge pull request #7648 from crosbymichael/update-libcontainer-aug5
Update libcontainer to db65c35051d05f3fb218a0e84a1
This commit is contained in:
commit
b1d20c483a
|
@ -59,7 +59,7 @@ rm -rf src/code.google.com/p/go
|
||||||
mkdir -p src/code.google.com/p/go/src/pkg/archive
|
mkdir -p src/code.google.com/p/go/src/pkg/archive
|
||||||
mv tmp-tar src/code.google.com/p/go/src/pkg/archive/tar
|
mv tmp-tar src/code.google.com/p/go/src/pkg/archive/tar
|
||||||
|
|
||||||
clone git github.com/docker/libcontainer 29363e2d2d7b8f62a5f353be333758f83df540a9
|
clone git github.com/docker/libcontainer db65c35051d05f3fb218a0e84a11267e0894fe0a
|
||||||
# see src/github.com/docker/libcontainer/update-vendor.sh which is the "source of truth" for libcontainer deps (just like this file)
|
# see src/github.com/docker/libcontainer/update-vendor.sh which is the "source of truth" for libcontainer deps (just like this file)
|
||||||
rm -rf src/github.com/docker/libcontainer/vendor
|
rm -rf src/github.com/docker/libcontainer/vendor
|
||||||
eval "$(grep '^clone ' src/github.com/docker/libcontainer/update-vendor.sh | grep -v 'github.com/codegangsta/cli')"
|
eval "$(grep '^clone ' src/github.com/docker/libcontainer/update-vendor.sh | grep -v 'github.com/codegangsta/cli')"
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
package cgroups
|
package cgroups
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"fmt"
|
||||||
|
|
||||||
"github.com/docker/libcontainer/devices"
|
"github.com/docker/libcontainer/devices"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
ErrNotFound = errors.New("mountpoint not found")
|
|
||||||
)
|
|
||||||
|
|
||||||
type FreezerState string
|
type FreezerState string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -18,6 +14,29 @@ const (
|
||||||
Thawed FreezerState = "THAWED"
|
Thawed FreezerState = "THAWED"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type NotFoundError struct {
|
||||||
|
Subsystem string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *NotFoundError) Error() string {
|
||||||
|
return fmt.Sprintf("mountpoint for %s not found", e.Subsystem)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNotFoundError(sub string) error {
|
||||||
|
return &NotFoundError{
|
||||||
|
Subsystem: sub,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsNotFound(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
_, ok := err.(*NotFoundError)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
type Cgroup struct {
|
type Cgroup struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Parent string `json:"parent,omitempty"` // name of parent cgroup or slice
|
Parent string `json:"parent,omitempty"` // name of parent cgroup or slice
|
||||||
|
|
|
@ -76,7 +76,7 @@ func GetStats(c *cgroups.Cgroup) (*cgroups.Stats, error) {
|
||||||
path, err := d.path(sysname)
|
path, err := d.path(sysname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Don't fail if a cgroup hierarchy was not found, just skip this subsystem
|
// Don't fail if a cgroup hierarchy was not found, just skip this subsystem
|
||||||
if err == cgroups.ErrNotFound {
|
if cgroups.IsNotFound(err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,25 +155,45 @@ func (raw *data) parent(subsystem string) (string, error) {
|
||||||
|
|
||||||
func (raw *data) Paths() (map[string]string, error) {
|
func (raw *data) Paths() (map[string]string, error) {
|
||||||
paths := make(map[string]string)
|
paths := make(map[string]string)
|
||||||
|
|
||||||
for sysname := range subsystems {
|
for sysname := range subsystems {
|
||||||
path, err := raw.path(sysname)
|
path, err := raw.path(sysname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// Don't fail if a cgroup hierarchy was not found, just skip this subsystem
|
||||||
|
if cgroups.IsNotFound(err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
paths[sysname] = path
|
paths[sysname] = path
|
||||||
}
|
}
|
||||||
|
|
||||||
return paths, nil
|
return paths, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (raw *data) path(subsystem string) (string, error) {
|
func (raw *data) path(subsystem string) (string, error) {
|
||||||
// If the cgroup name/path is absolute do not look relative to the cgroup of the init process.
|
// If the cgroup name/path is absolute do not look relative to the cgroup of the init process.
|
||||||
if filepath.IsAbs(raw.cgroup) {
|
if filepath.IsAbs(raw.cgroup) {
|
||||||
return filepath.Join(raw.root, subsystem, raw.cgroup), nil
|
path := filepath.Join(raw.root, subsystem, raw.cgroup)
|
||||||
|
|
||||||
|
if _, err := os.Stat(path); err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return "", cgroups.NewNotFoundError(subsystem)
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return path, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
parent, err := raw.parent(subsystem)
|
parent, err := raw.parent(subsystem)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return filepath.Join(parent, raw.cgroup), nil
|
return filepath.Join(parent, raw.cgroup), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,10 @@ type BlkioGroup struct {
|
||||||
|
|
||||||
func (s *BlkioGroup) Set(d *data) error {
|
func (s *BlkioGroup) Set(d *data) error {
|
||||||
// we just want to join this group even though we don't set anything
|
// we just want to join this group even though we don't set anything
|
||||||
if _, err := d.join("blkio"); err != nil && err != cgroups.ErrNotFound {
|
if _, err := d.join("blkio"); err != nil && !cgroups.IsNotFound(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,10 @@ type CpuacctGroup struct {
|
||||||
|
|
||||||
func (s *CpuacctGroup) Set(d *data) error {
|
func (s *CpuacctGroup) Set(d *data) error {
|
||||||
// we just want to join this group even though we don't set anything
|
// we just want to join this group even though we don't set anything
|
||||||
if _, err := d.join("cpuacct"); err != nil && err != cgroups.ErrNotFound {
|
if _, err := d.join("cpuacct"); err != nil && !cgroups.IsNotFound(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ func (s *FreezerGroup) Set(d *data) error {
|
||||||
time.Sleep(1 * time.Millisecond)
|
time.Sleep(1 * time.Millisecond)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if _, err := d.join("freezer"); err != nil && err != cgroups.ErrNotFound {
|
if _, err := d.join("freezer"); err != nil && !cgroups.IsNotFound(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ type PerfEventGroup struct {
|
||||||
|
|
||||||
func (s *PerfEventGroup) Set(d *data) error {
|
func (s *PerfEventGroup) Set(d *data) error {
|
||||||
// we just want to join this group even though we don't set anything
|
// we just want to join this group even though we don't set anything
|
||||||
if _, err := d.join("perf_event"); err != nil && err != cgroups.ErrNotFound {
|
if _, err := d.join("perf_event"); err != nil && !cgroups.IsNotFound(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -5,8 +5,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/libcontainer/cgroups"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -68,20 +66,3 @@ func TestGetCgroupParamsInt(t *testing.T) {
|
||||||
t.Fatal("Expecting error, got none")
|
t.Fatal("Expecting error, got none")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAbsolutePathHandling(t *testing.T) {
|
|
||||||
testCgroup := cgroups.Cgroup{
|
|
||||||
Name: "bar",
|
|
||||||
Parent: "/foo",
|
|
||||||
}
|
|
||||||
cgroupData := data{
|
|
||||||
root: "/sys/fs/cgroup",
|
|
||||||
cgroup: "/foo/bar",
|
|
||||||
c: &testCgroup,
|
|
||||||
pid: 1,
|
|
||||||
}
|
|
||||||
expectedPath := filepath.Join(cgroupData.root, "cpu", testCgroup.Parent, testCgroup.Name)
|
|
||||||
if path, err := cgroupData.path("cpu"); path != expectedPath || err != nil {
|
|
||||||
t.Fatalf("expected path %s but got %s %s", expectedPath, path, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -13,8 +13,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
systemd1 "github.com/coreos/go-systemd/dbus"
|
systemd "github.com/coreos/go-systemd/dbus"
|
||||||
"github.com/docker/docker/pkg/systemd"
|
|
||||||
"github.com/docker/libcontainer/cgroups"
|
"github.com/docker/libcontainer/cgroups"
|
||||||
"github.com/docker/libcontainer/cgroups/fs"
|
"github.com/docker/libcontainer/cgroups/fs"
|
||||||
"github.com/godbus/dbus"
|
"github.com/godbus/dbus"
|
||||||
|
@ -30,7 +29,7 @@ type subsystem interface {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
connLock sync.Mutex
|
connLock sync.Mutex
|
||||||
theConn *systemd1.Conn
|
theConn *systemd.Conn
|
||||||
hasStartTransientUnit bool
|
hasStartTransientUnit bool
|
||||||
subsystems = map[string]subsystem{
|
subsystems = map[string]subsystem{
|
||||||
"devices": &fs.DevicesGroup{},
|
"devices": &fs.DevicesGroup{},
|
||||||
|
@ -45,7 +44,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func UseSystemd() bool {
|
func UseSystemd() bool {
|
||||||
if !systemd.SdBooted() {
|
s, err := os.Stat("/run/systemd/system")
|
||||||
|
if err != nil || !s.IsDir() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ func UseSystemd() bool {
|
||||||
|
|
||||||
if theConn == nil {
|
if theConn == nil {
|
||||||
var err error
|
var err error
|
||||||
theConn, err = systemd1.New()
|
theConn, err = systemd.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ func Apply(c *cgroups.Cgroup, pid int) (cgroups.ActiveCgroup, error) {
|
||||||
var (
|
var (
|
||||||
unitName = getUnitName(c)
|
unitName = getUnitName(c)
|
||||||
slice = "system.slice"
|
slice = "system.slice"
|
||||||
properties []systemd1.Property
|
properties []systemd.Property
|
||||||
res = &systemdCgroup{}
|
res = &systemdCgroup{}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -99,27 +99,27 @@ func Apply(c *cgroups.Cgroup, pid int) (cgroups.ActiveCgroup, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
properties = append(properties,
|
properties = append(properties,
|
||||||
systemd1.Property{"Slice", dbus.MakeVariant(slice)},
|
systemd.Property{"Slice", dbus.MakeVariant(slice)},
|
||||||
systemd1.Property{"Description", dbus.MakeVariant("docker container " + c.Name)},
|
systemd.Property{"Description", dbus.MakeVariant("docker container " + c.Name)},
|
||||||
systemd1.Property{"PIDs", dbus.MakeVariant([]uint32{uint32(pid)})},
|
systemd.Property{"PIDs", dbus.MakeVariant([]uint32{uint32(pid)})},
|
||||||
)
|
)
|
||||||
|
|
||||||
// Always enable accounting, this gets us the same behaviour as the fs implementation,
|
// Always enable accounting, this gets us the same behaviour as the fs implementation,
|
||||||
// plus the kernel has some problems with joining the memory cgroup at a later time.
|
// plus the kernel has some problems with joining the memory cgroup at a later time.
|
||||||
properties = append(properties,
|
properties = append(properties,
|
||||||
systemd1.Property{"MemoryAccounting", dbus.MakeVariant(true)},
|
systemd.Property{"MemoryAccounting", dbus.MakeVariant(true)},
|
||||||
systemd1.Property{"CPUAccounting", dbus.MakeVariant(true)},
|
systemd.Property{"CPUAccounting", dbus.MakeVariant(true)},
|
||||||
systemd1.Property{"BlockIOAccounting", dbus.MakeVariant(true)})
|
systemd.Property{"BlockIOAccounting", dbus.MakeVariant(true)})
|
||||||
|
|
||||||
if c.Memory != 0 {
|
if c.Memory != 0 {
|
||||||
properties = append(properties,
|
properties = append(properties,
|
||||||
systemd1.Property{"MemoryLimit", dbus.MakeVariant(uint64(c.Memory))})
|
systemd.Property{"MemoryLimit", dbus.MakeVariant(uint64(c.Memory))})
|
||||||
}
|
}
|
||||||
// TODO: MemoryReservation and MemorySwap not available in systemd
|
// TODO: MemoryReservation and MemorySwap not available in systemd
|
||||||
|
|
||||||
if c.CpuShares != 0 {
|
if c.CpuShares != 0 {
|
||||||
properties = append(properties,
|
properties = append(properties,
|
||||||
systemd1.Property{"CPUShares", dbus.MakeVariant(uint64(c.CpuShares))})
|
systemd.Property{"CPUShares", dbus.MakeVariant(uint64(c.CpuShares))})
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := theConn.StartTransientUnit(unitName, "replace", properties...); err != nil {
|
if _, err := theConn.StartTransientUnit(unitName, "replace", properties...); err != nil {
|
||||||
|
@ -166,7 +166,7 @@ func (c *systemdCgroup) Paths() (map[string]string, error) {
|
||||||
subsystemPath, err := getSubsystemPath(c.cgroup, sysname)
|
subsystemPath, err := getSubsystemPath(c.cgroup, sysname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Don't fail if a cgroup hierarchy was not found, just skip this subsystem
|
// Don't fail if a cgroup hierarchy was not found, just skip this subsystem
|
||||||
if err == cgroups.ErrNotFound {
|
if cgroups.IsNotFound(err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ func GetStats(c *cgroups.Cgroup) (*cgroups.Stats, error) {
|
||||||
subsystemPath, err := getSubsystemPath(c, sysname)
|
subsystemPath, err := getSubsystemPath(c, sysname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Don't fail if a cgroup hierarchy was not found, just skip this subsystem
|
// Don't fail if a cgroup hierarchy was not found, just skip this subsystem
|
||||||
if err == cgroups.ErrNotFound {
|
if cgroups.IsNotFound(err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,8 @@ func FindCgroupMountpoint(subsystem string) (string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", ErrNotFound
|
|
||||||
|
return "", NewNotFoundError(subsystem)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mount struct {
|
type Mount struct {
|
||||||
|
@ -153,19 +154,23 @@ func ReadProcsFile(dir string) ([]int, error) {
|
||||||
|
|
||||||
func parseCgroupFile(subsystem string, r io.Reader) (string, error) {
|
func parseCgroupFile(subsystem string, r io.Reader) (string, error) {
|
||||||
s := bufio.NewScanner(r)
|
s := bufio.NewScanner(r)
|
||||||
|
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
if err := s.Err(); err != nil {
|
if err := s.Err(); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
text := s.Text()
|
text := s.Text()
|
||||||
parts := strings.Split(text, ":")
|
parts := strings.Split(text, ":")
|
||||||
|
|
||||||
for _, subs := range strings.Split(parts[1], ",") {
|
for _, subs := range strings.Split(parts[1], ",") {
|
||||||
if subs == subsystem {
|
if subs == subsystem {
|
||||||
return parts[2], nil
|
return parts[2], nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", ErrNotFound
|
|
||||||
|
return "", NewNotFoundError(subsystem)
|
||||||
}
|
}
|
||||||
|
|
||||||
func pathExists(path string) bool {
|
func pathExists(path string) bool {
|
||||||
|
|
Loading…
Reference in New Issue