Signed-off-by: David Calavera <david.calavera@gmail.com>
| ... | ... |
@@ -8,6 +8,15 @@ import ( |
| 8 | 8 |
volumestore "github.com/docker/docker/volume/store" |
| 9 | 9 |
) |
| 10 | 10 |
|
| 11 |
+func (daemon *Daemon) prepareMountPoints(container *container.Container) error {
|
|
| 12 |
+ for _, config := range container.MountPoints {
|
|
| 13 |
+ if err := daemon.lazyInitializeVolume(container.ID, config); err != nil {
|
|
| 14 |
+ return err |
|
| 15 |
+ } |
|
| 16 |
+ } |
|
| 17 |
+ return nil |
|
| 18 |
+} |
|
| 19 |
+ |
|
| 11 | 20 |
func (daemon *Daemon) removeMountPoints(container *container.Container, rm bool) error {
|
| 12 | 21 |
var rmErrors []string |
| 13 | 22 |
for _, m := range container.MountPoints {
|
| ... | ... |
@@ -153,3 +153,17 @@ func (daemon *Daemon) registerMountPoints(container *container.Container, hostCo |
| 153 | 153 |
|
| 154 | 154 |
return nil |
| 155 | 155 |
} |
| 156 |
+ |
|
| 157 |
+// lazyInitializeVolume initializes a mountpoint's volume if needed. |
|
| 158 |
+// This happens after a daemon restart. |
|
| 159 |
+func (daemon *Daemon) lazyInitializeVolume(containerID string, m *volume.MountPoint) error {
|
|
| 160 |
+ if len(m.Driver) > 0 && m.Volume == nil {
|
|
| 161 |
+ v, err := daemon.volumes.GetWithRef(m.Name, m.Driver, containerID) |
|
| 162 |
+ |
|
| 163 |
+ if err != nil {
|
|
| 164 |
+ return err |
|
| 165 |
+ } |
|
| 166 |
+ m.Volume = v |
|
| 167 |
+ } |
|
| 168 |
+ return nil |
|
| 169 |
+} |
| ... | ... |
@@ -20,13 +20,8 @@ import ( |
| 20 | 20 |
func (daemon *Daemon) setupMounts(container *container.Container) ([]execdriver.Mount, error) {
|
| 21 | 21 |
var mounts []execdriver.Mount |
| 22 | 22 |
for _, m := range container.MountPoints {
|
| 23 |
- // Lazy initialize m.Volume if needed. This happens after a daemon restart |
|
| 24 |
- if len(m.Driver) > 0 && m.Volume == nil {
|
|
| 25 |
- v, err := daemon.createVolume(m.Name, m.Driver, nil) |
|
| 26 |
- if err != nil {
|
|
| 27 |
- return nil, err |
|
| 28 |
- } |
|
| 29 |
- m.Volume = v |
|
| 23 |
+ if err := daemon.lazyInitializeVolume(container.ID, m); err != nil {
|
|
| 24 |
+ return nil, err |
|
| 30 | 25 |
} |
| 31 | 26 |
path, err := m.Setup() |
| 32 | 27 |
if err != nil {
|
| ... | ... |
@@ -18,13 +18,8 @@ import ( |
| 18 | 18 |
func (daemon *Daemon) setupMounts(container *container.Container) ([]execdriver.Mount, error) {
|
| 19 | 19 |
var mnts []execdriver.Mount |
| 20 | 20 |
for _, mount := range container.MountPoints { // type is volume.MountPoint
|
| 21 |
- // Lazy initialize m.Volume if needed. This happens after a daemon restart |
|
| 22 |
- if len(m.Driver) > 0 && m.Volume == nil {
|
|
| 23 |
- v, err := daemon.createVolume(m.Name, m.Driver, nil) |
|
| 24 |
- if err != nil {
|
|
| 25 |
- return nil, err |
|
| 26 |
- } |
|
| 27 |
- m.Volume = v |
|
| 21 |
+ if err := daemon.lazyInitializeVolume(container.ID, mount); err != nil {
|
|
| 22 |
+ return nil, err |
|
| 28 | 23 |
} |
| 29 | 24 |
// If there is no source, take it from the volume path |
| 30 | 25 |
s := mount.Source |