Remove duplicated lazy volume initialization.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
2aa673aed7
commit
aab3596397
5 changed files with 31 additions and 14 deletions
|
@ -283,6 +283,10 @@ func (daemon *Daemon) Register(container *container.Container) error {
|
|||
}
|
||||
}
|
||||
|
||||
if err := daemon.prepareMountPoints(container); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue