mount.go 3.8 KB

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