mount.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package mount
  2. import (
  3. "os"
  4. )
  5. // Type represents the type of a mount.
  6. type Type string
  7. // Type constants
  8. const (
  9. // TypeBind is the type for mounting host dir
  10. TypeBind Type = "bind"
  11. // TypeVolume is the type for remote storage volumes
  12. TypeVolume Type = "volume"
  13. // TypeTmpfs is the type for mounting tmpfs
  14. TypeTmpfs Type = "tmpfs"
  15. // TypeNamedPipe is the type for mounting Windows named pipes
  16. TypeNamedPipe Type = "npipe"
  17. )
  18. // Mount represents a mount (volume).
  19. type Mount struct {
  20. Type Type `json:",omitempty"`
  21. // Source specifies the name of the mount. Depending on mount type, this
  22. // may be a volume name or a host path, or even ignored.
  23. // Source is not supported for tmpfs (must be an empty value)
  24. Source string `json:",omitempty"`
  25. Target string `json:",omitempty"`
  26. ReadOnly bool `json:",omitempty"`
  27. Consistency Consistency `json:",omitempty"`
  28. BindOptions *BindOptions `json:",omitempty"`
  29. VolumeOptions *VolumeOptions `json:",omitempty"`
  30. TmpfsOptions *TmpfsOptions `json:",omitempty"`
  31. }
  32. // Propagation represents the propagation of a mount.
  33. type Propagation string
  34. const (
  35. // PropagationRPrivate RPRIVATE
  36. PropagationRPrivate Propagation = "rprivate"
  37. // PropagationPrivate PRIVATE
  38. PropagationPrivate Propagation = "private"
  39. // PropagationRShared RSHARED
  40. PropagationRShared Propagation = "rshared"
  41. // PropagationShared SHARED
  42. PropagationShared Propagation = "shared"
  43. // PropagationRSlave RSLAVE
  44. PropagationRSlave Propagation = "rslave"
  45. // PropagationSlave SLAVE
  46. PropagationSlave Propagation = "slave"
  47. )
  48. // Propagations is the list of all valid mount propagations
  49. var Propagations = []Propagation{
  50. PropagationRPrivate,
  51. PropagationPrivate,
  52. PropagationRShared,
  53. PropagationShared,
  54. PropagationRSlave,
  55. PropagationSlave,
  56. }
  57. // Consistency represents the consistency requirements of a mount.
  58. type Consistency string
  59. const (
  60. // ConsistencyFull guarantees bind mount-like consistency
  61. ConsistencyFull Consistency = "consistent"
  62. // ConsistencyCached mounts can cache read data and FS structure
  63. ConsistencyCached Consistency = "cached"
  64. // ConsistencyDelegated mounts can cache read and written data and structure
  65. ConsistencyDelegated Consistency = "delegated"
  66. // ConsistencyDefault provides "consistent" behavior unless overridden
  67. ConsistencyDefault Consistency = "default"
  68. )
  69. // BindOptions defines options specific to mounts of type "bind".
  70. type BindOptions struct {
  71. Propagation Propagation `json:",omitempty"`
  72. }
  73. // VolumeOptions represents the options for a mount of type volume.
  74. type VolumeOptions struct {
  75. NoCopy bool `json:",omitempty"`
  76. Labels map[string]string `json:",omitempty"`
  77. DriverConfig *Driver `json:",omitempty"`
  78. }
  79. // Driver represents a volume driver.
  80. type Driver struct {
  81. Name string `json:",omitempty"`
  82. Options map[string]string `json:",omitempty"`
  83. }
  84. // TmpfsOptions defines options specific to mounts of type "tmpfs".
  85. type TmpfsOptions struct {
  86. // Size sets the size of the tmpfs, in bytes.
  87. //
  88. // This will be converted to an operating system specific value
  89. // depending on the host. For example, on linux, it will be converted to
  90. // use a 'k', 'm' or 'g' syntax. BSD, though not widely supported with
  91. // docker, uses a straight byte value.
  92. //
  93. // Percentages are not supported.
  94. SizeBytes int64 `json:",omitempty"`
  95. // Mode of the tmpfs upon creation
  96. Mode os.FileMode `json:",omitempty"`
  97. // TODO(stevvooe): There are several more tmpfs flags, specified in the
  98. // daemon, that are accepted. Only the most basic are added for now.
  99. //
  100. // From docker/docker/pkg/mount/flags.go:
  101. //
  102. // var validFlags = map[string]bool{
  103. // "": true,
  104. // "size": true, X
  105. // "mode": true, X
  106. // "uid": true,
  107. // "gid": true,
  108. // "nr_inodes": true,
  109. // "nr_blocks": true,
  110. // "mpol": true,
  111. // }
  112. //
  113. // Some of these may be straightforward to add, but others, such as
  114. // uid/gid have implications in a clustered system.
  115. }