Forráskód Böngészése

Remove duplicated lazy volume initialization.

Signed-off-by: David Calavera <david.calavera@gmail.com>
David Calavera 9 éve
szülő
commit
aab3596397
5 módosított fájl, 31 hozzáadás és 14 törlés
  1. 4 0
      daemon/daemon.go
  2. 9 0
      daemon/mounts.go
  3. 14 0
      daemon/volumes.go
  4. 2 7
      daemon/volumes_unix.go
  5. 2 7
      daemon/volumes_windows.go

+ 4 - 0
daemon/daemon.go

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

+ 9 - 0
daemon/mounts.go

@@ -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 {

+ 14 - 0
daemon/volumes.go

@@ -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
+}

+ 2 - 7
daemon/volumes_unix.go

@@ -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 {

+ 2 - 7
daemon/volumes_windows.go

@@ -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