2018-02-05 16:05:59 -05:00
|
|
|
package mount // import "github.com/docker/docker/pkg/mount"
|
2014-10-30 17:04:56 -04:00
|
|
|
|
2015-03-28 14:29:33 +01:00
|
|
|
// MakeShared ensures a mounted filesystem has the SHARED mount option enabled.
|
|
|
|
// See the supported options in flags.go for further reference.
|
2014-10-31 10:18:41 -04:00
|
|
|
func MakeShared(mountPoint string) error {
|
2019-04-09 11:25:41 -07:00
|
|
|
return ensureMountedAs(mountPoint, SHARED)
|
2014-10-31 10:18:41 -04:00
|
|
|
}
|
|
|
|
|
2015-03-28 14:29:33 +01:00
|
|
|
// MakeRShared ensures a mounted filesystem has the RSHARED mount option enabled.
|
|
|
|
// See the supported options in flags.go for further reference.
|
2014-10-31 10:18:41 -04:00
|
|
|
func MakeRShared(mountPoint string) error {
|
2019-04-09 11:25:41 -07:00
|
|
|
return ensureMountedAs(mountPoint, RSHARED)
|
2014-10-31 10:18:41 -04:00
|
|
|
}
|
|
|
|
|
2015-03-28 14:29:33 +01:00
|
|
|
// MakePrivate ensures a mounted filesystem has the PRIVATE mount option enabled.
|
|
|
|
// See the supported options in flags.go for further reference.
|
2014-10-30 17:04:56 -04:00
|
|
|
func MakePrivate(mountPoint string) error {
|
2019-04-09 11:25:41 -07:00
|
|
|
return ensureMountedAs(mountPoint, PRIVATE)
|
2014-10-31 10:18:41 -04:00
|
|
|
}
|
|
|
|
|
2015-03-28 14:29:33 +01:00
|
|
|
// MakeRPrivate ensures a mounted filesystem has the RPRIVATE mount option
|
|
|
|
// enabled. See the supported options in flags.go for further reference.
|
2014-10-31 10:18:41 -04:00
|
|
|
func MakeRPrivate(mountPoint string) error {
|
2019-04-09 11:25:41 -07:00
|
|
|
return ensureMountedAs(mountPoint, RPRIVATE)
|
2014-10-31 10:18:41 -04:00
|
|
|
}
|
|
|
|
|
2015-03-28 14:29:33 +01:00
|
|
|
// MakeSlave ensures a mounted filesystem has the SLAVE mount option enabled.
|
|
|
|
// See the supported options in flags.go for further reference.
|
2014-10-31 10:18:41 -04:00
|
|
|
func MakeSlave(mountPoint string) error {
|
2019-04-09 11:25:41 -07:00
|
|
|
return ensureMountedAs(mountPoint, SLAVE)
|
2014-10-31 10:18:41 -04:00
|
|
|
}
|
|
|
|
|
2015-03-28 14:29:33 +01:00
|
|
|
// MakeRSlave ensures a mounted filesystem has the RSLAVE mount option enabled.
|
|
|
|
// See the supported options in flags.go for further reference.
|
2014-10-31 10:18:41 -04:00
|
|
|
func MakeRSlave(mountPoint string) error {
|
2019-04-09 11:25:41 -07:00
|
|
|
return ensureMountedAs(mountPoint, RSLAVE)
|
2014-10-31 10:18:41 -04:00
|
|
|
}
|
|
|
|
|
2015-03-28 14:29:33 +01:00
|
|
|
// MakeUnbindable ensures a mounted filesystem has the UNBINDABLE mount option
|
|
|
|
// enabled. See the supported options in flags.go for further reference.
|
2014-10-31 10:18:41 -04:00
|
|
|
func MakeUnbindable(mountPoint string) error {
|
2019-04-09 11:25:41 -07:00
|
|
|
return ensureMountedAs(mountPoint, UNBINDABLE)
|
2014-10-31 10:18:41 -04:00
|
|
|
}
|
|
|
|
|
2015-03-28 14:29:33 +01:00
|
|
|
// MakeRUnbindable ensures a mounted filesystem has the RUNBINDABLE mount
|
|
|
|
// option enabled. See the supported options in flags.go for further reference.
|
2014-10-31 10:18:41 -04:00
|
|
|
func MakeRUnbindable(mountPoint string) error {
|
2019-04-09 11:25:41 -07:00
|
|
|
return ensureMountedAs(mountPoint, RUNBINDABLE)
|
2014-10-31 10:18:41 -04:00
|
|
|
}
|
|
|
|
|
2018-10-11 23:22:11 -07:00
|
|
|
// MakeMount ensures that the file or directory given is a mount point,
|
|
|
|
// bind mounting it to itself it case it is not.
|
|
|
|
func MakeMount(mnt string) error {
|
|
|
|
mounted, err := Mounted(mnt)
|
2014-10-30 17:04:56 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-10-11 23:22:11 -07:00
|
|
|
if mounted {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-04-09 11:25:41 -07:00
|
|
|
return mount(mnt, mnt, "none", uintptr(BIND), "")
|
2018-10-11 23:22:11 -07:00
|
|
|
}
|
2014-10-30 17:04:56 -04:00
|
|
|
|
2019-04-09 11:25:41 -07:00
|
|
|
func ensureMountedAs(mnt string, flags int) error {
|
|
|
|
if err := MakeMount(mnt); err != nil {
|
2018-10-11 23:22:11 -07:00
|
|
|
return err
|
2014-10-30 17:04:56 -04:00
|
|
|
}
|
|
|
|
|
2019-04-09 11:25:41 -07:00
|
|
|
return mount("", mnt, "none", uintptr(flags), "")
|
2014-10-30 17:04:56 -04:00
|
|
|
}
|