mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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 <dsheets@docker.com> Signed-off-by: Jeremy Yallop <yallop@docker.com>
This commit is contained in:
parent
ce79f6b644
commit
f13297c0be
3 changed files with 31 additions and 4 deletions
|
@ -26,6 +26,7 @@ type Mount struct {
|
||||||
Source string `json:",omitempty"`
|
Source string `json:",omitempty"`
|
||||||
Target string `json:",omitempty"`
|
Target string `json:",omitempty"`
|
||||||
ReadOnly bool `json:",omitempty"`
|
ReadOnly bool `json:",omitempty"`
|
||||||
|
Consistency Consistency `json:",omitempty"`
|
||||||
|
|
||||||
BindOptions *BindOptions `json:",omitempty"`
|
BindOptions *BindOptions `json:",omitempty"`
|
||||||
VolumeOptions *VolumeOptions `json:",omitempty"`
|
VolumeOptions *VolumeOptions `json:",omitempty"`
|
||||||
|
@ -60,6 +61,20 @@ var Propagations = []Propagation{
|
||||||
PropagationSlave,
|
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".
|
// BindOptions defines options specific to mounts of type "bind".
|
||||||
type BindOptions struct {
|
type BindOptions struct {
|
||||||
Propagation Propagation `json:",omitempty"`
|
Propagation Propagation `json:",omitempty"`
|
||||||
|
|
|
@ -95,6 +95,8 @@ func (m *MountOpt) Set(value string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid value for %s: %s", key, value)
|
return fmt.Errorf("invalid value for %s: %s", key, value)
|
||||||
}
|
}
|
||||||
|
case "consistency":
|
||||||
|
mount.Consistency = mounttypes.Consistency(strings.ToLower(value))
|
||||||
case "bind-propagation":
|
case "bind-propagation":
|
||||||
bindOptions().Propagation = mounttypes.Propagation(strings.ToLower(value))
|
bindOptions().Propagation = mounttypes.Propagation(strings.ToLower(value))
|
||||||
case "volume-nocopy":
|
case "volume-nocopy":
|
||||||
|
|
|
@ -30,6 +30,13 @@ var labelModes = map[string]bool{
|
||||||
"z": true,
|
"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
|
// BackwardsCompatible decides whether this mount point can be
|
||||||
// used in old versions of Docker or not.
|
// used in old versions of Docker or not.
|
||||||
// Only bind mounts and local volumes can be used in old versions of Docker.
|
// 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
|
labelModeCount := 0
|
||||||
propagationModeCount := 0
|
propagationModeCount := 0
|
||||||
copyModeCount := 0
|
copyModeCount := 0
|
||||||
|
consistencyModeCount := 0
|
||||||
|
|
||||||
for _, o := range strings.Split(mode, ",") {
|
for _, o := range strings.Split(mode, ",") {
|
||||||
switch {
|
switch {
|
||||||
|
@ -73,13 +81,15 @@ func ValidMountMode(mode string) bool {
|
||||||
propagationModeCount++
|
propagationModeCount++
|
||||||
case copyModeExists(o):
|
case copyModeExists(o):
|
||||||
copyModeCount++
|
copyModeCount++
|
||||||
|
case consistencyModes[mounttypes.Consistency(o)]:
|
||||||
|
consistencyModeCount++
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only one string for each mode is allowed.
|
// 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 false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Add table
Reference in a new issue