mirror of
https://github.com/containers/podman.git
synced 2025-05-20 16:47:39 +08:00
Add ContainerStateRemoving
When Libpod removes a container, there is the possibility that removal will not fully succeed. The most notable problems are storage issues, where the container cannot be removed from c/storage. When this occurs, we were faced with a choice. We can keep the container in the state, appearing in `podman ps` and available for other API operations, but likely unable to do any of them as it's been partially removed. Or we can remove it very early and clean up after it's already gone. We have, until now, used the second approach. The problem that arises is intermittent problems removing storage. We end up removing a container, failing to remove its storage, and ending up with a container permanently stuck in c/storage that we can't remove with the normal Podman CLI, can't use the name of, and generally can't interact with. A notable cause is when Podman is hit by a SIGKILL midway through removal, which can consistently cause `podman rm` to fail to remove storage. We now add a new state for containers that are in the process of being removed, ContainerStateRemoving. We set this at the beginning of the removal process. It notifies Podman that the container cannot be used anymore, but preserves it in the DB until it is fully removed. This will allow Remove to be run on these containers again, which should successfully remove storage if it fails. Fixes #3906 Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
@ -404,6 +404,11 @@ func (c *Container) Mount() (string, error) {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
if c.state.State == define.ContainerStateRemoving {
|
||||
return "", errors.Wrapf(define.ErrCtrStateInvalid, "cannot mount container %s as it is being removed", c.ID())
|
||||
}
|
||||
|
||||
defer c.newContainerEvent(events.Mount)
|
||||
return c.mount()
|
||||
}
|
||||
@ -488,7 +493,12 @@ func (c *Container) Export(path string) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
defer c.newContainerEvent(events.Export)
|
||||
|
||||
if c.state.State == define.ContainerStateRemoving {
|
||||
return errors.Wrapf(define.ErrCtrStateInvalid, "cannot mount container %s as it is being removed", c.ID())
|
||||
}
|
||||
|
||||
defer c.newContainerEvent(events.Mount)
|
||||
return c.export(path)
|
||||
}
|
||||
|
||||
@ -674,6 +684,10 @@ func (c *Container) Refresh(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
if c.state.State == define.ContainerStateRemoving {
|
||||
return errors.Wrapf(define.ErrCtrStateInvalid, "cannot refresh containers that are being removed")
|
||||
}
|
||||
|
||||
wasCreated := false
|
||||
if c.state.State == define.ContainerStateCreated {
|
||||
wasCreated = true
|
||||
@ -819,7 +833,6 @@ func (c *Container) Checkpoint(ctx context.Context, options ContainerCheckpointO
|
||||
return err
|
||||
}
|
||||
}
|
||||
defer c.newContainerEvent(events.Checkpoint)
|
||||
return c.checkpoint(ctx, options)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user