mirror of
https://github.com/containers/podman.git
synced 2025-06-24 19:42:56 +08:00
Merge pull request #17281 from vrothberg/rm-perf
container rm: save once for exec removal and state change
This commit is contained in:
@ -1072,14 +1072,6 @@ func (c *Container) removeAllExecSessions() error {
|
||||
}
|
||||
c.state.ExecSessions = nil
|
||||
c.state.LegacyExecSessions = nil
|
||||
if err := c.save(); err != nil {
|
||||
if !errors.Is(err, define.ErrCtrRemoved) {
|
||||
if lastErr != nil {
|
||||
logrus.Errorf("Stopping container %s exec sessions: %v", c.ID(), lastErr)
|
||||
}
|
||||
lastErr = err
|
||||
}
|
||||
}
|
||||
|
||||
return lastErr
|
||||
}
|
||||
|
@ -776,16 +776,6 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force, remo
|
||||
cleanupErr = fmt.Errorf("cleaning up container %s: %w", c.ID(), err)
|
||||
}
|
||||
|
||||
// Set ContainerStateRemoving
|
||||
c.state.State = define.ContainerStateRemoving
|
||||
|
||||
if err := c.save(); err != nil {
|
||||
if cleanupErr != nil {
|
||||
logrus.Errorf(err.Error())
|
||||
}
|
||||
return fmt.Errorf("unable to set container %s removing state in database: %w", c.ID(), err)
|
||||
}
|
||||
|
||||
// Remove all active exec sessions
|
||||
// removing the exec sessions might temporarily unlock the container's lock. Using it
|
||||
// after setting the state to ContainerStateRemoving will prevent that the container is
|
||||
@ -798,6 +788,20 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force, remo
|
||||
}
|
||||
}
|
||||
|
||||
// Set ContainerStateRemoving as an intermediate state (we may get
|
||||
// killed at any time) and save the container.
|
||||
c.state.State = define.ContainerStateRemoving
|
||||
|
||||
if err := c.save(); err != nil {
|
||||
if !errors.Is(err, define.ErrCtrRemoved) {
|
||||
if cleanupErr == nil {
|
||||
cleanupErr = err
|
||||
} else {
|
||||
logrus.Errorf("Saving container: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Stop the container's storage
|
||||
if err := c.teardownStorage(); err != nil {
|
||||
if cleanupErr == nil {
|
||||
|
Reference in New Issue
Block a user