Browse code

Move platform specific mount data to Container

The Solaris version (previously daemon/inspect_solaris.go) was
apparently missing some fields that should be available on that
platform.

Signed-off-by: Fabio Kung <fabio.kung@gmail.com>

Fabio Kung authored on 2017/02/23 02:11:10
Showing 6 changed files
... ...
@@ -10,6 +10,7 @@ import (
10 10
 	"strings"
11 11
 
12 12
 	"github.com/Sirupsen/logrus"
13
+	"github.com/docker/docker/api/types"
13 14
 	containertypes "github.com/docker/docker/api/types/container"
14 15
 	mounttypes "github.com/docker/docker/api/types/mount"
15 16
 	"github.com/docker/docker/pkg/chrootarchive"
... ...
@@ -462,3 +463,21 @@ func cleanResourcePath(path string) string {
462 462
 func (container *Container) EnableServiceDiscoveryOnDefaultNetwork() bool {
463 463
 	return false
464 464
 }
465
+
466
+// GetMountPoints gives a platform specific transformation to types.MountPoint. Callers must hold a Container lock.
467
+func (container *Container) GetMountPoints() []types.MountPoint {
468
+	mountPoints := make([]types.MountPoint, 0, len(container.MountPoints))
469
+	for _, m := range container.MountPoints {
470
+		mountPoints = append(mountPoints, types.MountPoint{
471
+			Type:        m.Type,
472
+			Name:        m.Name,
473
+			Source:      m.Path(),
474
+			Destination: m.Destination,
475
+			Driver:      m.Driver,
476
+			Mode:        m.Mode,
477
+			RW:          m.RW,
478
+			Propagation: m.Propagation,
479
+		})
480
+	}
481
+	return mountPoints
482
+}
... ...
@@ -7,6 +7,7 @@ import (
7 7
 	"os"
8 8
 	"path/filepath"
9 9
 
10
+	"github.com/docker/docker/api/types"
10 11
 	containertypes "github.com/docker/docker/api/types/container"
11 12
 	"github.com/docker/docker/pkg/system"
12 13
 )
... ...
@@ -194,3 +195,19 @@ func (container *Container) BuildHostnameFile() error {
194 194
 func (container *Container) EnableServiceDiscoveryOnDefaultNetwork() bool {
195 195
 	return true
196 196
 }
197
+
198
+// GetMountPoints gives a platform specific transformation to types.MountPoint. Callers must hold a Container lock.
199
+func (container *Container) GetMountPoints() []types.MountPoint {
200
+	mountPoints := make([]types.MountPoint, 0, len(container.MountPoints))
201
+	for _, m := range container.MountPoints {
202
+		mountPoints = append(mountPoints, types.MountPoint{
203
+			Type:        m.Type,
204
+			Name:        m.Name,
205
+			Source:      m.Path(),
206
+			Destination: m.Destination,
207
+			Driver:      m.Driver,
208
+			RW:          m.RW,
209
+		})
210
+	}
211
+	return mountPoints
212
+}
... ...
@@ -51,7 +51,7 @@ func (daemon *Daemon) ContainerInspectCurrent(name string, size bool) (*types.Co
51 51
 		}
52 52
 	}
53 53
 
54
-	mountPoints := addMountPoints(container)
54
+	mountPoints := container.GetMountPoints()
55 55
 	networkSettings := &types.NetworkSettings{
56 56
 		NetworkSettingsBase: types.NetworkSettingsBase{
57 57
 			Bridge:                 container.NetworkSettings.Bridge,
... ...
@@ -104,7 +104,7 @@ func (daemon *Daemon) containerInspect120(name string) (*v1p20.ContainerJSON, er
104 104
 		return nil, err
105 105
 	}
106 106
 
107
-	mountPoints := addMountPoints(container)
107
+	mountPoints := container.GetMountPoints()
108 108
 	config := &v1p20.ContainerConfig{
109 109
 		Config:          container.Config,
110 110
 		MacAddress:      container.Config.MacAddress,
... ...
@@ -18,20 +18,6 @@ func (daemon *Daemon) containerInspectPre120(name string) (*v1p19.ContainerJSON,
18 18
 	return &v1p19.ContainerJSON{}, nil
19 19
 }
20 20
 
21
-func addMountPoints(container *container.Container) []types.MountPoint {
22
-	mountPoints := make([]types.MountPoint, 0, len(container.MountPoints))
23
-	for _, m := range container.MountPoints {
24
-		mountPoints = append(mountPoints, types.MountPoint{
25
-			Name:        m.Name,
26
-			Source:      m.Path(),
27
-			Destination: m.Destination,
28
-			Driver:      m.Driver,
29
-			RW:          m.RW,
30
-		})
31
-	}
32
-	return mountPoints
33
-}
34
-
35 21
 func inspectExecProcessConfig(e *exec.Config) *backend.ExecProcessConfig {
36 22
 	return &backend.ExecProcessConfig{
37 23
 		Tty:        e.Tty,
... ...
@@ -64,23 +64,6 @@ func (daemon *Daemon) containerInspectPre120(name string) (*v1p19.ContainerJSON,
64 64
 	}, nil
65 65
 }
66 66
 
67
-func addMountPoints(container *container.Container) []types.MountPoint {
68
-	mountPoints := make([]types.MountPoint, 0, len(container.MountPoints))
69
-	for _, m := range container.MountPoints {
70
-		mountPoints = append(mountPoints, types.MountPoint{
71
-			Type:        m.Type,
72
-			Name:        m.Name,
73
-			Source:      m.Path(),
74
-			Destination: m.Destination,
75
-			Driver:      m.Driver,
76
-			Mode:        m.Mode,
77
-			RW:          m.RW,
78
-			Propagation: m.Propagation,
79
-		})
80
-	}
81
-	return mountPoints
82
-}
83
-
84 67
 func inspectExecProcessConfig(e *exec.Config) *backend.ExecProcessConfig {
85 68
 	return &backend.ExecProcessConfig{
86 69
 		Tty:        e.Tty,
... ...
@@ -12,21 +12,6 @@ func setPlatformSpecificContainerFields(container *container.Container, contJSON
12 12
 	return contJSONBase
13 13
 }
14 14
 
15
-func addMountPoints(container *container.Container) []types.MountPoint {
16
-	mountPoints := make([]types.MountPoint, 0, len(container.MountPoints))
17
-	for _, m := range container.MountPoints {
18
-		mountPoints = append(mountPoints, types.MountPoint{
19
-			Type:        m.Type,
20
-			Name:        m.Name,
21
-			Source:      m.Path(),
22
-			Destination: m.Destination,
23
-			Driver:      m.Driver,
24
-			RW:          m.RW,
25
-		})
26
-	}
27
-	return mountPoints
28
-}
29
-
30 15
 // containerInspectPre120 get containers for pre 1.20 APIs.
31 16
 func (daemon *Daemon) containerInspectPre120(name string) (*types.ContainerJSON, error) {
32 17
 	return daemon.ContainerInspectCurrent(name, false)