volume_propagation_linux.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // +build linux
  2. package volume
  3. import (
  4. "strings"
  5. mounttypes "github.com/docker/docker/api/types/mount"
  6. )
  7. // DefaultPropagationMode defines what propagation mode should be used by
  8. // default if user has not specified one explicitly.
  9. // propagation modes
  10. const DefaultPropagationMode = mounttypes.PropagationRPrivate
  11. var propagationModes = map[mounttypes.Propagation]bool{
  12. mounttypes.PropagationPrivate: true,
  13. mounttypes.PropagationRPrivate: true,
  14. mounttypes.PropagationSlave: true,
  15. mounttypes.PropagationRSlave: true,
  16. mounttypes.PropagationShared: true,
  17. mounttypes.PropagationRShared: true,
  18. }
  19. // GetPropagation extracts and returns the mount propagation mode. If there
  20. // are no specifications, then by default it is "private".
  21. func GetPropagation(mode string) mounttypes.Propagation {
  22. for _, o := range strings.Split(mode, ",") {
  23. prop := mounttypes.Propagation(o)
  24. if propagationModes[prop] {
  25. return prop
  26. }
  27. }
  28. return DefaultPropagationMode
  29. }
  30. // HasPropagation checks if there is a valid propagation mode present in
  31. // passed string. Returns true if a valid propagation mode specifier is
  32. // present, false otherwise.
  33. func HasPropagation(mode string) bool {
  34. for _, o := range strings.Split(mode, ",") {
  35. if propagationModes[mounttypes.Propagation(o)] {
  36. return true
  37. }
  38. }
  39. return false
  40. }