Don't expose cgroups via the execdriver API.

Use Resources to represent container limits rather than a cgroup specific field.

Docker-DCO-1.1-Signed-off-by: Paul Nasrat <pnasrat@gmail.com> (github: pnasrat)
This commit is contained in:
Paul Nasrat 2014-01-20 16:23:02 -05:00
parent fbd374f30b
commit 71c1646ba3
5 changed files with 31 additions and 34 deletions

View File

@ -7,7 +7,6 @@ import (
"github.com/dotcloud/docker/archive" "github.com/dotcloud/docker/archive"
"github.com/dotcloud/docker/execdriver" "github.com/dotcloud/docker/execdriver"
"github.com/dotcloud/docker/graphdriver" "github.com/dotcloud/docker/graphdriver"
"github.com/dotcloud/docker/pkg/cgroups"
"github.com/dotcloud/docker/pkg/mount" "github.com/dotcloud/docker/pkg/mount"
"github.com/dotcloud/docker/pkg/term" "github.com/dotcloud/docker/pkg/term"
"github.com/dotcloud/docker/utils" "github.com/dotcloud/docker/utils"
@ -671,7 +670,7 @@ func (container *Container) Start() (err error) {
driverConfig = append(driverConfig, fmt.Sprintf("%s = %s", pair.Key, pair.Value)) driverConfig = append(driverConfig, fmt.Sprintf("%s = %s", pair.Key, pair.Value))
} }
} }
cgroupValues := &cgroups.Values{ resources := &execdriver.Resources{
Memory: container.Config.Memory, Memory: container.Config.Memory,
MemorySwap: container.Config.MemorySwap, MemorySwap: container.Config.MemorySwap,
CpuShares: container.Config.CpuShares, CpuShares: container.Config.CpuShares,
@ -689,7 +688,7 @@ func (container *Container) Start() (err error) {
Tty: container.Config.Tty, Tty: container.Config.Tty,
User: container.Config.User, User: container.Config.User,
Config: driverConfig, Config: driverConfig,
Cgroups: cgroupValues, Resources: resources,
} }
container.process.SysProcAttr = &syscall.SysProcAttr{Setsid: true} container.process.SysProcAttr = &syscall.SysProcAttr{Setsid: true}

View File

@ -2,7 +2,6 @@ package execdriver
import ( import (
"errors" "errors"
"github.com/dotcloud/docker/pkg/cgroups"
"os/exec" "os/exec"
"syscall" "syscall"
) )
@ -76,24 +75,30 @@ type Network struct {
Mtu int `json:"mtu"` Mtu int `json:"mtu"`
} }
type Resources struct {
Memory int64 `json:"memory"`
MemorySwap int64 `json:"memory_swap"`
CpuShares int64 `json:"cpu_shares"`
}
// Process wrapps an os/exec.Cmd to add more metadata // Process wrapps an os/exec.Cmd to add more metadata
// TODO: Rename to Command // TODO: Rename to Command
type Process struct { type Process struct {
exec.Cmd exec.Cmd
ID string `json:"id"` ID string `json:"id"`
Privileged bool `json:"privileged"` Privileged bool `json:"privileged"`
User string `json:"user"` User string `json:"user"`
Rootfs string `json:"rootfs"` // root fs of the container Rootfs string `json:"rootfs"` // root fs of the container
InitPath string `json:"initpath"` // dockerinit InitPath string `json:"initpath"` // dockerinit
Entrypoint string `json:"entrypoint"` Entrypoint string `json:"entrypoint"`
Arguments []string `json:"arguments"` Arguments []string `json:"arguments"`
WorkingDir string `json:"working_dir"` WorkingDir string `json:"working_dir"`
ConfigPath string `json:"config_path"` // this should be able to be removed when the lxc template is moved into the driver ConfigPath string `json:"config_path"` // this should be able to be removed when the lxc template is moved into the driver
Tty bool `json:"tty"` Tty bool `json:"tty"`
Network *Network `json:"network"` // if network is nil then networking is disabled Network *Network `json:"network"` // if network is nil then networking is disabled
Config []string `json:"config"` // generic values that specific drivers can consume Config []string `json:"config"` // generic values that specific drivers can consume
Cgroups *cgroups.Values `json:"cgroups"` Resources *Resources `json:"resources"`
} }
// Return the pid of the process // Return the pid of the process

