pkg/mount/Make*: optimize

The only option we supply is either BIND or a mount propagation flag,
so it makes sense to specify the flag value directly, rather than using
parseOptions() every time.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2019-04-09 11:25:41 -07:00
parent a6773f69f2
commit ec248fe61d
1 changed files with 12 additions and 12 deletions

View File

@ -3,49 +3,49 @@ package mount // import "github.com/docker/docker/pkg/mount"
// MakeShared ensures a mounted filesystem has the SHARED mount option enabled. // MakeShared ensures a mounted filesystem has the SHARED mount option enabled.
// See the supported options in flags.go for further reference. // See the supported options in flags.go for further reference.
func MakeShared(mountPoint string) error { func MakeShared(mountPoint string) error {
return ensureMountedAs(mountPoint, "shared") return ensureMountedAs(mountPoint, SHARED)
} }
// MakeRShared ensures a mounted filesystem has the RSHARED mount option enabled. // MakeRShared ensures a mounted filesystem has the RSHARED mount option enabled.
// See the supported options in flags.go for further reference. // See the supported options in flags.go for further reference.
func MakeRShared(mountPoint string) error { func MakeRShared(mountPoint string) error {
return ensureMountedAs(mountPoint, "rshared") return ensureMountedAs(mountPoint, RSHARED)
} }
// MakePrivate ensures a mounted filesystem has the PRIVATE mount option enabled. // MakePrivate ensures a mounted filesystem has the PRIVATE mount option enabled.
// See the supported options in flags.go for further reference. // See the supported options in flags.go for further reference.
func MakePrivate(mountPoint string) error { func MakePrivate(mountPoint string) error {
return ensureMountedAs(mountPoint, "private") return ensureMountedAs(mountPoint, PRIVATE)
} }
// MakeRPrivate ensures a mounted filesystem has the RPRIVATE mount option // MakeRPrivate ensures a mounted filesystem has the RPRIVATE mount option
// enabled. See the supported options in flags.go for further reference. // enabled. See the supported options in flags.go for further reference.
func MakeRPrivate(mountPoint string) error { func MakeRPrivate(mountPoint string) error {
return ensureMountedAs(mountPoint, "rprivate") return ensureMountedAs(mountPoint, RPRIVATE)
} }
// MakeSlave ensures a mounted filesystem has the SLAVE mount option enabled. // MakeSlave ensures a mounted filesystem has the SLAVE mount option enabled.
// See the supported options in flags.go for further reference. // See the supported options in flags.go for further reference.
func MakeSlave(mountPoint string) error { func MakeSlave(mountPoint string) error {
return ensureMountedAs(mountPoint, "slave") return ensureMountedAs(mountPoint, SLAVE)
} }
// MakeRSlave ensures a mounted filesystem has the RSLAVE mount option enabled. // MakeRSlave ensures a mounted filesystem has the RSLAVE mount option enabled.
// See the supported options in flags.go for further reference. // See the supported options in flags.go for further reference.
func MakeRSlave(mountPoint string) error { func MakeRSlave(mountPoint string) error {
return ensureMountedAs(mountPoint, "rslave") return ensureMountedAs(mountPoint, RSLAVE)
} }
// MakeUnbindable ensures a mounted filesystem has the UNBINDABLE mount option // MakeUnbindable ensures a mounted filesystem has the UNBINDABLE mount option
// enabled. See the supported options in flags.go for further reference. // enabled. See the supported options in flags.go for further reference.
func MakeUnbindable(mountPoint string) error { func MakeUnbindable(mountPoint string) error {
return ensureMountedAs(mountPoint, "unbindable") return ensureMountedAs(mountPoint, UNBINDABLE)
} }
// MakeRUnbindable ensures a mounted filesystem has the RUNBINDABLE mount // MakeRUnbindable ensures a mounted filesystem has the RUNBINDABLE mount
// option enabled. See the supported options in flags.go for further reference. // option enabled. See the supported options in flags.go for further reference.
func MakeRUnbindable(mountPoint string) error { func MakeRUnbindable(mountPoint string) error {
return ensureMountedAs(mountPoint, "runbindable") return ensureMountedAs(mountPoint, RUNBINDABLE)
} }
// MakeMount ensures that the file or directory given is a mount point, // MakeMount ensures that the file or directory given is a mount point,
@ -59,13 +59,13 @@ func MakeMount(mnt string) error {
return nil return nil
} }
return ForceMount(mnt, mnt, "none", "bind") return mount(mnt, mnt, "none", uintptr(BIND), "")
} }
func ensureMountedAs(mountPoint, options string) error { func ensureMountedAs(mnt string, flags int) error {
if err := MakeMount(mountPoint); err != nil { if err := MakeMount(mnt); err != nil {
return err return err
} }
return ForceMount("", mountPoint, "none", options) return mount("", mnt, "none", uintptr(flags), "")
} }