summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-05-09 16:33:31 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-05-11 14:43:57 +0000
commitc4c5c1a3e191348491299aa2d53397879da0854d (patch)
tree5370f50ecc5239d2a4279cc5b133107671c4b1c9
parentb70f6cc04a831478b2c81094b6bfe80bfed6a687 (diff)
downloadpodman-c4c5c1a3e191348491299aa2d53397879da0854d.tar.gz
podman-c4c5c1a3e191348491299aa2d53397879da0854d.tar.bz2
podman-c4c5c1a3e191348491299aa2d53397879da0854d.zip
Remove parent cgroup we create with cgroupfs
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #507 Approved by: baude
-rw-r--r--libpod/container_internal.go35
-rw-r--r--libpod/runtime_ctr.go5
2 files changed, 40 insertions, 0 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 816e7bd31..21ddf9cbb 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -14,6 +14,7 @@ import (
"syscall"
"time"
+ "github.com/containerd/cgroups"
"github.com/containers/storage"
"github.com/containers/storage/pkg/archive"
"github.com/containers/storage/pkg/chrootarchive"
@@ -721,6 +722,30 @@ func (c *Container) prepare() (err error) {
return nil
}
+// cleanupCgroup cleans up residual CGroups after container execution
+// This is a no-op for the systemd cgroup driver
+func (c *Container) cleanupCgroups() error {
+ if c.runtime.config.CgroupManager == SystemdCgroupsManager {
+ return nil
+ }
+
+ // Remove the base path of the container's cgroups
+ path := filepath.Join(c.config.CgroupParent, fmt.Sprintf("libpod-%s", c.ID()))
+
+ logrus.Debugf("Removing CGroup %s", path)
+
+ cgroup, err := cgroups.Load(cgroups.V1, cgroups.StaticPath(path))
+ if err != nil {
+ return err
+ }
+
+ if err := cgroup.Delete(); err != nil {
+ return err
+ }
+
+ return nil
+}
+
// cleanupNetwork unmounts and cleans up the container's network
func (c *Container) cleanupNetwork() error {
// Stop the container's network namespace (if it has one)
@@ -764,11 +789,21 @@ func (c *Container) cleanupStorage() error {
func (c *Container) cleanup() error {
var lastError error
+ logrus.Debugf("Cleaning up container %s", c.ID())
+
// Clean up network namespace, if present
if err := c.cleanupNetwork(); err != nil {
lastError = nil
}
+ if err := c.cleanupCgroups(); err != nil {
+ if lastError != nil {
+ logrus.Errorf("Error cleaning up container %s CGroups: %v", c.ID(), err)
+ } else {
+ lastError = err
+ }
+ }
+
// Unmount storage
if err := c.cleanupStorage(); err != nil {
if lastError != nil {
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go
index f5d8e5704..981f745b4 100644
--- a/libpod/runtime_ctr.go
+++ b/libpod/runtime_ctr.go
@@ -219,6 +219,11 @@ func (r *Runtime) removeContainer(c *Container, force bool) error {
return errors.Wrapf(ErrCtrExists, "container %s has dependent containers which must be removed before it: %s", c.ID(), depsStr)
}
+ // Tear down the container's cgroups (if they exist)
+ if err := c.cleanupCgroups(); err != nil {
+ return err
+ }
+
// Stop the container's network namespace (if it has one)
if err := r.teardownNetNS(c); err != nil {
return err