Remove duplicated lazy volume initialization.

Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
David Calavera 2016-01-12 17:18:57 -05:00
parent 2aa673aed7
commit aab3596397
5 changed files with 31 additions and 14 deletions

View file

@ -283,6 +283,10 @@ func (daemon *Daemon) Register(container *container.Container) error {
}
}
if err := daemon.prepareMountPoints(container); err != nil {
return err
}
return nil
}

View file

@ -8,6 +8,15 @@ import (
volumestore "github.com/docker/docker/volume/store"
)
func (daemon *Daemon) prepareMountPoints(container *container.Container) error {
for _, config := range container.MountPoints {
if err := daemon.lazyInitializeVolume(container.ID, config); err != nil {
return err
}
}
return nil
}
func (daemon *Daemon) removeMountPoints(container *container.Container, rm bool) error {
var rmErrors []string
for _, m := range container.MountPoints {

View file

@ -153,3 +153,17 @@ func (daemon *Daemon) registerMountPoints(container *container.Container, hostCo
return nil
}
// lazyInitializeVolume initializes a mountpoint's volume if needed.
// This happens after a daemon restart.
func (daemon *Daemon) lazyInitializeVolume(containerID string, m *volume.MountPoint) error {
if len(m.Driver) > 0 && m.Volume == nil {
v, err := daemon.volumes.GetWithRef(m.Name, m.Driver, containerID)
if err != nil {
return err
}
m.Volume = v
}
return nil
}

View file

@ -20,13 +20,8 @@ import (
func (daemon *Daemon) setupMounts(container *container.Container) ([]execdriver.Mount, error) {
var mounts []execdriver.Mount
for _, m := range container.MountPoints {
// Lazy initialize m.Volume if needed. This happens after a daemon restart
if len(m.Driver) > 0 && m.Volume == nil {
v, err := daemon.createVolume(m.Name, m.Driver, nil)
if err != nil {
return nil, err
}
m.Volume = v
if err := daemon.lazyInitializeVolume(container.ID, m); err != nil {
return nil, err
}
path, err := m.Setup()
if err != nil {

View file

@ -18,13 +18,8 @@ import (
func (daemon *Daemon) setupMounts(container *container.Container) ([]execdriver.Mount, error) {
var mnts []execdriver.Mount
for _, mount := range container.MountPoints { // type is volume.MountPoint
// Lazy initialize m.Volume if needed. This happens after a daemon restart
if len(m.Driver) > 0 && m.Volume == nil {
v, err := daemon.createVolume(m.Name, m.Driver, nil)
if err != nil {
return nil, err
}
m.Volume = v
if err := daemon.lazyInitializeVolume(container.ID, mount); err != nil {
return nil, err
}
// If there is no source, take it from the volume path
s := mount.Source