mirror of
https://github.com/containers/podman.git
synced 2025-05-24 18:46:26 +08:00

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>
81 lines
2.7 KiB
Go
81 lines
2.7 KiB
Go
package define
|
|
|
|
import "github.com/pkg/errors"
|
|
|
|
// ContainerStatus represents the current state of a container
|
|
type ContainerStatus int
|
|
|
|
const (
|
|
// ContainerStateUnknown indicates that the container is in an error
|
|
// state where information about it cannot be retrieved
|
|
ContainerStateUnknown ContainerStatus = iota
|
|
// ContainerStateConfigured indicates that the container has had its
|
|
// storage configured but it has not been created in the OCI runtime
|
|
ContainerStateConfigured ContainerStatus = iota
|
|
// ContainerStateCreated indicates the container has been created in
|
|
// the OCI runtime but not started
|
|
ContainerStateCreated ContainerStatus = iota
|
|
// ContainerStateRunning indicates the container is currently executing
|
|
ContainerStateRunning ContainerStatus = iota
|
|
// ContainerStateStopped indicates that the container was running but has
|
|
// exited
|
|
ContainerStateStopped ContainerStatus = iota
|
|
// ContainerStatePaused indicates that the container has been paused
|
|
ContainerStatePaused ContainerStatus = iota
|
|
// ContainerStateExited indicates the the container has stopped and been
|
|
// cleaned up
|
|
ContainerStateExited ContainerStatus = iota
|
|
// ContainerStateRemoving indicates the container is in the process of
|
|
// being removed.
|
|
ContainerStateRemoving ContainerStatus = iota
|
|
)
|
|
|
|
// ContainerStatus returns a string representation for users
|
|
// of a container state
|
|
func (t ContainerStatus) String() string {
|
|
switch t {
|
|
case ContainerStateUnknown:
|
|
return "unknown"
|
|
case ContainerStateConfigured:
|
|
return "configured"
|
|
case ContainerStateCreated:
|
|
return "created"
|
|
case ContainerStateRunning:
|
|
return "running"
|
|
case ContainerStateStopped:
|
|
return "stopped"
|
|
case ContainerStatePaused:
|
|
return "paused"
|
|
case ContainerStateExited:
|
|
return "exited"
|
|
case ContainerStateRemoving:
|
|
return "removing"
|
|
}
|
|
return "bad state"
|
|
}
|
|
|
|
// StringToContainerStatus converts a string representation of a containers
|
|
// status into an actual container status type
|
|
func StringToContainerStatus(status string) (ContainerStatus, error) {
|
|
switch status {
|
|
case ContainerStateUnknown.String():
|
|
return ContainerStateUnknown, nil
|
|
case ContainerStateConfigured.String():
|
|
return ContainerStateConfigured, nil
|
|
case ContainerStateCreated.String():
|
|
return ContainerStateCreated, nil
|
|
case ContainerStateRunning.String():
|
|
return ContainerStateRunning, nil
|
|
case ContainerStateStopped.String():
|
|
return ContainerStateStopped, nil
|
|
case ContainerStatePaused.String():
|
|
return ContainerStatePaused, nil
|
|
case ContainerStateExited.String():
|
|
return ContainerStateExited, nil
|
|
case ContainerStateRemoving.String():
|
|
return ContainerStateRemoving, nil
|
|
default:
|
|
return ContainerStateUnknown, errors.Wrapf(ErrInvalidArg, "unknown container state: %s", status)
|
|
}
|
|
}
|