Skip to content

Commit

Permalink
Merge pull request moby#19273 from calavera/volume-lazy-init
Browse files Browse the repository at this point in the history
[Carry 18549] Lazy initialize Volume on container Mount object.
  • Loading branch information
cpuguy83 committed Jan 13, 2016
2 parents 0ee6412 + aab3596 commit 184040b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
9 changes: 2 additions & 7 deletions daemon/mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions daemon/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions daemon/volumes_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions daemon/volumes_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 184040b

Please sign in to comment.