libcontainer: cgroups: deal with unlimited case for pids.max
Make sure we don't error out collecting statistics for cases where pids.max == "max". In that case, we can use a limit of 0 which means "unlimited". In addition, change the name of the stats attribute (Max) to mirror the name of the resources attribute in the spec (Limit) so that it's consistent internally. Signed-off-by: Aleksa Sarai <asarai@suse.de>
This commit is contained in:
parent
bbde9c426f
commit
087b953dc5
|
@ -4,6 +4,7 @@ package fs
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/opencontainers/runc/libcontainer/cgroups"
|
||||
|
@ -52,12 +53,21 @@ func (s *PidsGroup) GetStats(path string, stats *cgroups.Stats) error {
|
|||
return fmt.Errorf("failed to parse pids.current - %s", err)
|
||||
}
|
||||
|
||||
max, err := getCgroupParamUint(path, "pids.max")
|
||||
maxString, err := getCgroupParamString(path, "pids.max")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse pids.max - %s", err)
|
||||
}
|
||||
|
||||
// Default if pids.max == "max" is 0 -- which represents "no limit".
|
||||
var max uint64
|
||||
if maxString != "max" {
|
||||
max, err = parseUint(maxString, 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse pids.max - unable to parse %q as a uint from Cgroup file %q", maxString, filepath.Join(path, "pids.max"))
|
||||
}
|
||||
}
|
||||
|
||||
stats.PidsStats.Current = current
|
||||
stats.PidsStats.Max = max
|
||||
stats.PidsStats.Limit = max
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ type PidsStats struct {
|
|||
// number of pids in the cgroup
|
||||
Current uint64 `json:"current,omitempty"`
|
||||
// active pids hard limit
|
||||
Max uint64 `json:"max,omitempty"`
|
||||
Limit uint64 `json:"limit,omitempty"`
|
||||
}
|
||||
|
||||
type BlkioStatEntry struct {
|
||||
|
|
Loading…
Reference in New Issue