Browse code

Merge pull request #31047 from yallop/cli-v-state

Flags for specifying bind mount consistency

Sebastiaan van Stijn authored on 2017/03/13 19:36:10
Showing 3 changed files
... ...
@@ -23,9 +23,10 @@ type Mount struct {
23 23
 	// Source specifies the name of the mount. Depending on mount type, this
24 24
 	// may be a volume name or a host path, or even ignored.
25 25
 	// Source is not supported for tmpfs (must be an empty value)
26
-	Source   string `json:",omitempty"`
27
-	Target   string `json:",omitempty"`
28
-	ReadOnly bool   `json:",omitempty"`
26
+	Source      string      `json:",omitempty"`
27
+	Target      string      `json:",omitempty"`
28
+	ReadOnly    bool        `json:",omitempty"`
29
+	Consistency Consistency `json:",omitempty"`
29 30
 
30 31
 	BindOptions   *BindOptions   `json:",omitempty"`
31 32
 	VolumeOptions *VolumeOptions `json:",omitempty"`
... ...
@@ -60,6 +61,20 @@ var Propagations = []Propagation{
60 60
 	PropagationSlave,
61 61
 }
62 62
 
63
+// Consistency represents the consistency requirements of a mount.
64
+type Consistency string
65
+
66
+const (
67
+	// ConsistencyFull guarantees bind-mount-like consistency
68
+	ConsistencyFull Consistency = "consistent"
69
+	// ConsistencyCached mounts can cache read data and FS structure
70
+	ConsistencyCached Consistency = "cached"
71
+	// ConsistencyDelegated mounts can cache read and written data and structure
72
+	ConsistencyDelegated Consistency = "delegated"
73
+	// ConsistencyDefault provides "consistent" behavior unless overridden
74
+	ConsistencyDefault Consistency = "default"
75
+)
76
+
63 77
 // BindOptions defines options specific to mounts of type "bind".
64 78
 type BindOptions struct {
65 79
 	Propagation Propagation `json:",omitempty"`
... ...
@@ -95,6 +95,8 @@ func (m *MountOpt) Set(value string) error {
95 95
 			if err != nil {
96 96
 				return fmt.Errorf("invalid value for %s: %s", key, value)
97 97
 			}
98
+		case "consistency":
99
+			mount.Consistency = mounttypes.Consistency(strings.ToLower(value))
98 100
 		case "bind-propagation":
99 101
 			bindOptions().Propagation = mounttypes.Propagation(strings.ToLower(value))
100 102
 		case "volume-nocopy":
... ...
@@ -30,6 +30,13 @@ var labelModes = map[string]bool{
30 30
 	"z": true,
31 31
 }
32 32
 
33
+// consistency modes
34
+var consistencyModes = map[mounttypes.Consistency]bool{
35
+	mounttypes.ConsistencyFull:      true,
36
+	mounttypes.ConsistencyCached:    true,
37
+	mounttypes.ConsistencyDelegated: true,
38
+}
39
+
33 40
 // BackwardsCompatible decides whether this mount point can be
34 41
 // used in old versions of Docker or not.
35 42
 // Only bind mounts and local volumes can be used in old versions of Docker.
... ...
@@ -62,6 +69,7 @@ func ValidMountMode(mode string) bool {
62 62
 	labelModeCount := 0
63 63
 	propagationModeCount := 0
64 64
 	copyModeCount := 0
65
+	consistencyModeCount := 0
65 66
 
66 67
 	for _, o := range strings.Split(mode, ",") {
67 68
 		switch {
... ...
@@ -73,13 +81,15 @@ func ValidMountMode(mode string) bool {
73 73
 			propagationModeCount++
74 74
 		case copyModeExists(o):
75 75
 			copyModeCount++
76
+		case consistencyModes[mounttypes.Consistency(o)]:
77
+			consistencyModeCount++
76 78
 		default:
77 79
 			return false
78 80
 		}
79 81
 	}
80 82
 
81 83
 	// Only one string for each mode is allowed.
82
-	if rwModeCount > 1 || labelModeCount > 1 || propagationModeCount > 1 || copyModeCount > 1 {
84
+	if rwModeCount > 1 || labelModeCount > 1 || propagationModeCount > 1 || copyModeCount > 1 || consistencyModeCount > 1 {
83 85
 		return false
84 86
 	}
85 87
 	return true