summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2019-06-19 11:13:18 +0200
committerGiuseppe Scrivano <gscrivan@redhat.com>2019-06-26 13:17:02 +0200
commit72cf0c81e86435c1c8daed9bff183b20d6bc400c (patch)
tree09ce3687ec7977ac2a027639e376db3586979bc2
parentfa1869381301797295dece0aec12435fc902295b (diff)
downloadpodman-72cf0c81e86435c1c8daed9bff183b20d6bc400c.tar.gz
podman-72cf0c81e86435c1c8daed9bff183b20d6bc400c.tar.bz2
podman-72cf0c81e86435c1c8daed9bff183b20d6bc400c.zip
libpod: use pkg/cgroups instead of containerd/cgroups
use the new implementation for dealing with cgroups. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
-rw-r--r--libpod/container_internal.go7
-rw-r--r--libpod/oci_linux.go6
-rw-r--r--libpod/runtime_pod_linux.go10
-rw-r--r--libpod/stats.go7
-rw-r--r--libpod/util_linux.go31
-rw-r--r--pkg/cgroups/blkio.go5
-rw-r--r--pkg/cgroups/cgroups.go1
-rw-r--r--pkg/cgroups/pids.go2
8 files changed, 17 insertions, 52 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 2687bcdd1..fcd6a990a 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -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()
diff --git a/libpod/oci_linux.go b/libpod/oci_linux.go
index 07bc4e5f3..7d9f47ae2 100644
--- a/libpod/oci_linux.go
+++ b/libpod/oci_linux.go
@@ -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)
}
}
diff --git a/libpod/runtime_pod_linux.go b/libpod/runtime_pod_linux.go
index d1d303ad5..11dc8cd44 100644
--- a/libpod/runtime_pod_linux.go
+++ b/libpod/runtime_pod_linux.go
@@ -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())
diff --git a/libpod/stats.go b/libpod/stats.go
index 926a1a511..e003f145b 100644
--- a/libpod/stats.go
+++ b/libpod/stats.go
@@ -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")
}
diff --git a/libpod/util_linux.go b/libpod/util_linux.go
index 8752eba20..77dcf86f6 100644
--- a/libpod/util_linux.go
+++ b/libpod/util_linux.go
@@ -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 {
diff --git a/pkg/cgroups/blkio.go b/pkg/cgroups/blkio.go
index 8434703fd..8eb54abec 100644
--- a/pkg/cgroups/blkio.go
+++ b/pkg/cgroups/blkio.go
@@ -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
}
diff --git a/pkg/cgroups/cgroups.go b/pkg/cgroups/cgroups.go
index 2a88c9db6..24dce71bd 100644
--- a/pkg/cgroups/cgroups.go
+++ b/pkg/cgroups/cgroups.go
@@ -6,7 +6,6 @@ import (
"os"
"path/filepath"
"strconv"
- "strings"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
diff --git a/pkg/cgroups/pids.go b/pkg/cgroups/pids.go
index f37ac7611..342b25d85 100644
--- a/pkg/cgroups/pids.go
+++ b/pkg/cgroups/pids.go
@@ -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 {