Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6d022bd

Browse files
committed
Updates libcontainer to v2.2.1
Signed-off-by: Mrunal Patel <[email protected]>
1 parent 3f11e05 commit 6d022bd

45 files changed

Lines changed: 943 additions & 91 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

daemon/stats_linux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ func convertStatsToAPITypes(ls *libcontainer.Stats) *types.Stats {
5252
}
5353
mem := cs.MemoryStats
5454
s.MemoryStats = types.MemoryStats{
55-
Usage: mem.Usage,
56-
MaxUsage: mem.MaxUsage,
55+
Usage: mem.Usage.Usage,
56+
MaxUsage: mem.Usage.MaxUsage,
5757
Stats: mem.Stats,
58-
Failcnt: mem.Failcnt,
58+
Failcnt: mem.Usage.Failcnt,
5959
}
6060
}
6161

hack/vendor.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ clone git github.com/hashicorp/consul v0.5.2
2929
# get distribution packages
3030
clone git github.com/docker/distribution b9eeb328080d367dbde850ec6e94f1e4ac2b5efe
3131

32-
clone git github.com/docker/libcontainer v2.1.1
32+
clone git github.com/docker/libcontainer v2.2.1
3333
# libcontainer deps (see src/github.com/docker/libcontainer/update-vendor.sh)
3434
clone git github.com/coreos/go-systemd v2
3535
clone git github.com/godbus/dbus v2

