mirror of
https://github.com/containers/podman.git
synced 2025-06-28 14:29:04 +08:00
libpod: use pkg/cgroups instead of containerd/cgroups
use the new implementation for dealing with cgroups. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -1461,13 +1461,6 @@ 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
|
||||
}
|
||||
|
||||
// this should be from chrootarchive.
|
||||
func (c *Container) copyWithTarFromImage(src, dest string) error {
|
||||
mountpoint, err := c.mount()
|
||||
|
@ -15,8 +15,8 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/cgroups"
|
||||
"github.com/containers/libpod/libpod/define"
|
||||
"github.com/containers/libpod/pkg/cgroups"
|
||||
"github.com/containers/libpod/pkg/rootless"
|
||||
"github.com/containers/libpod/pkg/util"
|
||||
"github.com/containers/libpod/utils"
|
||||
@ -49,13 +49,13 @@ func (r *OCIRuntime) moveConmonToCgroup(ctr *Container, cgroupParent string, cmd
|
||||
}
|
||||
} else {
|
||||
cgroupPath := filepath.Join(ctr.config.CgroupParent, "conmon")
|
||||
control, err := cgroups.New(cgroups.V1, cgroups.StaticPath(cgroupPath), &spec.LinuxResources{})
|
||||
control, err := cgroups.New(cgroupPath, &spec.LinuxResources{})
|
||||
if err != nil {
|
||||
logrus.Warnf("Failed to add conmon to cgroupfs sandbox cgroup: %v", err)
|
||||
} else {
|
||||
// we need to remove this defer and delete the cgroup once conmon exits
|
||||
// maybe need a conmon monitor?
|
||||
if err := control.Add(cgroups.Process{Pid: cmd.Process.Pid}); err != nil {
|
||||
if err := control.AddPid(cmd.Process.Pid); err != nil {
|
||||
logrus.Warnf("Failed to add conmon to cgroupfs sandbox cgroup: %v", err)
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/containerd/cgroups"
|
||||
"github.com/containers/libpod/libpod/define"
|
||||
"github.com/containers/libpod/libpod/events"
|
||||
"github.com/containers/libpod/pkg/cgroups"
|
||||
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -183,9 +183,8 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool)
|
||||
// would prevent removing the CGroups.
|
||||
if p.runtime.config.CgroupManager == CgroupfsCgroupsManager {
|
||||
// Get the conmon CGroup
|
||||
v1CGroups := GetV1CGroups(getExcludedCGroups())
|
||||
conmonCgroupPath := filepath.Join(p.state.CgroupPath, "conmon")
|
||||
conmonCgroup, err := cgroups.Load(v1CGroups, cgroups.StaticPath(conmonCgroupPath))
|
||||
conmonCgroup, err := cgroups.Load(conmonCgroupPath)
|
||||
if err != nil && err != cgroups.ErrCgroupDeleted {
|
||||
if removalErr == nil {
|
||||
removalErr = errors.Wrapf(err, "error retrieving pod %s conmon cgroup %s", p.ID(), conmonCgroupPath)
|
||||
@ -250,9 +249,8 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool)
|
||||
// Make sure the conmon cgroup is deleted first
|
||||
// Since the pod is almost gone, don't bother failing
|
||||
// hard - instead, just log errors.
|
||||
v1CGroups := GetV1CGroups(getExcludedCGroups())
|
||||
conmonCgroupPath := filepath.Join(p.state.CgroupPath, "conmon")
|
||||
conmonCgroup, err := cgroups.Load(v1CGroups, cgroups.StaticPath(conmonCgroupPath))
|
||||
conmonCgroup, err := cgroups.Load(conmonCgroupPath)
|
||||
if err != nil && err != cgroups.ErrCgroupDeleted {
|
||||
if removalErr == nil {
|
||||
removalErr = errors.Wrapf(err, "error retrieving pod %s conmon cgroup", p.ID())
|
||||
@ -269,7 +267,7 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool)
|
||||
}
|
||||
}
|
||||
}
|
||||
cgroup, err := cgroups.Load(v1CGroups, cgroups.StaticPath(p.state.CgroupPath))
|
||||
cgroup, err := cgroups.Load(p.state.CgroupPath)
|
||||
if err != nil && err != cgroups.ErrCgroupDeleted {
|
||||
if removalErr == nil {
|
||||
removalErr = errors.Wrapf(err, "error retrieving pod %s cgroup", p.ID())
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/cgroups"
|
||||
"github.com/containers/libpod/libpod/define"
|
||||
"github.com/containers/libpod/pkg/cgroups"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -34,14 +34,13 @@ func (c *Container) GetContainerStats(previousStats *ContainerStats) (*Container
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v1CGroups := GetV1CGroups(getExcludedCGroups())
|
||||
cgroup, err := cgroups.Load(v1CGroups, cgroups.StaticPath(cgroupPath))
|
||||
cgroup, err := cgroups.Load(cgroupPath)
|
||||
if err != nil {
|
||||
return stats, errors.Wrapf(err, "unable to load cgroup at %s", cgroupPath)
|
||||
}
|
||||
|
||||
// Ubuntu does not have swap memory in cgroups because swap is often not enabled.
|
||||
cgroupStats, err := cgroup.Stat(cgroups.IgnoreNotExist)
|
||||
cgroupStats, err := cgroup.Stat()
|
||||
if err != nil {
|
||||
return stats, errors.Wrapf(err, "unable to obtain cgroup stats")
|
||||
}
|
||||
|
@ -6,10 +6,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/containerd/cgroups"
|
||||
"github.com/containers/libpod/libpod/define"
|
||||
"github.com/containers/libpod/pkg/util"
|
||||
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/containers/libpod/pkg/cgroups"
|
||||
"github.com/opencontainers/selinux/go-selinux/label"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -42,7 +40,7 @@ func makeSystemdCgroup(path string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return controller.Create(path, &spec.LinuxResources{})
|
||||
return controller.CreateSystemdUnit(path)
|
||||
}
|
||||
|
||||
// deleteSystemdCgroup deletes the systemd cgroup at the given location
|
||||
@ -52,7 +50,7 @@ func deleteSystemdCgroup(path string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return controller.Delete(path)
|
||||
return controller.DeleteByPath(path)
|
||||
}
|
||||
|
||||
// assembleSystemdCgroupName creates a systemd cgroup path given a base and
|
||||
@ -71,29 +69,6 @@ func assembleSystemdCgroupName(baseSlice, newSlice string) (string, error) {
|
||||
return final, 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
|
||||
}
|
||||
}
|
||||
|
||||
// LabelVolumePath takes a mount path for a volume and gives it an
|
||||
// selinux label of either shared or not
|
||||
func LabelVolumePath(path string, shared bool) error {
|
||||
|
@ -59,8 +59,6 @@ func (c *blkioHandler) Stat(ctr *CgroupControl, m *Metrics) error {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
var ioServiceBytesRecursive []BlkIOEntry
|
||||
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
@ -95,6 +93,9 @@ func (c *blkioHandler) Stat(ctr *CgroupControl, m *Metrics) error {
|
||||
}
|
||||
ioServiceBytesRecursive = append(ioServiceBytesRecursive, entry)
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
m.Blkio = BlkioMetrics{IoServiceBytesRecursive: ioServiceBytesRecursive}
|
||||
return nil
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
|
@ -50,7 +50,7 @@ func (c *pidHandler) Stat(ctr *CgroupControl, m *Metrics) error {
|
||||
return fmt.Errorf("function not implemented yet")
|
||||
}
|
||||
|
||||
PIDRoot := ctr.getCgroupv1Path(Pids)
|
||||
PIDRoot = ctr.getCgroupv1Path(Pids)
|
||||
|
||||
current, err := readFileAsUint64(filepath.Join(PIDRoot, "pids.current"))
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user