
This patch adds support for a container annotation and two separate
pod annotations for controlling the blockio class of containers.
The container annotation can be used by a CRI client:
"io.kubernetes.cri.blockio-class"
Pod annotations specify the blockio class in the K8s pod spec level:
"blockio.resources.beta.kubernetes.io/pod"
(pod-wide default for all containers within)
"blockio.resources.beta.kubernetes.io/container.<container_name>"
(container-specific overrides)
Correspondingly, this patch adds support for --blockio-class and
--blockio-config-file to ctr, too.
This implementation follows the resource class annotation pattern
introduced in RDT and merged in commit 893701220
.
Signed-off-by: Antti Kervinen <antti.kervinen@intel.com>
66 lines
1.1 KiB
Go
66 lines
1.1 KiB
Go
package cgroups
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"sync"
|
|
)
|
|
|
|
// CgroupID implements mapping kernel cgroup IDs to cgroupfs paths with transparent caching.
|
|
type CgroupID struct {
|
|
root string
|
|
cache map[uint64]string
|
|
sync.Mutex
|
|
}
|
|
|
|
// NewCgroupID creates a new CgroupID map/cache.
|
|
func NewCgroupID(root string) *CgroupID {
|
|
return &CgroupID{
|
|
root: root,
|
|
cache: make(map[uint64]string),
|
|
}
|
|
}
|
|
|
|
// Find finds the path for the given cgroup id.
|
|
func (cgid *CgroupID) Find(id uint64) (string, error) {
|
|
found := false
|
|
var p string
|
|
|
|
cgid.Lock()
|
|
defer cgid.Unlock()
|
|
|
|
if path, ok := cgid.cache[id]; ok {
|
|
return path, nil
|
|
}
|
|
|
|
err := fsi.Walk(cgid.root, func(path string, info os.FileInfo, err error) error {
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
return nil
|
|
}
|
|
return err
|
|
}
|
|
|
|
if found {
|
|
return filepath.SkipDir
|
|
}
|
|
|
|
if info.IsDir() && id == getID(path) {
|
|
found = true
|
|
p = path
|
|
return filepath.SkipDir
|
|
}
|
|
return nil
|
|
})
|
|
|
|
if err != nil {
|
|
return "", err
|
|
} else if !found {
|
|
return "", fmt.Errorf("cgroupid %v not found", id)
|
|
} else {
|
|
cgid.cache[id] = p
|
|
return p, nil
|
|
}
|
|
}
|