vendor/src/github.com/Sirupsen/logrus/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
324324
325325
#### Logger as an `io.Writer`
326326
327-
Logrus can be transformed into an `io.Writer`. That writer is the end of an `io.Pipe` and it is your responsibility to close it.
327+
Logrus can be transormed into an `io.Writer`. That writer is the end of an `io.Pipe` and it is your responsibility to close it.
328328
329329
```go
330330
w := logger.Writer()

vendor/src/github.com/docker/libcontainer/CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ The following packages are required to compile libcontainer natively.
2424
- git
2525
- cgutils
2626

27-
You can develop on OS X, but you are limited to Dockerfile-based builds only.
27+
You can develop on OSX, but you are limited to Dockerfile-based builds only.
2828

2929
### Building libcontainer from Dockerfile
3030

3131
make all
3232

3333
This is the easiest way of building libcontainer.
34-
As this build is done using Docker, you can even run this from [OS X](https://github.com/boot2docker/boot2docker)
34+
As this build is done using Docker, you can even run this from [OSX](https://github.com/boot2docker/boot2docker)
3535

3636
### Testing changes with "nsinit"
3737

3838
make sh
3939

4040
This will create an container that runs `nsinit exec sh` on a busybox rootfs with the configuration from ['minimal.json'](https://github.com/docker/libcontainer/blob/master/sample_configs/minimal.json).
41-
Like the previous command, you can run this on OS X too!
41+
Like the previous command, you can run this on OSX too!
4242

4343
### Building libcontainer directly
4444

vendor/src/github.com/docker/libcontainer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## libcontainer - reference implementation for containers [![Build Status](https://jenkins.dockerproject.com/buildStatus/icon?job=Libcontainer Master)](https://jenkins.dockerproject.com/job/Libcontainer%20Master/)
1+
## libcontainer - reference implementation for containers [![Build Status](https://jenkins.dockerproject.org/buildStatus/icon?job=Libcontainer%20Master)](https://jenkins.dockerproject.org/job/Libcontainer%20Master/)
22

33
Libcontainer provides a native Go implementation for creating containers
44
with namespaces, cgroups, capabilities, and filesystem access controls.

vendor/src/github.com/docker/libcontainer/ROADMAP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This document is a high-level overview of where we want to take libcontainer next.
44
It is a curated selection of planned improvements which are either important, difficult, or both.
55

6-
For a more complete view of planned and requested improvements, see [the GitHub issues](https://github.com/docker/libcontainer/issues).
6+
For a more complete view of planned and requested improvements, see [the Github issues](https://github.com/docker/libcontainer/issues).
77

88
To suggest changes to the roadmap, including additions, please write the change as if it were already in effect, and make a pull request.
99

vendor/src/github.com/docker/libcontainer/SPEC.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ unmount all the mounts that were setup within that namespace.
4747
For a container to execute properly there are certain filesystems that
4848
are required to be mounted within the rootfs that the runtime will setup.
4949

50-
| Path | Type | Flags | Data |
51-
| ----------- | ------ | -------------------------------------- | --------------------------------------- |
52-
| /proc | proc | MS_NOEXEC,MS_NOSUID,MS_NODEV | |
53-
| /dev | tmpfs | MS_NOEXEC,MS_STRICTATIME | mode=755 |
54-
| /dev/shm | shm | MS_NOEXEC,MS_NOSUID,MS_NODEV | mode=1777,size=65536k |
55-
| /dev/mqueue | mqueue | MS_NOEXEC,MS_NOSUID,MS_NODEV | |
56-
| /dev/pts | devpts | MS_NOEXEC,MS_NOSUID | newinstance,ptmxmode=0666,mode=620,gid5 |
57-
| /sys | sysfs | MS_NOEXEC,MS_NOSUID,MS_NODEV,MS_RDONLY | |
50+
| Path | Type | Flags | Data |
51+
| ----------- | ------ | -------------------------------------- | ---------------------------------------- |
52+
| /proc | proc | MS_NOEXEC,MS_NOSUID,MS_NODEV | |
53+
| /dev | tmpfs | MS_NOEXEC,MS_STRICTATIME | mode=755 |
54+
| /dev/shm | tmpfs | MS_NOEXEC,MS_NOSUID,MS_NODEV | mode=1777,size=65536k |
55+
| /dev/mqueue | mqueue | MS_NOEXEC,MS_NOSUID,MS_NODEV | |
56+
| /dev/pts | devpts | MS_NOEXEC,MS_NOSUID | newinstance,ptmxmode=0666,mode=620,gid=5 |
57+
| /sys | sysfs | MS_NOEXEC,MS_NOSUID,MS_NODEV,MS_RDONLY | |
5858

5959

6060
After a container's filesystems are mounted within the newly created
6161
mount namespace `/dev` will need to be populated with a set of device nodes.
6262
It is expected that a rootfs does not need to have any device nodes specified
63-
for `/dev` within the rootfs as the container will setup the correct devices
63+
for `/dev` witin the rootfs as the container will setup the correct devices
6464
that are required for executing a container's process.
6565

6666
| Path | Mode | Access |

vendor/src/github.com/docker/libcontainer/cgroups/fs/apply_raw.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var (
3030
"freezer": &FreezerGroup{},
3131
}
3232
CgroupProcesses = "cgroup.procs"
33+
HugePageSizes, _ = cgroups.GetHugePageSize()
3334
)
3435

3536
type subsystem interface {
@@ -44,6 +45,7 @@ type subsystem interface {
4445
}
4546

4647
type Manager struct {
48+
mu sync.Mutex
4749
Cgroups *configs.Cgroup
4850
Paths map[string]string
4951
}
@@ -82,7 +84,6 @@ type data struct {
8284
}
8385

8486
func (m *Manager) Apply(pid int) error {
85-
8687
if m.Cgroups == nil {
8788
return nil
8889
}
@@ -128,14 +129,25 @@ func (m *Manager) Apply(pid int) error {
128129
}
129130

130131
func (m *Manager) Destroy() error {
131-
return cgroups.RemovePaths(m.Paths)
132+
m.mu.Lock()
133+
defer m.mu.Unlock()
134+
if err := cgroups.RemovePaths(m.Paths); err != nil {
135+
return err
136+
}
137+
m.Paths = make(map[string]string)
138+
return nil
132139
}
133140

134141
func (m *Manager) GetPaths() map[string]string {
135-
return m.Paths
142+
m.mu.Lock()
143+
paths := m.Paths
144+
m.mu.Unlock()
145+
return paths
136146
}
137147

138148
func (m *Manager) GetStats() (*cgroups.Stats, error) {
149+
m.mu.Lock()
150+
defer m.mu.Unlock()
139151
stats := cgroups.NewStats()
140152
for name, path := range m.Paths {
141153
sys, ok := subsystems[name]

vendor/src/github.com/docker/libcontainer/cgroups/fs/hugetlb.go

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
package fs
44

55
import (
6+
"fmt"
7+
"strconv"
8+
"strings"
9+
610
"github.com/docker/libcontainer/cgroups"
711
"github.com/docker/libcontainer/configs"
812
)
@@ -11,14 +15,25 @@ type HugetlbGroup struct {
1115
}
1216

1317
func (s *HugetlbGroup) Apply(d *data) error {
14-
// we just want to join this group even though we don't set anything
15-
if _, err := d.join("hugetlb"); err != nil && !cgroups.IsNotFound(err) {
18+
dir, err := d.join("hugetlb")
19+
if err != nil && !cgroups.IsNotFound(err) {
20+
return err
21+
}
22+
23+
if err := s.Set(dir, d.c); err != nil {
1624
return err
1725
}
26+
1827
return nil
1928
}
2029

2130
func (s *HugetlbGroup) Set(path string, cgroup *configs.Cgroup) error {
31+
for _, hugetlb := range cgroup.HugetlbLimit {
32+
if err := writeFile(path, strings.Join([]string{"hugetlb", hugetlb.Pagesize, "limit_in_bytes"}, "."), strconv.Itoa(hugetlb.Limit)); err != nil {
33+
return err
34+
}
35+
}
36+
2237
return nil
2338
}
2439

@@ -27,5 +42,31 @@ func (s *HugetlbGroup) Remove(d *data) error {
2742
}
2843

2944
func (s *HugetlbGroup) GetStats(path string, stats *cgroups.Stats) error {
45+
hugetlbStats := cgroups.HugetlbStats{}
46+
for _, pageSize := range HugePageSizes {
47+
usage := strings.Join([]string{"hugetlb", pageSize, "usage_in_bytes"}, ".")
48+
value, err := getCgroupParamUint(path, usage)
49+
if err != nil {
50+
return fmt.Errorf("failed to parse %s - %v", usage, err)
51+
}
52+
hugetlbStats.Usage = value
53+
54+
maxUsage := strings.Join([]string{"hugetlb", pageSize, "max_usage_in_bytes"}, ".")
55+
value, err = getCgroupParamUint(path, maxUsage)
56+
if err != nil {
57+
return fmt.Errorf("failed to parse %s - %v", maxUsage, err)
58+
}
59+
hugetlbStats.MaxUsage = value
60+
61+
failcnt := strings.Join([]string{"hugetlb", pageSize, "failcnt"}, ".")
62+
value, err = getCgroupParamUint(path, failcnt)
63+
if err != nil {
64+
return fmt.Errorf("failed to parse %s - %v", failcnt, err)
65+
}
66+
hugetlbStats.Failcnt = value
67+
68+
stats.HugetlbStats[pageSize] = hugetlbStats
69+
}
70+
3071
return nil
3172
}

vendor/src/github.com/docker/libcontainer/cgroups/fs/memory.go

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"path/filepath"
1010
"strconv"
11+
"strings"
1112

1213
"github.com/docker/libcontainer/cgroups"
1314
"github.com/docker/libcontainer/configs"
@@ -45,12 +46,6 @@ func (s *MemoryGroup) Set(path string, cgroup *configs.Cgroup) error {
4546
return err
4647
}
4748
}
48-
// By default, MemorySwap is set to twice the size of Memory.
49-
if cgroup.MemorySwap == 0 && cgroup.Memory != 0 {
50-
if err := writeFile(path, "memory.memsw.limit_in_bytes", strconv.FormatInt(cgroup.Memory*2, 10)); err != nil {
51-
return err
52-
}
53-
}
5449
if cgroup.MemorySwap > 0 {
5550
if err := writeFile(path, "memory.memsw.limit_in_bytes", strconv.FormatInt(cgroup.MemorySwap, 10)); err != nil {
5651
return err
@@ -67,6 +62,11 @@ func (s *MemoryGroup) Set(path string, cgroup *configs.Cgroup) error {
6762
return err
6863
}
6964
}
65+
if cgroup.MemorySwappiness >= 0 && cgroup.MemorySwappiness <= 100 {
66+
if err := writeFile(path, "memory.swappiness", strconv.FormatInt(cgroup.MemorySwappiness, 10)); err != nil {
67+
return err
68+
}
69+
}
7070

7171
return nil
7272
}
@@ -94,24 +94,62 @@ func (s *MemoryGroup) GetStats(path string, stats *cgroups.Stats) error {
9494
}
9595
stats.MemoryStats.Stats[t] = v
9696
}
97+
stats.MemoryStats.Cache = stats.MemoryStats.Stats["cache"]
9798

98-
// Set memory usage and max historical usage.
99-
value, err := getCgroupParamUint(path, "memory.usage_in_bytes")
99+
memoryUsage, err := getMemoryData(path, "")
100100
if err != nil {
101-
return fmt.Errorf("failed to parse memory.usage_in_bytes - %v", err)
101+
return err
102102
}
103-
stats.MemoryStats.Usage = value
104-
stats.MemoryStats.Cache = stats.MemoryStats.Stats["cache"]
105-
value, err = getCgroupParamUint(path, "memory.max_usage_in_bytes")
103+
stats.MemoryStats.Usage = memoryUsage
104+
swapUsage, err := getMemoryData(path, "memsw")
106105
if err != nil {
107-
return fmt.Errorf("failed to parse memory.max_usage_in_bytes - %v", err)
106+
return err
108107
}
109-
stats.MemoryStats.MaxUsage = value
110-
value, err = getCgroupParamUint(path, "memory.failcnt")
108+
stats.MemoryStats.SwapUsage = swapUsage
109+
kernelUsage, err := getMemoryData(path, "kmem")
111110
if err != nil {
112-
return fmt.Errorf("failed to parse memory.failcnt - %v", err)
111+
return err
113112
}
114-
stats.MemoryStats.Failcnt = value
113+
stats.MemoryStats.KernelUsage = kernelUsage
115114

116115
return nil
117116
}
117+
118+
func getMemoryData(path, name string) (cgroups.MemoryData, error) {
119+
memoryData := cgroups.MemoryData{}
120+
121+
moduleName := "memory"
122+
if name != "" {
123+
moduleName = strings.Join([]string{"memory", name}, ".")
124+
}
125+
usage := strings.Join([]string{moduleName, "usage_in_bytes"}, ".")
126+
maxUsage := strings.Join([]string{moduleName, "max_usage_in_bytes"}, ".")
127+
failcnt := strings.Join([]string{moduleName, "failcnt"}, ".")
128+
129+
value, err := getCgroupParamUint(path, usage)
130+
if err != nil {
131+
if moduleName != "memory" && os.IsNotExist(err) {
132+
return cgroups.MemoryData{}, nil
133+
}
134+
return cgroups.MemoryData{}, fmt.Errorf("failed to parse %s - %v", usage, err)
135+
}
136+
memoryData.Usage = value
137+
value, err = getCgroupParamUint(path, maxUsage)
138+
if err != nil {
139+
if moduleName != "memory" && os.IsNotExist(err) {
140+
return cgroups.MemoryData{}, nil
141+
}
142+
return cgroups.MemoryData{}, fmt.Errorf("failed to parse %s - %v", maxUsage, err)
143+
}
144+
memoryData.MaxUsage = value
145+
value, err = getCgroupParamUint(path, failcnt)
146+
if err != nil {
147+
if moduleName != "memory" && os.IsNotExist(err) {
148+
return cgroups.MemoryData{}, nil
149+
}
150+
return cgroups.MemoryData{}, fmt.Errorf("failed to parse %s - %v", failcnt, err)
151+
}
152+
memoryData.Failcnt = value
153+
154+
return memoryData, nil
155+
}

0 commit comments

Comments
 (0)