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 09:29:33 -04: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 {
|
|
|
|
return ensureMountedAs(mountPoint, "shared")
|
|
|
|
}
|
|
|
|
|
2015-03-28 09:29:33 -04: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 {
|
|
|
|
return ensureMountedAs(mountPoint, "rshared")
|
|
|
|
}
|
|
|
|
|
2015-03-28 09:29:33 -04: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 {
|
2014-10-31 10:18:41 -04:00
|
|
|
return ensureMountedAs(mountPoint, "private")
|
|
|
|
}
|
|
|
|
|
2015-03-28 09:29:33 -04: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 {
|
|
|
|
return ensureMountedAs(mountPoint, "rprivate")
|
|
|
|
}
|
|
|
|
|
2015-03-28 09:29:33 -04: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 {
|
|
|
|
return ensureMountedAs(mountPoint, "slave")
|
|
|
|
}
|
|
|
|
|
2015-03-28 09:29:33 -04: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 {
|
|
|
|
return ensureMountedAs(mountPoint, "rslave")
|
|
|
|
}
|
|
|
|
|
2015-03-28 09:29:33 -04: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 {
|
|
|
|
return ensureMountedAs(mountPoint, "unbindable")
|
|
|
|
}
|
|
|
|
|
2015-03-28 09:29:33 -04: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 {
|
|
|
|
return ensureMountedAs(mountPoint, "runbindable")
|
|
|
|
}
|
|
|
|
|
2018-10-12 02:22:11 -04: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-12 02:22:11 -04:00
|
|
|
if mounted {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return Mount(mnt, mnt, "none", "bind")
|
|
|
|
}
|
2014-10-30 17:04:56 -04:00
|
|
|
|
2018-10-12 02:22:11 -04:00
|
|
|
func ensureMountedAs(mountPoint, options string) error {
|
|
|
|
if err := MakeMount(mountPoint); err != nil {
|
|
|
|
return err
|
2014-10-30 17:04:56 -04:00
|
|
|
}
|
|
|
|
|
2014-10-31 10:18:41 -04:00
|
|
|
return ForceMount("", mountPoint, "none", options)
|
2014-10-30 17:04:56 -04:00
|
|
|
}
|