1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #25785 from WeiZhang555/fix-flaky-external-volume-driver

bugfix: report "destroy" after all volumes of container destroy
This commit is contained in:
Vincent Demeester 2016-08-18 09:58:54 +02:00 committed by GitHub
commit 3cebff8b86
2 changed files with 6 additions and 17 deletions

View file

@ -90,7 +90,7 @@ func (daemon *Daemon) create(params types.ContainerCreateConfig, managed bool) (
} }
defer func() { defer func() {
if retErr != nil { if retErr != nil {
if err := daemon.cleanupContainer(container, true); err != nil { if err := daemon.cleanupContainer(container, true, true); err != nil {
logrus.Errorf("failed to cleanup container on create error: %v", err) logrus.Errorf("failed to cleanup container on create error: %v", err)
} }
} }
@ -118,13 +118,6 @@ func (daemon *Daemon) create(params types.ContainerCreateConfig, managed bool) (
if err := daemon.setHostConfig(container, params.HostConfig); err != nil { if err := daemon.setHostConfig(container, params.HostConfig); err != nil {
return nil, err return nil, err
} }
defer func() {
if retErr != nil {
if err := daemon.removeMountPoints(container, true); err != nil {
logrus.Error(err)
}
}
}()
if err := daemon.createContainerPlatformSpecificSettings(container, params.Config, params.HostConfig); err != nil { if err := daemon.createContainerPlatformSpecificSettings(container, params.Config, params.HostConfig); err != nil {
return nil, err return nil, err

View file

@ -39,14 +39,7 @@ func (daemon *Daemon) ContainerRm(name string, config *types.ContainerRmConfig)
return daemon.rmLink(container, name) return daemon.rmLink(container, name)
} }
err = daemon.cleanupContainer(container, config.ForceRemove) return daemon.cleanupContainer(container, config.ForceRemove, config.RemoveVolume)
if err == nil || config.ForceRemove {
if e := daemon.removeMountPoints(container, config.RemoveVolume); e != nil {
logrus.Error(e)
}
}
return err
} }
func (daemon *Daemon) rmLink(container *container.Container, name string) error { func (daemon *Daemon) rmLink(container *container.Container, name string) error {
@ -77,7 +70,7 @@ func (daemon *Daemon) rmLink(container *container.Container, name string) error
// cleanupContainer unregisters a container from the daemon, stops stats // cleanupContainer unregisters a container from the daemon, stops stats
// collection and cleanly removes contents and metadata from the filesystem. // collection and cleanly removes contents and metadata from the filesystem.
func (daemon *Daemon) cleanupContainer(container *container.Container, forceRemove bool) (err error) { func (daemon *Daemon) cleanupContainer(container *container.Container, forceRemove, removeVolume bool) (err error) {
if container.IsRunning() { if container.IsRunning() {
if !forceRemove { if !forceRemove {
err := fmt.Errorf("You cannot remove a running container %s. Stop the container before attempting removal or use -f", container.ID) err := fmt.Errorf("You cannot remove a running container %s. Stop the container before attempting removal or use -f", container.ID)
@ -115,6 +108,9 @@ func (daemon *Daemon) cleanupContainer(container *container.Container, forceRemo
selinuxFreeLxcContexts(container.ProcessLabel) selinuxFreeLxcContexts(container.ProcessLabel)
daemon.idIndex.Delete(container.ID) daemon.idIndex.Delete(container.ID)
daemon.containers.Delete(container.ID) daemon.containers.Delete(container.ID)
if e := daemon.removeMountPoints(container, removeVolume); e != nil {
logrus.Error(e)
}
daemon.LogContainerEvent(container, "destroy") daemon.LogContainerEvent(container, "destroy")
} }
}() }()