From 334345671759d521ee6fbe7f6e1e7392ee312ab4 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 21 Jun 2018 09:45:03 -0400 Subject: 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 Closes: #981 Approved by: baude --- libpod/container_internal.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'libpod/container_internal.go') 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 -- cgit v1.2.3-54-g00ecf