Signed-off-by: Daniel Nephin <dnephin@docker.com>
| ... | ... |
@@ -23,9 +23,9 @@ import ( |
| 23 | 23 |
"github.com/docker/docker/pkg/ioutils" |
| 24 | 24 |
"github.com/docker/docker/pkg/progress" |
| 25 | 25 |
"github.com/docker/docker/pkg/streamformatter" |
| 26 |
- "github.com/docker/docker/pkg/ulimit" |
|
| 27 | 26 |
"github.com/docker/docker/reference" |
| 28 | 27 |
"github.com/docker/docker/utils" |
| 28 |
+ "github.com/docker/go-units" |
|
| 29 | 29 |
"golang.org/x/net/context" |
| 30 | 30 |
) |
| 31 | 31 |
|
| ... | ... |
@@ -151,7 +151,7 @@ func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r * |
| 151 | 151 |
buildConfig.Isolation = i |
| 152 | 152 |
} |
| 153 | 153 |
|
| 154 |
- var buildUlimits = []*ulimit.Ulimit{}
|
|
| 154 |
+ var buildUlimits = []*units.Ulimit{}
|
|
| 155 | 155 |
ulimitsJSON := r.FormValue("ulimits")
|
| 156 | 156 |
if ulimitsJSON != "" {
|
| 157 | 157 |
if err := json.NewDecoder(strings.NewReader(ulimitsJSON)).Decode(&buildUlimits); err != nil {
|
| ... | ... |
@@ -7,7 +7,7 @@ import ( |
| 7 | 7 |
|
| 8 | 8 |
"github.com/docker/docker/api/types/container" |
| 9 | 9 |
"github.com/docker/docker/api/types/filters" |
| 10 |
- "github.com/docker/docker/pkg/ulimit" |
|
| 10 |
+ "github.com/docker/go-units" |
|
| 11 | 11 |
) |
| 12 | 12 |
|
| 13 | 13 |
// ContainerAttachOptions holds parameters to attach to a container. |
| ... | ... |
@@ -137,7 +137,7 @@ type ImageBuildOptions struct {
|
| 137 | 137 |
CgroupParent string |
| 138 | 138 |
ShmSize string |
| 139 | 139 |
Dockerfile string |
| 140 |
- Ulimits []*ulimit.Ulimit |
|
| 140 |
+ Ulimits []*units.Ulimit |
|
| 141 | 141 |
BuildArgs []string |
| 142 | 142 |
AuthConfigs map[string]AuthConfig |
| 143 | 143 |
Context io.Reader |
| ... | ... |
@@ -5,8 +5,8 @@ import ( |
| 5 | 5 |
|
| 6 | 6 |
"github.com/docker/docker/api/types/blkiodev" |
| 7 | 7 |
"github.com/docker/docker/api/types/strslice" |
| 8 |
- "github.com/docker/docker/pkg/ulimit" |
|
| 9 | 8 |
"github.com/docker/go-connections/nat" |
| 9 |
+ "github.com/docker/go-units" |
|
| 10 | 10 |
) |
| 11 | 11 |
|
| 12 | 12 |
// NetworkMode represents the container network stack. |
| ... | ... |
@@ -170,18 +170,18 @@ type Resources struct {
|
| 170 | 170 |
BlkioDeviceWriteBps []*blkiodev.ThrottleDevice |
| 171 | 171 |
BlkioDeviceReadIOps []*blkiodev.ThrottleDevice |
| 172 | 172 |
BlkioDeviceWriteIOps []*blkiodev.ThrottleDevice |
| 173 |
- CPUPeriod int64 `json:"CpuPeriod"` // CPU CFS (Completely Fair Scheduler) period |
|
| 174 |
- CPUQuota int64 `json:"CpuQuota"` // CPU CFS (Completely Fair Scheduler) quota |
|
| 175 |
- CpusetCpus string // CpusetCpus 0-2, 0,1 |
|
| 176 |
- CpusetMems string // CpusetMems 0-2, 0,1 |
|
| 177 |
- Devices []DeviceMapping // List of devices to map inside the container |
|
| 178 |
- KernelMemory int64 // Kernel memory limit (in bytes) |
|
| 179 |
- Memory int64 // Memory limit (in bytes) |
|
| 180 |
- MemoryReservation int64 // Memory soft limit (in bytes) |
|
| 181 |
- MemorySwap int64 // Total memory usage (memory + swap); set `-1` to disable swap |
|
| 182 |
- MemorySwappiness *int64 // Tuning container memory swappiness behaviour |
|
| 183 |
- OomKillDisable bool // Whether to disable OOM Killer or not |
|
| 184 |
- Ulimits []*ulimit.Ulimit // List of ulimits to be set in the container |
|
| 173 |
+ CPUPeriod int64 `json:"CpuPeriod"` // CPU CFS (Completely Fair Scheduler) period |
|
| 174 |
+ CPUQuota int64 `json:"CpuQuota"` // CPU CFS (Completely Fair Scheduler) quota |
|
| 175 |
+ CpusetCpus string // CpusetCpus 0-2, 0,1 |
|
| 176 |
+ CpusetMems string // CpusetMems 0-2, 0,1 |
|
| 177 |
+ Devices []DeviceMapping // List of devices to map inside the container |
|
| 178 |
+ KernelMemory int64 // Kernel memory limit (in bytes) |
|
| 179 |
+ Memory int64 // Memory limit (in bytes) |
|
| 180 |
+ MemoryReservation int64 // Memory soft limit (in bytes) |
|
| 181 |
+ MemorySwap int64 // Total memory usage (memory + swap); set `-1` to disable swap |
|
| 182 |
+ MemorySwappiness *int64 // Tuning container memory swappiness behaviour |
|
| 183 |
+ OomKillDisable bool // Whether to disable OOM Killer or not |
|
| 184 |
+ Ulimits []*units.Ulimit // List of ulimits to be set in the container |
|
| 185 | 185 |
} |
| 186 | 186 |
|
| 187 | 187 |
// HostConfig the non-portable Config structure of a container. |
| ... | ... |
@@ -14,7 +14,7 @@ import ( |
| 14 | 14 |
"github.com/docker/docker/builder" |
| 15 | 15 |
"github.com/docker/docker/builder/dockerfile/parser" |
| 16 | 16 |
"github.com/docker/docker/pkg/stringid" |
| 17 |
- "github.com/docker/docker/pkg/ulimit" |
|
| 17 |
+ "github.com/docker/go-units" |
|
| 18 | 18 |
) |
| 19 | 19 |
|
| 20 | 20 |
var validCommitCommands = map[string]bool{
|
| ... | ... |
@@ -66,7 +66,7 @@ type Config struct {
|
| 66 | 66 |
CPUSetCpus string |
| 67 | 67 |
CPUSetMems string |
| 68 | 68 |
CgroupParent string |
| 69 |
- Ulimits []*ulimit.Ulimit |
|
| 69 |
+ Ulimits []*units.Ulimit |
|
| 70 | 70 |
} |
| 71 | 71 |
|
| 72 | 72 |
// Builder is a Dockerfile builder |
| ... | ... |
@@ -24,8 +24,8 @@ import ( |
| 24 | 24 |
"github.com/docker/docker/pkg/idtools" |
| 25 | 25 |
"github.com/docker/docker/pkg/mount" |
| 26 | 26 |
"github.com/docker/docker/pkg/stringid" |
| 27 |
- "github.com/docker/docker/pkg/ulimit" |
|
| 28 | 27 |
"github.com/docker/docker/runconfig" |
| 28 |
+ "github.com/docker/go-units" |
|
| 29 | 29 |
"github.com/docker/libnetwork" |
| 30 | 30 |
"github.com/docker/libnetwork/netlabel" |
| 31 | 31 |
"github.com/docker/libnetwork/options" |
| ... | ... |
@@ -146,11 +146,11 @@ func (daemon *Daemon) populateCommand(c *container.Container, env []string) erro |
| 146 | 146 |
|
| 147 | 147 |
autoCreatedDevices := mergeDevices(configs.DefaultAutoCreatedDevices, userSpecifiedDevices) |
| 148 | 148 |
|
| 149 |
- var rlimits []*ulimit.Rlimit |
|
| 149 |
+ var rlimits []*units.Rlimit |
|
| 150 | 150 |
ulimits := c.HostConfig.Ulimits |
| 151 | 151 |
|
| 152 | 152 |
// Merge ulimits with daemon defaults |
| 153 |
- ulIdx := make(map[string]*ulimit.Ulimit) |
|
| 153 |
+ ulIdx := make(map[string]*units.Ulimit) |
|
| 154 | 154 |
for _, ul := range ulimits {
|
| 155 | 155 |
ulIdx[ul.Name] = ul |
| 156 | 156 |
} |
| ... | ... |
@@ -14,7 +14,7 @@ import ( |
| 14 | 14 |
"github.com/docker/docker/daemon/execdriver/native/template" |
| 15 | 15 |
"github.com/docker/docker/pkg/idtools" |
| 16 | 16 |
"github.com/docker/docker/pkg/mount" |
| 17 |
- "github.com/docker/docker/pkg/ulimit" |
|
| 17 |
+ "github.com/docker/go-units" |
|
| 18 | 18 |
"github.com/opencontainers/runc/libcontainer" |
| 19 | 19 |
"github.com/opencontainers/runc/libcontainer/cgroups/fs" |
| 20 | 20 |
"github.com/opencontainers/runc/libcontainer/configs" |
| ... | ... |
@@ -48,7 +48,7 @@ type Resources struct {
|
| 48 | 48 |
CpusetCpus string `json:"cpuset_cpus"` |
| 49 | 49 |
CpusetMems string `json:"cpuset_mems"` |
| 50 | 50 |
CPUPeriod int64 `json:"cpu_period"` |
| 51 |
- Rlimits []*ulimit.Rlimit `json:"rlimits"` |
|
| 51 |
+ Rlimits []*units.Rlimit `json:"rlimits"` |
|
| 52 | 52 |
OomKillDisable bool `json:"oom_kill_disable"` |
| 53 | 53 |
MemorySwappiness int64 `json:"memory_swappiness"` |
| 54 | 54 |
} |
| ... | ... |
@@ -7,7 +7,7 @@ import ( |
| 7 | 7 |
"strings" |
| 8 | 8 |
|
| 9 | 9 |
"github.com/docker/docker/pkg/integration/checker" |
| 10 |
- "github.com/docker/docker/pkg/ulimit" |
|
| 10 |
+ "github.com/docker/go-units" |
|
| 11 | 11 |
"github.com/go-check/check" |
| 12 | 12 |
) |
| 13 | 13 |
|
| ... | ... |
@@ -33,7 +33,7 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
|
| 33 | 33 |
CpusetMems string |
| 34 | 34 |
CPUShares int64 |
| 35 | 35 |
CPUQuota int64 |
| 36 |
- Ulimits []*ulimit.Ulimit |
|
| 36 |
+ Ulimits []*units.Ulimit |
|
| 37 | 37 |
} |
| 38 | 38 |
|
| 39 | 39 |
cfg, err := inspectFieldJSON(cID, "HostConfig") |
| 40 | 40 |
deleted file mode 100644 |
| ... | ... |
@@ -1,111 +0,0 @@ |
| 1 |
-// Package ulimit provides structure and helper function to parse and represent |
|
| 2 |
-// resource limits (Rlimit and Ulimit, its human friendly version). |
|
| 3 |
-package ulimit |
|
| 4 |
- |
|
| 5 |
-import ( |
|
| 6 |
- "fmt" |
|
| 7 |
- "strconv" |
|
| 8 |
- "strings" |
|
| 9 |
-) |
|
| 10 |
- |
|
| 11 |
-// Ulimit is a human friendly version of Rlimit. |
|
| 12 |
-type Ulimit struct {
|
|
| 13 |
- Name string |
|
| 14 |
- Hard int64 |
|
| 15 |
- Soft int64 |
|
| 16 |
-} |
|
| 17 |
- |
|
| 18 |
-// Rlimit specifies the resource limits, such as max open files. |
|
| 19 |
-type Rlimit struct {
|
|
| 20 |
- Type int `json:"type,omitempty"` |
|
| 21 |
- Hard uint64 `json:"hard,omitempty"` |
|
| 22 |
- Soft uint64 `json:"soft,omitempty"` |
|
| 23 |
-} |
|
| 24 |
- |
|
| 25 |
-const ( |
|
| 26 |
- // magic numbers for making the syscall |
|
| 27 |
- // some of these are defined in the syscall package, but not all. |
|
| 28 |
- // Also since Windows client doesn't get access to the syscall package, need to |
|
| 29 |
- // define these here |
|
| 30 |
- rlimitAs = 9 |
|
| 31 |
- rlimitCore = 4 |
|
| 32 |
- rlimitCPU = 0 |
|
| 33 |
- rlimitData = 2 |
|
| 34 |
- rlimitFsize = 1 |
|
| 35 |
- rlimitLocks = 10 |
|
| 36 |
- rlimitMemlock = 8 |
|
| 37 |
- rlimitMsgqueue = 12 |
|
| 38 |
- rlimitNice = 13 |
|
| 39 |
- rlimitNofile = 7 |
|
| 40 |
- rlimitNproc = 6 |
|
| 41 |
- rlimitRss = 5 |
|
| 42 |
- rlimitRtprio = 14 |
|
| 43 |
- rlimitRttime = 15 |
|
| 44 |
- rlimitSigpending = 11 |
|
| 45 |
- rlimitStack = 3 |
|
| 46 |
-) |
|
| 47 |
- |
|
| 48 |
-var ulimitNameMapping = map[string]int{
|
|
| 49 |
- //"as": rlimitAs, // Disabled since this doesn't seem usable with the way Docker inits a container. |
|
| 50 |
- "core": rlimitCore, |
|
| 51 |
- "cpu": rlimitCPU, |
|
| 52 |
- "data": rlimitData, |
|
| 53 |
- "fsize": rlimitFsize, |
|
| 54 |
- "locks": rlimitLocks, |
|
| 55 |
- "memlock": rlimitMemlock, |
|
| 56 |
- "msgqueue": rlimitMsgqueue, |
|
| 57 |
- "nice": rlimitNice, |
|
| 58 |
- "nofile": rlimitNofile, |
|
| 59 |
- "nproc": rlimitNproc, |
|
| 60 |
- "rss": rlimitRss, |
|
| 61 |
- "rtprio": rlimitRtprio, |
|
| 62 |
- "rttime": rlimitRttime, |
|
| 63 |
- "sigpending": rlimitSigpending, |
|
| 64 |
- "stack": rlimitStack, |
|
| 65 |
-} |
|
| 66 |
- |
|
| 67 |
-// Parse parses and returns a Ulimit from the specified string. |
|
| 68 |
-func Parse(val string) (*Ulimit, error) {
|
|
| 69 |
- parts := strings.SplitN(val, "=", 2) |
|
| 70 |
- if len(parts) != 2 {
|
|
| 71 |
- return nil, fmt.Errorf("invalid ulimit argument: %s", val)
|
|
| 72 |
- } |
|
| 73 |
- |
|
| 74 |
- if _, exists := ulimitNameMapping[parts[0]]; !exists {
|
|
| 75 |
- return nil, fmt.Errorf("invalid ulimit type: %s", parts[0])
|
|
| 76 |
- } |
|
| 77 |
- |
|
| 78 |
- limitVals := strings.SplitN(parts[1], ":", 2) |
|
| 79 |
- if len(limitVals) > 2 {
|
|
| 80 |
- return nil, fmt.Errorf("too many limit value arguments - %s, can only have up to two, `soft[:hard]`", parts[1])
|
|
| 81 |
- } |
|
| 82 |
- |
|
| 83 |
- soft, err := strconv.ParseInt(limitVals[0], 10, 64) |
|
| 84 |
- if err != nil {
|
|
| 85 |
- return nil, err |
|
| 86 |
- } |
|
| 87 |
- |
|
| 88 |
- hard := soft // in case no hard was set |
|
| 89 |
- if len(limitVals) == 2 {
|
|
| 90 |
- hard, err = strconv.ParseInt(limitVals[1], 10, 64) |
|
| 91 |
- } |
|
| 92 |
- if soft > hard {
|
|
| 93 |
- return nil, fmt.Errorf("ulimit soft limit must be less than or equal to hard limit: %d > %d", soft, hard)
|
|
| 94 |
- } |
|
| 95 |
- |
|
| 96 |
- return &Ulimit{Name: parts[0], Soft: soft, Hard: hard}, nil
|
|
| 97 |
-} |
|
| 98 |
- |
|
| 99 |
-// GetRlimit returns the RLimit corresponding to Ulimit. |
|
| 100 |
-func (u *Ulimit) GetRlimit() (*Rlimit, error) {
|
|
| 101 |
- t, exists := ulimitNameMapping[u.Name] |
|
| 102 |
- if !exists {
|
|
| 103 |
- return nil, fmt.Errorf("invalid ulimit name %s", u.Name)
|
|
| 104 |
- } |
|
| 105 |
- |
|
| 106 |
- return &Rlimit{Type: t, Soft: uint64(u.Soft), Hard: uint64(u.Hard)}, nil
|
|
| 107 |
-} |
|
| 108 |
- |
|
| 109 |
-func (u *Ulimit) String() string {
|
|
| 110 |
- return fmt.Sprintf("%s=%d:%d", u.Name, u.Soft, u.Hard)
|
|
| 111 |
-} |
| 112 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,55 +0,0 @@ |
| 1 |
-package ulimit |
|
| 2 |
- |
|
| 3 |
-import "testing" |
|
| 4 |
- |
|
| 5 |
-func TestParseValid(t *testing.T) {
|
|
| 6 |
- u1 := &Ulimit{"nofile", 1024, 512}
|
|
| 7 |
- if u2, _ := Parse("nofile=512:1024"); *u1 != *u2 {
|
|
| 8 |
- t.Fatalf("expected %q, but got %q", u1, u2)
|
|
| 9 |
- } |
|
| 10 |
-} |
|
| 11 |
- |
|
| 12 |
-func TestParseInvalidLimitType(t *testing.T) {
|
|
| 13 |
- if _, err := Parse("notarealtype=1024:1024"); err == nil {
|
|
| 14 |
- t.Fatalf("expected error on invalid ulimit type")
|
|
| 15 |
- } |
|
| 16 |
-} |
|
| 17 |
- |
|
| 18 |
-func TestParseBadFormat(t *testing.T) {
|
|
| 19 |
- if _, err := Parse("nofile:1024:1024"); err == nil {
|
|
| 20 |
- t.Fatal("expected error on bad syntax")
|
|
| 21 |
- } |
|
| 22 |
- |
|
| 23 |
- if _, err := Parse("nofile"); err == nil {
|
|
| 24 |
- t.Fatal("expected error on bad syntax")
|
|
| 25 |
- } |
|
| 26 |
- |
|
| 27 |
- if _, err := Parse("nofile="); err == nil {
|
|
| 28 |
- t.Fatal("expected error on bad syntax")
|
|
| 29 |
- } |
|
| 30 |
- if _, err := Parse("nofile=:"); err == nil {
|
|
| 31 |
- t.Fatal("expected error on bad syntax")
|
|
| 32 |
- } |
|
| 33 |
- if _, err := Parse("nofile=:1024"); err == nil {
|
|
| 34 |
- t.Fatal("expected error on bad syntax")
|
|
| 35 |
- } |
|
| 36 |
-} |
|
| 37 |
- |
|
| 38 |
-func TestParseHardLessThanSoft(t *testing.T) {
|
|
| 39 |
- if _, err := Parse("nofile:1024:1"); err == nil {
|
|
| 40 |
- t.Fatal("expected error on hard limit less than soft limit")
|
|
| 41 |
- } |
|
| 42 |
-} |
|
| 43 |
- |
|
| 44 |
-func TestParseInvalidValueType(t *testing.T) {
|
|
| 45 |
- if _, err := Parse("nofile:asdf"); err == nil {
|
|
| 46 |
- t.Fatal("expected error on bad value type")
|
|
| 47 |
- } |
|
| 48 |
-} |
|
| 49 |
- |
|
| 50 |
-func TestStringOutput(t *testing.T) {
|
|
| 51 |
- u := &Ulimit{"nofile", 1024, 512}
|
|
| 52 |
- if s := u.String(); s != "nofile=512:1024" {
|
|
| 53 |
- t.Fatal("expected String to return nofile=512:1024, but got", s)
|
|
| 54 |
- } |
|
| 55 |
-} |