From f3bce92a24300366c1f14e2a71361bceefd90e59 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 21 Aug 2021 00:14:25 +0200 Subject: [PATCH] daemon: cleanupContainer(): pass ContainerRmConfig as parameter We already have this config, so might as well pass it, instead of passing each option as a separate argument. Signed-off-by: Sebastiaan van Stijn --- daemon/create.go | 8 ++++++-- daemon/delete.go | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/daemon/create.go b/daemon/create.go index 89334c310b..c7942d286c 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -153,8 +153,12 @@ func (daemon *Daemon) create(opts createOpts) (retC *container.Container, retErr } defer func() { if retErr != nil { - if err := daemon.cleanupContainer(ctr, true, true); err != nil { - logrus.Errorf("failed to cleanup container on create error: %v", err) + err = daemon.cleanupContainer(ctr, types.ContainerRmConfig{ + ForceRemove: true, + RemoveVolume: true, + }) + if err != nil { + logrus.WithError(err).Error("failed to cleanup container on create error") } } }() diff --git a/daemon/delete.go b/daemon/delete.go index a8d924cbd2..f1a2ed737a 100644 --- a/daemon/delete.go +++ b/daemon/delete.go @@ -43,7 +43,7 @@ func (daemon *Daemon) ContainerRm(name string, config *types.ContainerRmConfig) return daemon.rmLink(ctr, name) } - err = daemon.cleanupContainer(ctr, config.ForceRemove, config.RemoveVolume) + err = daemon.cleanupContainer(ctr, *config) containerActions.WithValues("delete").UpdateSince(start) return err @@ -77,9 +77,9 @@ func (daemon *Daemon) rmLink(container *container.Container, name string) error // cleanupContainer unregisters a container from the daemon, stops stats // collection and cleanly removes contents and metadata from the filesystem. -func (daemon *Daemon) cleanupContainer(container *container.Container, forceRemove, removeVolume bool) error { +func (daemon *Daemon) cleanupContainer(container *container.Container, config types.ContainerRmConfig) error { if container.IsRunning() { - if !forceRemove { + if !config.ForceRemove { state := container.StateString() procedure := "Stop the container before attempting removal or force remove" if state == "paused" { @@ -135,7 +135,7 @@ func (daemon *Daemon) cleanupContainer(container *container.Container, forceRemo daemon.idIndex.Delete(container.ID) daemon.containers.Delete(container.ID) daemon.containersReplica.Delete(container) - if err := daemon.removeMountPoints(container, removeVolume); err != nil { + if err := daemon.removeMountPoints(container, config.RemoveVolume); err != nil { logrus.Error(err) } for _, name := range linkNames {