aboutsummaryrefslogtreecommitdiff
path: root/libpod/container_internal.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-06-21 11:09:17 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-06-22 19:26:46 +0000
commitc3602075ec6ee535e2fbf3e4fcf2ecbd27fa22c9 (patch)
tree80330aed0ce1e21103307be4dd6d1d7afeb49c14 /libpod/container_internal.go
parentd2f981fd0babda31c89ac031dabc671d76b8f25a (diff)
downloadpodman-c3602075ec6ee535e2fbf3e4fcf2ecbd27fa22c9.tar.gz
podman-c3602075ec6ee535e2fbf3e4fcf2ecbd27fa22c9.tar.bz2
podman-c3602075ec6ee535e2fbf3e4fcf2ecbd27fa22c9.zip
Make CGroups cleanup optional on whether they exist
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #981 Approved by: baude
Diffstat (limited to 'libpod/container_internal.go')
-rw-r--r--libpod/container_internal.go29
1 files changed, 25 insertions, 4 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index fee13953c..1985bb141 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -329,15 +329,13 @@ func resetState(state *containerState) error {
state.Interfaces = nil
state.Routes = nil
state.BindMounts = make(map[string]string)
+ state.CgroupCreated = false
return nil
}
// Refresh refreshes the container's state after a restart
func (c *Container) refresh() error {
- c.lock.Lock()
- defer c.lock.Unlock()
-
if !c.valid {
return errors.Wrapf(ErrCtrRemoved, "container %s is not valid - may have been removed", c.ID())
}
@@ -567,6 +565,7 @@ func (c *Container) init(ctx context.Context) error {
logrus.Debugf("Created container %s in OCI runtime", c.ID())
c.state.State = ContainerStateCreated
+ c.state.CgroupCreated = true
if err := c.save(); err != nil {
return err
@@ -812,6 +811,11 @@ func (c *Container) prepare() (err error) {
// 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.state.CgroupCreated {
+ logrus.Debugf("Cgroups are not present, ignoring...")
+ return nil
+ }
+
if c.runtime.config.CgroupManager == SystemdCgroupsManager {
return nil
}
@@ -836,11 +840,22 @@ func (c *Container) cleanupCgroups() error {
return err
}
+ c.state.CgroupCreated = false
+
+ if c.valid {
+ return c.save()
+ }
+
return nil
}
// cleanupNetwork unmounts and cleans up the container's network
func (c *Container) cleanupNetwork() error {
+ if c.state.NetNS == nil {
+ logrus.Debugf("Network is already cleaned up, skipping...")
+ return nil
+ }
+
// Stop the container's network namespace (if it has one)
if err := c.runtime.teardownNetNS(c); err != nil {
logrus.Errorf("unable to cleanup network for container %s: %q", c.ID(), err)
@@ -850,13 +865,19 @@ func (c *Container) cleanupNetwork() error {
c.state.IPs = nil
c.state.Interfaces = nil
c.state.Routes = nil
- return c.save()
+
+ if c.valid {
+ return c.save()
+ }
+
+ return nil
}
// cleanupStorage unmounts and cleans up the container's root filesystem
func (c *Container) cleanupStorage() error {
if !c.state.Mounted {
// Already unmounted, do nothing
+ logrus.Debugf("Storage is already unmounted, skipping...")
return nil
}