From a0c9be20617a871c6cb61f27516565af36338d7a Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Wed, 28 Nov 2018 12:24:14 -0500 Subject: Add --sync option to podman rm With the changes made recently to ensure Podman does not hit the OCI runtime as often to sync state, we can find ourselves in a situation where the runtime's state does not match ours. Add a --sync flag to podman rm to ensure we can still remove containers when this happens. Signed-off-by: Matthew Heon --- libpod/container_api.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'libpod/container_api.go') diff --git a/libpod/container_api.go b/libpod/container_api.go index bc92cae69..ee060ad6a 100644 --- a/libpod/container_api.go +++ b/libpod/container_api.go @@ -675,22 +675,22 @@ func (c *Container) Batch(batchFunc func(*Container) error) error { return err } -// Sync updates the current state of the container, checking whether its state -// has changed -// Sync can only be used inside Batch() - otherwise, it will be done -// automatically. -// When called outside Batch(), Sync() is a no-op +// Sync updates the status of a container by querying the OCI runtime. +// If the container has not been created inside the OCI runtime, nothing will be +// done. +// Most of the time, Podman does not explicitly query the OCI runtime for +// container status, and instead relies upon exit files created by conmon. +// This can cause a disconnect between running state and what Podman sees in +// cases where Conmon was killed unexpected, or runc was upgraded. +// Running a manual Sync() ensures that container state will be correct in +// such situations. func (c *Container) Sync() error { - if !c.batched { - return nil - } - // If runtime knows about the container, update its status in runtime // And then save back to disk if (c.state.State != ContainerStateUnknown) && - (c.state.State != ContainerStateConfigured) { + (c.state.State != ContainerStateConfigured) && + (c.state.State != ContainerStateExited) { oldState := c.state.State - // TODO: optionally replace this with a stat for the exit file if err := c.runtime.ociRuntime.updateContainerStatus(c, true); err != nil { return err } -- cgit v1.2.3-54-g00ecf From b945d9128a0988ee006a8c743127cf1edc9cb47b Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Wed, 28 Nov 2018 13:06:32 -0500 Subject: Add locking to Sync() on containers Previously not needed as it only worked inside of Batch(), but now that it can be called anywhere we need to add mutual exclusion on its config changes. Signed-off-by: Matthew Heon --- libpod/container_api.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libpod/container_api.go') diff --git a/libpod/container_api.go b/libpod/container_api.go index ee060ad6a..09bc46905 100644 --- a/libpod/container_api.go +++ b/libpod/container_api.go @@ -685,6 +685,11 @@ func (c *Container) Batch(batchFunc func(*Container) error) error { // Running a manual Sync() ensures that container state will be correct in // such situations. func (c *Container) Sync() error { + if !c.batched { + c.lock.Lock() + defer c.lock.Unlock() + } + // If runtime knows about the container, update its status in runtime // And then save back to disk if (c.state.State != ContainerStateUnknown) && -- cgit v1.2.3-54-g00ecf