Merge pull request #7027 from AkihiroSuda/containerd-cgroup-1.0.4
go.mod: github.com/containerd/cgroups v1.0.4
This commit is contained in:
commit
0532f666f6
2
go.mod
2
go.mod
@ -9,7 +9,7 @@ require (
|
|||||||
github.com/container-orchestrated-devices/container-device-interface v0.3.1
|
github.com/container-orchestrated-devices/container-device-interface v0.3.1
|
||||||
github.com/containerd/aufs v1.0.0
|
github.com/containerd/aufs v1.0.0
|
||||||
github.com/containerd/btrfs v1.0.0
|
github.com/containerd/btrfs v1.0.0
|
||||||
github.com/containerd/cgroups v1.0.3
|
github.com/containerd/cgroups v1.0.4
|
||||||
github.com/containerd/console v1.0.3
|
github.com/containerd/console v1.0.3
|
||||||
github.com/containerd/continuity v0.3.0
|
github.com/containerd/continuity v0.3.0
|
||||||
github.com/containerd/fifo v1.0.0
|
github.com/containerd/fifo v1.0.0
|
||||||
|
3
go.sum
3
go.sum
@ -191,8 +191,9 @@ github.com/containerd/cgroups v0.0.0-20200710171044-318312a37340/go.mod h1:s5q4S
|
|||||||
github.com/containerd/cgroups v0.0.0-20200824123100-0b889c03f102/go.mod h1:s5q4SojHctfxANBDvMeIaIovkq29IP48TKAxnhYRxvo=
|
github.com/containerd/cgroups v0.0.0-20200824123100-0b889c03f102/go.mod h1:s5q4SojHctfxANBDvMeIaIovkq29IP48TKAxnhYRxvo=
|
||||||
github.com/containerd/cgroups v0.0.0-20210114181951-8a68de567b68/go.mod h1:ZJeTFisyysqgcCdecO57Dj79RfL0LNeGiFUqLYQRYLE=
|
github.com/containerd/cgroups v0.0.0-20210114181951-8a68de567b68/go.mod h1:ZJeTFisyysqgcCdecO57Dj79RfL0LNeGiFUqLYQRYLE=
|
||||||
github.com/containerd/cgroups v1.0.1/go.mod h1:0SJrPIenamHDcZhEcJMNBB85rHcUsw4f25ZfBiPYRkU=
|
github.com/containerd/cgroups v1.0.1/go.mod h1:0SJrPIenamHDcZhEcJMNBB85rHcUsw4f25ZfBiPYRkU=
|
||||||
github.com/containerd/cgroups v1.0.3 h1:ADZftAkglvCiD44c77s5YmMqaP2pzVCFZvBmAlBdAP4=
|
|
||||||
github.com/containerd/cgroups v1.0.3/go.mod h1:/ofk34relqNjSGyqPrmEULrO4Sc8LJhvJmWbUCUKqj8=
|
github.com/containerd/cgroups v1.0.3/go.mod h1:/ofk34relqNjSGyqPrmEULrO4Sc8LJhvJmWbUCUKqj8=
|
||||||
|
github.com/containerd/cgroups v1.0.4 h1:jN/mbWBEaz+T1pi5OFtnkQ+8qnmEbAr1Oo1FRm5B0dA=
|
||||||
|
github.com/containerd/cgroups v1.0.4/go.mod h1:nLNQtsF7Sl2HxNebu77i1R0oDlhiTG+kO4JTrUzo6IA=
|
||||||
github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw=
|
github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw=
|
||||||
github.com/containerd/console v0.0.0-20181022165439-0650fd9eeb50/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw=
|
github.com/containerd/console v0.0.0-20181022165439-0650fd9eeb50/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw=
|
||||||
github.com/containerd/console v0.0.0-20191206165004-02ecf6a7291e/go.mod h1:8Pf4gM6VEbTNRIT26AyyU7hxdQU3MvAvxVI0sc00XBE=
|
github.com/containerd/console v0.0.0-20191206165004-02ecf6a7291e/go.mod h1:8Pf4gM6VEbTNRIT26AyyU7hxdQU3MvAvxVI0sc00XBE=
|
||||||
|
@ -5,7 +5,7 @@ go 1.18
|
|||||||
require (
|
require (
|
||||||
github.com/Microsoft/hcsshim v0.9.2
|
github.com/Microsoft/hcsshim v0.9.2
|
||||||
github.com/Microsoft/hcsshim/test v0.0.0-20210408205431-da33ecd607e1
|
github.com/Microsoft/hcsshim/test v0.0.0-20210408205431-da33ecd607e1
|
||||||
github.com/containerd/cgroups v1.0.3
|
github.com/containerd/cgroups v1.0.4
|
||||||
github.com/containerd/containerd v1.6.2 // see replace; the actual version of containerd is replaced with the code at the root of this repository
|
github.com/containerd/containerd v1.6.2 // see replace; the actual version of containerd is replaced with the code at the root of this repository
|
||||||
github.com/containerd/go-runc v1.0.0
|
github.com/containerd/go-runc v1.0.0
|
||||||
github.com/containerd/ttrpc v1.1.1-0.20220420014843-944ef4a40df3
|
github.com/containerd/ttrpc v1.1.1-0.20220420014843-944ef4a40df3
|
||||||
|
@ -132,8 +132,8 @@ github.com/containerd/aufs v1.0.0/go.mod h1:kL5kd6KM5TzQjR79jljyi4olc1Vrx6XBlcyj
|
|||||||
github.com/containerd/btrfs v1.0.0/go.mod h1:zMcX3qkXTAi9GI50+0HOeuV8LU2ryCE/V2vG/ZBiTss=
|
github.com/containerd/btrfs v1.0.0/go.mod h1:zMcX3qkXTAi9GI50+0HOeuV8LU2ryCE/V2vG/ZBiTss=
|
||||||
github.com/containerd/cgroups v0.0.0-20200824123100-0b889c03f102/go.mod h1:s5q4SojHctfxANBDvMeIaIovkq29IP48TKAxnhYRxvo=
|
github.com/containerd/cgroups v0.0.0-20200824123100-0b889c03f102/go.mod h1:s5q4SojHctfxANBDvMeIaIovkq29IP48TKAxnhYRxvo=
|
||||||
github.com/containerd/cgroups v1.0.1/go.mod h1:0SJrPIenamHDcZhEcJMNBB85rHcUsw4f25ZfBiPYRkU=
|
github.com/containerd/cgroups v1.0.1/go.mod h1:0SJrPIenamHDcZhEcJMNBB85rHcUsw4f25ZfBiPYRkU=
|
||||||
github.com/containerd/cgroups v1.0.3 h1:ADZftAkglvCiD44c77s5YmMqaP2pzVCFZvBmAlBdAP4=
|
github.com/containerd/cgroups v1.0.4 h1:jN/mbWBEaz+T1pi5OFtnkQ+8qnmEbAr1Oo1FRm5B0dA=
|
||||||
github.com/containerd/cgroups v1.0.3/go.mod h1:/ofk34relqNjSGyqPrmEULrO4Sc8LJhvJmWbUCUKqj8=
|
github.com/containerd/cgroups v1.0.4/go.mod h1:nLNQtsF7Sl2HxNebu77i1R0oDlhiTG+kO4JTrUzo6IA=
|
||||||
github.com/containerd/console v0.0.0-20191206165004-02ecf6a7291e/go.mod h1:8Pf4gM6VEbTNRIT26AyyU7hxdQU3MvAvxVI0sc00XBE=
|
github.com/containerd/console v0.0.0-20191206165004-02ecf6a7291e/go.mod h1:8Pf4gM6VEbTNRIT26AyyU7hxdQU3MvAvxVI0sc00XBE=
|
||||||
github.com/containerd/console v1.0.1/go.mod h1:XUsP6YE/mKtz6bxc+I8UiKKTP04qjQL4qcS3XoQ5xkw=
|
github.com/containerd/console v1.0.1/go.mod h1:XUsP6YE/mKtz6bxc+I8UiKKTP04qjQL4qcS3XoQ5xkw=
|
||||||
github.com/containerd/console v1.0.2/go.mod h1:ytZPjGgY2oeTkAONYafi2kSj0aYggsf8acV1PGKCbzQ=
|
github.com/containerd/console v1.0.2/go.mod h1:ytZPjGgY2oeTkAONYafi2kSj0aYggsf8acV1PGKCbzQ=
|
||||||
|
2
vendor/github.com/containerd/cgroups/README.md
generated
vendored
2
vendor/github.com/containerd/cgroups/README.md
generated
vendored
@ -26,7 +26,7 @@ uses the v1 implementation of cgroups.
|
|||||||
```go
|
```go
|
||||||
shares := uint64(100)
|
shares := uint64(100)
|
||||||
control, err := cgroups.New(cgroups.V1, cgroups.StaticPath("/test"), &specs.LinuxResources{
|
control, err := cgroups.New(cgroups.V1, cgroups.StaticPath("/test"), &specs.LinuxResources{
|
||||||
CPU: &specs.CPU{
|
CPU: &specs.LinuxCPU{
|
||||||
Shares: &shares,
|
Shares: &shares,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
8
vendor/github.com/containerd/cgroups/Vagrantfile
generated
vendored
8
vendor/github.com/containerd/cgroups/Vagrantfile
generated
vendored
@ -3,19 +3,19 @@
|
|||||||
|
|
||||||
Vagrant.configure("2") do |config|
|
Vagrant.configure("2") do |config|
|
||||||
# Fedora box is used for testing cgroup v2 support
|
# Fedora box is used for testing cgroup v2 support
|
||||||
config.vm.box = "fedora/32-cloud-base"
|
config.vm.box = "fedora/35-cloud-base"
|
||||||
config.vm.provider :virtualbox do |v|
|
config.vm.provider :virtualbox do |v|
|
||||||
v.memory = 2048
|
v.memory = 4096
|
||||||
v.cpus = 2
|
v.cpus = 2
|
||||||
end
|
end
|
||||||
config.vm.provider :libvirt do |v|
|
config.vm.provider :libvirt do |v|
|
||||||
v.memory = 2048
|
v.memory = 4096
|
||||||
v.cpus = 2
|
v.cpus = 2
|
||||||
end
|
end
|
||||||
config.vm.provision "shell", inline: <<-SHELL
|
config.vm.provision "shell", inline: <<-SHELL
|
||||||
set -eux -o pipefail
|
set -eux -o pipefail
|
||||||
# configuration
|
# configuration
|
||||||
GO_VERSION="1.15"
|
GO_VERSION="1.17.7"
|
||||||
|
|
||||||
# install gcc and Golang
|
# install gcc and Golang
|
||||||
dnf -y install gcc
|
dnf -y install gcc
|
||||||
|
37
vendor/github.com/containerd/cgroups/utils.go
generated
vendored
37
vendor/github.com/containerd/cgroups/utils.go
generated
vendored
@ -261,21 +261,28 @@ func parseKV(raw string) (string, uint64, error) {
|
|||||||
// "pids": "/user.slice/user-1000.slice"
|
// "pids": "/user.slice/user-1000.slice"
|
||||||
// etc.
|
// etc.
|
||||||
//
|
//
|
||||||
// Note that for cgroup v2 unified hierarchy, there are no per-controller
|
// The resulting map does not have an element for cgroup v2 unified hierarchy.
|
||||||
// cgroup paths, so the resulting map will have a single element where the key
|
// Use ParseCgroupFileUnified to get the unified path.
|
||||||
// is empty string ("") and the value is the cgroup path the <pid> is in.
|
|
||||||
func ParseCgroupFile(path string) (map[string]string, error) {
|
func ParseCgroupFile(path string) (map[string]string, error) {
|
||||||
f, err := os.Open(path)
|
x, _, err := ParseCgroupFileUnified(path)
|
||||||
if err != nil {
|
return x, err
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
return parseCgroupFromReader(f)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCgroupFromReader(r io.Reader) (map[string]string, error) {
|
// ParseCgroupFileUnified returns legacy subsystem paths as the first value,
|
||||||
|
// and returns the unified path as the second value.
|
||||||
|
func ParseCgroupFileUnified(path string) (map[string]string, string, error) {
|
||||||
|
f, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
return parseCgroupFromReaderUnified(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseCgroupFromReaderUnified(r io.Reader) (map[string]string, string, error) {
|
||||||
var (
|
var (
|
||||||
cgroups = make(map[string]string)
|
cgroups = make(map[string]string)
|
||||||
|
unified = ""
|
||||||
s = bufio.NewScanner(r)
|
s = bufio.NewScanner(r)
|
||||||
)
|
)
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
@ -284,18 +291,20 @@ func parseCgroupFromReader(r io.Reader) (map[string]string, error) {
|
|||||||
parts = strings.SplitN(text, ":", 3)
|
parts = strings.SplitN(text, ":", 3)
|
||||||
)
|
)
|
||||||
if len(parts) < 3 {
|
if len(parts) < 3 {
|
||||||
return nil, fmt.Errorf("invalid cgroup entry: %q", text)
|
return nil, unified, fmt.Errorf("invalid cgroup entry: %q", text)
|
||||||
}
|
}
|
||||||
for _, subs := range strings.Split(parts[1], ",") {
|
for _, subs := range strings.Split(parts[1], ",") {
|
||||||
if subs != "" {
|
if subs == "" {
|
||||||
|
unified = parts[2]
|
||||||
|
} else {
|
||||||
cgroups[subs] = parts[2]
|
cgroups[subs] = parts[2]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := s.Err(); err != nil {
|
if err := s.Err(); err != nil {
|
||||||
return nil, err
|
return nil, unified, err
|
||||||
}
|
}
|
||||||
return cgroups, nil
|
return cgroups, unified, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCgroupDestination(subsystem string) (string, error) {
|
func getCgroupDestination(subsystem string) (string, error) {
|
||||||
|
46
vendor/github.com/containerd/cgroups/v2/manager.go
generated
vendored
46
vendor/github.com/containerd/cgroups/v2/manager.go
generated
vendored
@ -240,6 +240,10 @@ func (c *Manager) Controllers() ([]string, error) {
|
|||||||
return strings.Fields(string(b)), nil
|
return strings.Fields(string(b)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Manager) Update(resources *Resources) error {
|
||||||
|
return setResources(c.path, resources)
|
||||||
|
}
|
||||||
|
|
||||||
type ControllerToggle int
|
type ControllerToggle int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -701,12 +705,39 @@ func setDevices(path string, devices []specs.LinuxDeviceCgroup) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getSystemdFullPath returns the full systemd path when creating a systemd slice group.
|
||||||
|
// the reason this is necessary is because the "-" character has a special meaning in
|
||||||
|
// systemd slice. For example, when creating a slice called "my-group-112233.slice",
|
||||||
|
// systemd will create a hierarchy like this:
|
||||||
|
// /sys/fs/cgroup/my.slice/my-group.slice/my-group-112233.slice
|
||||||
|
func getSystemdFullPath(slice, group string) string {
|
||||||
|
return filepath.Join(defaultCgroup2Path, dashesToPath(slice), dashesToPath(group))
|
||||||
|
}
|
||||||
|
|
||||||
|
// dashesToPath converts a slice name with dashes to it's corresponding systemd filesystem path.
|
||||||
|
func dashesToPath(in string) string {
|
||||||
|
path := ""
|
||||||
|
if strings.HasSuffix(in, ".slice") && strings.Contains(in, "-") {
|
||||||
|
parts := strings.Split(in, "-")
|
||||||
|
for i := range parts {
|
||||||
|
s := strings.Join(parts[0:i+1], "-")
|
||||||
|
if !strings.HasSuffix(s, ".slice") {
|
||||||
|
s += ".slice"
|
||||||
|
}
|
||||||
|
path = filepath.Join(path, s)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
path = filepath.Join(path, in)
|
||||||
|
}
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
func NewSystemd(slice, group string, pid int, resources *Resources) (*Manager, error) {
|
func NewSystemd(slice, group string, pid int, resources *Resources) (*Manager, error) {
|
||||||
if slice == "" {
|
if slice == "" {
|
||||||
slice = defaultSlice
|
slice = defaultSlice
|
||||||
}
|
}
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
path := filepath.Join(defaultCgroup2Path, slice, group)
|
path := getSystemdFullPath(slice, group)
|
||||||
conn, err := systemdDbus.NewWithContext(ctx)
|
conn, err := systemdDbus.NewWithContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &Manager{}, err
|
return &Manager{}, err
|
||||||
@ -734,12 +765,17 @@ func NewSystemd(slice, group string, pid int, resources *Resources) (*Manager, e
|
|||||||
properties = append(properties, newSystemdProperty("PIDs", []uint32{uint32(pid)}))
|
properties = append(properties, newSystemdProperty("PIDs", []uint32{uint32(pid)}))
|
||||||
}
|
}
|
||||||
|
|
||||||
if resources.Memory != nil && *resources.Memory.Max != 0 {
|
if resources.Memory != nil && resources.Memory.Min != nil && *resources.Memory.Min != 0 {
|
||||||
|
properties = append(properties,
|
||||||
|
newSystemdProperty("MemoryMin", uint64(*resources.Memory.Min)))
|
||||||
|
}
|
||||||
|
|
||||||
|
if resources.Memory != nil && resources.Memory.Max != nil && *resources.Memory.Max != 0 {
|
||||||
properties = append(properties,
|
properties = append(properties,
|
||||||
newSystemdProperty("MemoryMax", uint64(*resources.Memory.Max)))
|
newSystemdProperty("MemoryMax", uint64(*resources.Memory.Max)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if resources.CPU != nil && *resources.CPU.Weight != 0 {
|
if resources.CPU != nil && resources.CPU.Weight != nil && *resources.CPU.Weight != 0 {
|
||||||
properties = append(properties,
|
properties = append(properties,
|
||||||
newSystemdProperty("CPUWeight", *resources.CPU.Weight))
|
newSystemdProperty("CPUWeight", *resources.CPU.Weight))
|
||||||
}
|
}
|
||||||
@ -796,9 +832,9 @@ func LoadSystemd(slice, group string) (*Manager, error) {
|
|||||||
if slice == "" {
|
if slice == "" {
|
||||||
slice = defaultSlice
|
slice = defaultSlice
|
||||||
}
|
}
|
||||||
group = filepath.Join(defaultCgroup2Path, slice, group)
|
path := getSystemdFullPath(slice, group)
|
||||||
return &Manager{
|
return &Manager{
|
||||||
path: group,
|
path: path,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
vendor/github.com/containerd/cgroups/v2/memory.go
generated
vendored
7
vendor/github.com/containerd/cgroups/v2/memory.go
generated
vendored
@ -18,6 +18,7 @@ package v2
|
|||||||
|
|
||||||
type Memory struct {
|
type Memory struct {
|
||||||
Swap *int64
|
Swap *int64
|
||||||
|
Min *int64
|
||||||
Max *int64
|
Max *int64
|
||||||
Low *int64
|
Low *int64
|
||||||
High *int64
|
High *int64
|
||||||
@ -30,6 +31,12 @@ func (r *Memory) Values() (o []Value) {
|
|||||||
value: *r.Swap,
|
value: *r.Swap,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if r.Min != nil {
|
||||||
|
o = append(o, Value{
|
||||||
|
filename: "memory.min",
|
||||||
|
value: *r.Min,
|
||||||
|
})
|
||||||
|
}
|
||||||
if r.Max != nil {
|
if r.Max != nil {
|
||||||
o = append(o, Value{
|
o = append(o, Value{
|
||||||
filename: "memory.max",
|
filename: "memory.max",
|
||||||
|
2
vendor/github.com/containerd/cgroups/v2/utils.go
generated
vendored
2
vendor/github.com/containerd/cgroups/v2/utils.go
generated
vendored
@ -227,7 +227,7 @@ func ToResources(spec *specs.LinuxResources) *Resources {
|
|||||||
if i := spec.Rdma; i != nil {
|
if i := spec.Rdma; i != nil {
|
||||||
resources.RDMA = &RDMA{}
|
resources.RDMA = &RDMA{}
|
||||||
for device, value := range spec.Rdma {
|
for device, value := range spec.Rdma {
|
||||||
if device != "" && (value.HcaHandles != nil || value.HcaObjects != nil) {
|
if device != "" && (value.HcaHandles != nil && value.HcaObjects != nil) {
|
||||||
resources.RDMA.Limit = append(resources.RDMA.Limit, RDMAEntry{
|
resources.RDMA.Limit = append(resources.RDMA.Limit, RDMAEntry{
|
||||||
Device: device,
|
Device: device,
|
||||||
HcaHandles: *value.HcaHandles,
|
HcaHandles: *value.HcaHandles,
|
||||||
|
4
vendor/modules.txt
vendored
4
vendor/modules.txt
vendored
@ -80,8 +80,8 @@ github.com/containerd/aufs/plugin
|
|||||||
# github.com/containerd/btrfs v1.0.0
|
# github.com/containerd/btrfs v1.0.0
|
||||||
## explicit; go 1.15
|
## explicit; go 1.15
|
||||||
github.com/containerd/btrfs
|
github.com/containerd/btrfs
|
||||||
# github.com/containerd/cgroups v1.0.3
|
# github.com/containerd/cgroups v1.0.4
|
||||||
## explicit; go 1.16
|
## explicit; go 1.17
|
||||||
github.com/containerd/cgroups
|
github.com/containerd/cgroups
|
||||||
github.com/containerd/cgroups/stats/v1
|
github.com/containerd/cgroups/stats/v1
|
||||||
github.com/containerd/cgroups/v2
|
github.com/containerd/cgroups/v2
|
||||||
|
Loading…
Reference in New Issue
Block a user