diff options
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container_internal.go | 7 | ||||
-rw-r--r-- | libpod/runtime_pod_linux.go | 3 | ||||
-rw-r--r-- | libpod/stats.go | 7 | ||||
-rw-r--r-- | libpod/util.go | 25 |
4 files changed, 38 insertions, 4 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 71a3c4caf..033426817 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1333,3 +1333,10 @@ func (c *Container) unmount(force bool) error { return nil } + +// getExcludedCGroups returns a string slice of cgroups we want to exclude +// because runc or other components are unaware of them. +func getExcludedCGroups() (excludes []string) { + excludes = []string{"rdma"} + return +} diff --git a/libpod/runtime_pod_linux.go b/libpod/runtime_pod_linux.go index 974cd2b68..eb3d471dd 100644 --- a/libpod/runtime_pod_linux.go +++ b/libpod/runtime_pod_linux.go @@ -265,7 +265,8 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool) } case CgroupfsCgroupsManager: // Delete the cgroupfs cgroup - cgroup, err := cgroups.Load(cgroups.V1, cgroups.StaticPath(p.state.CgroupPath)) + v1CGroups := GetV1CGroups(getExcludedCGroups()) + cgroup, err := cgroups.Load(v1CGroups, cgroups.StaticPath(p.state.CgroupPath)) if err != nil && err != cgroups.ErrCgroupDeleted { return err } else if err == nil { diff --git a/libpod/stats.go b/libpod/stats.go index 9d5efd993..c58a46135 100644 --- a/libpod/stats.go +++ b/libpod/stats.go @@ -33,13 +33,14 @@ func (c *Container) GetContainerStats(previousStats *ContainerStats) (*Container if err != nil { return nil, err } - - cgroup, err := cgroups.Load(cgroups.V1, cgroups.StaticPath(cgroupPath)) + v1CGroups := GetV1CGroups(getExcludedCGroups()) + cgroup, err := cgroups.Load(v1CGroups, cgroups.StaticPath(cgroupPath)) if err != nil { return stats, errors.Wrapf(err, "unable to load cgroup at %s", cgroupPath) } - cgroupStats, err := cgroup.Stat() + // Ubuntu does not have swap memory in cgroups because swap is often not enabled. + cgroupStats, err := cgroup.Stat(cgroups.IgnoreNotExist) if err != nil { return stats, errors.Wrapf(err, "unable to obtain cgroup stats") } diff --git a/libpod/util.go b/libpod/util.go index 17325f6e4..3b51e4fcc 100644 --- a/libpod/util.go +++ b/libpod/util.go @@ -9,8 +9,10 @@ import ( "strings" "time" + "github.com/containerd/cgroups" "github.com/containers/image/signature" "github.com/containers/image/types" + "github.com/containers/libpod/pkg/util" spec "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" ) @@ -160,3 +162,26 @@ func validPodNSOption(p *Pod, ctrPod string) error { } return nil } + +// GetV1CGroups gets the V1 cgroup subsystems and then "filters" +// out any subsystems that are provided by the caller. Passing nil +// for excludes will return the subsystems unfiltered. +//func GetV1CGroups(excludes []string) ([]cgroups.Subsystem, error) { +func GetV1CGroups(excludes []string) cgroups.Hierarchy { + return func() ([]cgroups.Subsystem, error) { + var filtered []cgroups.Subsystem + + subSystem, err := cgroups.V1() + if err != nil { + return nil, err + } + for _, s := range subSystem { + // If the name of the subsystem is not in the list of excludes, then + // add it as a keeper. + if !util.StringInSlice(string(s.Name()), excludes) { + filtered = append(filtered, s) + } + } + return filtered, nil + } +} |