diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-06-21 09:45:03 -0400 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-06-22 19:26:46 +0000 |
commit | 334345671759d521ee6fbe7f6e1e7392ee312ab4 (patch) | |
tree | 0478ad55c1430af8834ac94a8306272499fb98a2 /libpod/container_internal.go | |
parent | 7a7d0f1446590f5895869d26f7dc9893fa5be3a2 (diff) | |
download | podman-334345671759d521ee6fbe7f6e1e7392ee312ab4.tar.gz podman-334345671759d521ee6fbe7f6e1e7392ee312ab4.tar.bz2 podman-334345671759d521ee6fbe7f6e1e7392ee312ab4.zip |
Add Refresh() to ctrs to refresh state after db change
The Refresh() function is used to reset a container's state after
a database format change to state is made that requires migration
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.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index f3be6f73b..fee13953c 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -316,6 +316,23 @@ func (c *Container) teardownStorage() error { return nil } +// Reset resets state fields to default values +// It is performed before a refresh and clears the state after a reboot +// It does not save the results - assumes the database will do that for us +func resetState(state *containerState) error { + state.PID = 0 + state.Mountpoint = "" + state.Mounted = false + state.State = ContainerStateConfigured + state.ExecSessions = make(map[string]*ExecSession) + state.IPs = nil + state.Interfaces = nil + state.Routes = nil + state.BindMounts = make(map[string]string) + + return nil +} + // Refresh refreshes the container's state after a restart func (c *Container) refresh() error { c.lock.Lock() @@ -681,6 +698,32 @@ func (c *Container) stop(timeout uint) error { return c.cleanup() } +// Internal, non-locking function to pause a container +func (c *Container) pause() error { + if err := c.runtime.ociRuntime.pauseContainer(c); err != nil { + return err + } + + logrus.Debugf("Paused container %s", c.ID()) + + c.state.State = ContainerStatePaused + + return c.save() +} + +// Internal, non-locking function to unpause a container +func (c *Container) unpause() error { + if err := c.runtime.ociRuntime.unpauseContainer(c); err != nil { + return err + } + + logrus.Debugf("Unpaused container %s", c.ID()) + + c.state.State = ContainerStateRunning + + return c.save() +} + // mountStorage sets up the container's root filesystem // It mounts the image and any other requested mounts // TODO: Add ability to override mount label so we can use this for Mount() too |