View File

@ -1,7 +1,7 @@
package lxc package lxc
import ( import (
"github.com/dotcloud/docker/pkg/cgroups" "github.com/dotcloud/docker/execdriver"
"strings" "strings"
"text/template" "text/template"
) )
@ -91,16 +91,16 @@ lxc.aa_profile = unconfined
{{end}} {{end}}
# limits # limits
{{if .Cgroups}} {{if .Resources}}
{{if .Cgroups.Memory}} {{if .Resources.Memory}}
lxc.cgroup.memory.limit_in_bytes = {{.Cgroups.Memory}} lxc.cgroup.memory.limit_in_bytes = {{.Resources.Memory}}
lxc.cgroup.memory.soft_limit_in_bytes = {{.Cgroups.Memory}} lxc.cgroup.memory.soft_limit_in_bytes = {{.Resources.Memory}}
{{with $memSwap := getMemorySwap .Cgroups}} {{with $memSwap := getMemorySwap .Resources}}
lxc.cgroup.memory.memsw.limit_in_bytes = {{$memSwap}} lxc.cgroup.memory.memsw.limit_in_bytes = {{$memSwap}}
{{end}} {{end}}
{{end}} {{end}}
{{if .Cgroups.CpuShares}} {{if .Resources.CpuShares}}
lxc.cgroup.cpu.shares = {{.Cgroups.CpuShares}} lxc.cgroup.cpu.shares = {{.Resources.CpuShares}}
{{end}} {{end}}
{{end}} {{end}}
@ -119,7 +119,7 @@ func escapeFstabSpaces(field string) string {
return strings.Replace(field, " ", "\\040", -1) return strings.Replace(field, " ", "\\040", -1)
} }
func getMemorySwap(v *cgroups.Values) int64 { func getMemorySwap(v *execdriver.Resources) int64 {
// By default, MemorySwap is set to twice the size of RAM. // By default, MemorySwap is set to twice the size of RAM.
// If you want to omit MemorySwap, set it to `-1'. // If you want to omit MemorySwap, set it to `-1'.
if v.MemorySwap < 0 { if v.MemorySwap < 0 {

View File

@ -4,7 +4,6 @@ import (
"bufio" "bufio"
"fmt" "fmt"
"github.com/dotcloud/docker/execdriver" "github.com/dotcloud/docker/execdriver"
"github.com/dotcloud/docker/pkg/cgroups"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"os" "os"
@ -40,7 +39,7 @@ func TestLXCConfig(t *testing.T) {
} }
process := &execdriver.Process{ process := &execdriver.Process{
ID: "1", ID: "1",
Cgroups: &cgroups.Values{ Resources: &execdriver.Resources{
Memory: int64(mem), Memory: int64(mem),
CpuShares: int64(cpu), CpuShares: int64(cpu),
}, },

View File

@ -12,12 +12,6 @@ import (
"strings" "strings"
) )
type Values struct {
Memory int64 `json:"memory"`
MemorySwap int64 `json:"memory_swap"`
CpuShares int64 `json:"cpu_shares"`
}
// https://www.kernel.org/doc/Documentation/cgroups/cgroups.txt // https://www.kernel.org/doc/Documentation/cgroups/cgroups.txt
func FindCgroupMountpoint(subsystem string) (string, error) { func FindCgroupMountpoint(subsystem string) (string, error) {
mounts, err := mount.GetMounts() mounts, err := mount.GetMounts()