mirror of
https://github.com/containers/podman.git
synced 2025-10-19 20:23:08 +08:00
Merge pull request #302 from rhatdan/cleanup
cleanup network stack as well as storage when container shuts down.
This commit is contained in:
@ -145,5 +145,5 @@ func runCmd(c *cli.Context) error {
|
|||||||
if createConfig.Rm {
|
if createConfig.Rm {
|
||||||
return runtime.RemoveContainer(ctr, true)
|
return runtime.RemoveContainer(ctr, true)
|
||||||
}
|
}
|
||||||
return ctr.CleanupStorage()
|
return ctr.Cleanup()
|
||||||
}
|
}
|
||||||
|
@ -138,6 +138,10 @@ func startCmd(c *cli.Context) error {
|
|||||||
} else {
|
} else {
|
||||||
exitCode = int(ecode)
|
exitCode = int(ecode)
|
||||||
}
|
}
|
||||||
|
if lastError != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, lastError)
|
||||||
|
}
|
||||||
|
lastError = ctr.Cleanup()
|
||||||
}
|
}
|
||||||
return lastError
|
return lastError
|
||||||
}
|
}
|
||||||
|
@ -694,8 +694,9 @@ func (c *Container) Wait() (int32, error) {
|
|||||||
return exitCode, nil
|
return exitCode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CleanupStorage unmounts all mount points in container and cleans up container storage
|
// Cleanup unmounts all mount points in container and cleans up container storage
|
||||||
func (c *Container) CleanupStorage() error {
|
// It also cleans up the network stack
|
||||||
|
func (c *Container) Cleanup() error {
|
||||||
if !c.locked {
|
if !c.locked {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
@ -703,6 +704,12 @@ func (c *Container) CleanupStorage() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop the container's network namespace (if it has one)
|
||||||
|
if err := c.cleanupNetwork(); err != nil {
|
||||||
|
logrus.Errorf("unable cleanup network for container %s: %q", c.ID(), err)
|
||||||
|
}
|
||||||
|
|
||||||
return c.cleanupStorage()
|
return c.cleanupStorage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,6 +365,19 @@ func (c *Container) mountStorage() (err error) {
|
|||||||
return c.save()
|
return c.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cleanupNetwork unmounts and cleans up the container's network
|
||||||
|
func (c *Container) cleanupNetwork() error {
|
||||||
|
// Stop the container's network namespace (if it has one)
|
||||||
|
if err := c.runtime.teardownNetNS(c); err != nil {
|
||||||
|
logrus.Errorf("unable cleanup network for container %s: %q", c.ID(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.state.NetNS = nil
|
||||||
|
c.state.SubnetMask = ""
|
||||||
|
c.state.IPAddress = ""
|
||||||
|
return c.save()
|
||||||
|
}
|
||||||
|
|
||||||
// cleanupStorage unmounts and cleans up the container's root filesystem
|
// cleanupStorage unmounts and cleans up the container's root filesystem
|
||||||
func (c *Container) cleanupStorage() error {
|
func (c *Container) cleanupStorage() error {
|
||||||
if !c.state.Mounted {
|
if !c.state.Mounted {
|
||||||
|
Reference in New Issue
Block a user