From f13297c0beaf4fcc6742a9f3c047cbfeef955ac1 Mon Sep 17 00:00:00 2001 From: David Sheets Date: Tue, 7 Feb 2017 12:17:21 +0000 Subject: [PATCH] Add 'consistent', 'cached', and 'delegated' mode flags This adds 'consistency' mode flags to the mount command line argument. Initially, the valid 'consistency' flags are 'consistent', 'cached', 'delegated', and 'default'. Signed-off-by: David Sheets Signed-off-by: Jeremy Yallop --- api/types/mount/mount.go | 21 ++++++++++++++++++--- opts/mount.go | 2 ++ volume/volume_unix.go | 12 +++++++++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/api/types/mount/mount.go b/api/types/mount/mount.go index 8ee16711ed..2744f85d6d 100644 --- a/api/types/mount/mount.go +++ b/api/types/mount/mount.go @@ -23,9 +23,10 @@ type Mount struct { // Source specifies the name of the mount. Depending on mount type, this // may be a volume name or a host path, or even ignored. // Source is not supported for tmpfs (must be an empty value) - Source string `json:",omitempty"` - Target string `json:",omitempty"` - ReadOnly bool `json:",omitempty"` + Source string `json:",omitempty"` + Target string `json:",omitempty"` + ReadOnly bool `json:",omitempty"` + Consistency Consistency `json:",omitempty"` BindOptions *BindOptions `json:",omitempty"` VolumeOptions *VolumeOptions `json:",omitempty"` @@ -60,6 +61,20 @@ var Propagations = []Propagation{ PropagationSlave, } +// Consistency represents the consistency requirements of a mount. +type Consistency string + +const ( + // ConsistencyFull guarantees bind-mount-like consistency + ConsistencyFull Consistency = "consistent" + // ConsistencyCached mounts can cache read data and FS structure + ConsistencyCached Consistency = "cached" + // ConsistencyDelegated mounts can cache read and written data and structure + ConsistencyDelegated Consistency = "delegated" + // ConsistencyDefault provides "consistent" behavior unless overridden + ConsistencyDefault Consistency = "default" +) + // BindOptions defines options specific to mounts of type "bind". type BindOptions struct { Propagation Propagation `json:",omitempty"` diff --git a/opts/mount.go b/opts/mount.go index ce6383ddca..97895a7844 100644 --- a/opts/mount.go +++ b/opts/mount.go @@ -95,6 +95,8 @@ func (m *MountOpt) Set(value string) error { if err != nil { return fmt.Errorf("invalid value for %s: %s", key, value) } + case "consistency": + mount.Consistency = mounttypes.Consistency(strings.ToLower(value)) case "bind-propagation": bindOptions().Propagation = mounttypes.Propagation(strings.ToLower(value)) case "volume-nocopy": diff --git a/volume/volume_unix.go b/volume/volume_unix.go index 0256ebb2ba..e35b70c03b 100644 --- a/volume/volume_unix.go +++ b/volume/volume_unix.go @@ -30,6 +30,13 @@ var labelModes = map[string]bool{ "z": true, } +// consistency modes +var consistencyModes = map[mounttypes.Consistency]bool{ + mounttypes.ConsistencyFull: true, + mounttypes.ConsistencyCached: true, + mounttypes.ConsistencyDelegated: true, +} + // BackwardsCompatible decides whether this mount point can be // used in old versions of Docker or not. // Only bind mounts and local volumes can be used in old versions of Docker. @@ -62,6 +69,7 @@ func ValidMountMode(mode string) bool { labelModeCount := 0 propagationModeCount := 0 copyModeCount := 0 + consistencyModeCount := 0 for _, o := range strings.Split(mode, ",") { switch { @@ -73,13 +81,15 @@ func ValidMountMode(mode string) bool { propagationModeCount++ case copyModeExists(o): copyModeCount++ + case consistencyModes[mounttypes.Consistency(o)]: + consistencyModeCount++ default: return false } } // Only one string for each mode is allowed. - if rwModeCount > 1 || labelModeCount > 1 || propagationModeCount > 1 || copyModeCount > 1 { + if rwModeCount > 1 || labelModeCount > 1 || propagationModeCount > 1 || copyModeCount > 1 || consistencyModeCount > 1 { return false } return true