Merge pull request #19273 from calavera/volume-lazy-init

[Carry 18549] Lazy initialize Volume on container Mount object.
Upstream-commit: 184040bdd55c3930123ad4984dd976181b26cae8
Component: engine
This commit is contained in:
Brian Goff
2016-01-13 14:15:17 -05:00
4 changed files with 22 additions and 7 deletions

View File

@ -10,13 +10,8 @@ import (
func (daemon *Daemon) prepareMountPoints(container *container.Container) error {
for _, config := range container.MountPoints {
if len(config.Driver) > 0 {
v, err := daemon.volumes.GetWithRef(config.Name, config.Driver, container.ID)
if err != nil {
return err
}
config.Volume = v
if err := daemon.lazyInitializeVolume(container.ID, config); err != nil {
return err
}
}
return nil

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,6 +20,9 @@ import (
func (daemon *Daemon) setupMounts(container *container.Container) ([]execdriver.Mount, error) {
var mounts []execdriver.Mount
for _, m := range container.MountPoints {
if err := daemon.lazyInitializeVolume(container.ID, m); err != nil {
return nil, err
}
path, err := m.Setup()
if err != nil {
return nil, err

View File

@ -18,6 +18,9 @@ import (
func (daemon *Daemon) setupMounts(container *container.Container) ([]execdriver.Mount, error) {
var mnts []execdriver.Mount
for _, mount := range container.MountPoints { // type is volume.MountPoint
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
if s == "" && mount.Volume != nil {