sharedsubtree_linux.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package mount // import "github.com/docker/docker/pkg/mount"
  2. // MakeShared ensures a mounted filesystem has the SHARED mount option enabled.
  3. // See the supported options in flags.go for further reference.
  4. func MakeShared(mountPoint string) error {
  5. return ensureMountedAs(mountPoint, "shared")
  6. }
  7. // MakeRShared ensures a mounted filesystem has the RSHARED mount option enabled.
  8. // See the supported options in flags.go for further reference.
  9. func MakeRShared(mountPoint string) error {
  10. return ensureMountedAs(mountPoint, "rshared")
  11. }
  12. // MakePrivate ensures a mounted filesystem has the PRIVATE mount option enabled.
  13. // See the supported options in flags.go for further reference.
  14. func MakePrivate(mountPoint string) error {
  15. return ensureMountedAs(mountPoint, "private")
  16. }
  17. // MakeRPrivate ensures a mounted filesystem has the RPRIVATE mount option
  18. // enabled. See the supported options in flags.go for further reference.
  19. func MakeRPrivate(mountPoint string) error {
  20. return ensureMountedAs(mountPoint, "rprivate")
  21. }
  22. // MakeSlave ensures a mounted filesystem has the SLAVE mount option enabled.
  23. // See the supported options in flags.go for further reference.
  24. func MakeSlave(mountPoint string) error {
  25. return ensureMountedAs(mountPoint, "slave")
  26. }
  27. // MakeRSlave ensures a mounted filesystem has the RSLAVE mount option enabled.
  28. // See the supported options in flags.go for further reference.
  29. func MakeRSlave(mountPoint string) error {
  30. return ensureMountedAs(mountPoint, "rslave")
  31. }
  32. // MakeUnbindable ensures a mounted filesystem has the UNBINDABLE mount option
  33. // enabled. See the supported options in flags.go for further reference.
  34. func MakeUnbindable(mountPoint string) error {
  35. return ensureMountedAs(mountPoint, "unbindable")
  36. }
  37. // MakeRUnbindable ensures a mounted filesystem has the RUNBINDABLE mount
  38. // option enabled. See the supported options in flags.go for further reference.
  39. func MakeRUnbindable(mountPoint string) error {
  40. return ensureMountedAs(mountPoint, "runbindable")
  41. }
  42. // MakeMount ensures that the file or directory given is a mount point,
  43. // bind mounting it to itself it case it is not.
  44. func MakeMount(mnt string) error {
  45. mounted, err := Mounted(mnt)
  46. if err != nil {
  47. return err
  48. }
  49. if mounted {
  50. return nil
  51. }
  52. return Mount(mnt, mnt, "none", "bind")
  53. }
  54. func ensureMountedAs(mountPoint, options string) error {
  55. if err := MakeMount(mountPoint); err != nil {
  56. return err
  57. }
  58. return ForceMount("", mountPoint, "none", options)
  59. }