1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #38992 from kolyshkin/mnt

pkg/mount: optimizations
This commit is contained in:
Sebastiaan van Stijn 2019-05-20 14:12:42 +02:00 committed by GitHub
commit 19008faf03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 27 deletions

View file

@ -1,5 +0,0 @@
// +build linux freebsd
package daemon // import "github.com/docker/docker/daemon"
const bindMountType = "bind"

View file

@ -141,10 +141,6 @@ func (daemon *Daemon) mountVolumes(container *container.Container) error {
if m.Writable { if m.Writable {
writeMode = "rw" writeMode = "rw"
} }
opts := strings.Join([]string{bindMode, writeMode}, ",")
if err := mount.Mount(m.Source, dest, bindMountType, opts); err != nil {
return err
}
// mountVolumes() seems to be called for temporary mounts // mountVolumes() seems to be called for temporary mounts
// outside the container. Soon these will be unmounted with // outside the container. Soon these will be unmounted with
@ -154,8 +150,9 @@ func (daemon *Daemon) mountVolumes(container *container.Container) error {
// then these unmounts will propagate and unmount original // then these unmounts will propagate and unmount original
// mount as well. So make all these mounts rprivate. // mount as well. So make all these mounts rprivate.
// Do not use propagation property of volume as that should // Do not use propagation property of volume as that should
// apply only when mounting happen inside the container. // apply only when mounting happens inside the container.
if err := mount.MakeRPrivate(dest); err != nil { opts := strings.Join([]string{bindMode, writeMode, "rprivate"}, ",")
if err := mount.Mount(m.Source, dest, "", opts); err != nil {
return err return err
} }
} }

View file

@ -2092,8 +2092,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) {
assert.NilError(c, err) assert.NilError(c, err)
defer os.RemoveAll(tmpDir3) defer os.RemoveAll(tmpDir3)
c.Assert(mount.Mount(tmpDir3, tmpDir3, "none", "bind,rw"), checker.IsNil) c.Assert(mount.Mount(tmpDir3, tmpDir3, "none", "bind,shared"), checker.IsNil)
c.Assert(mount.ForceMount("", tmpDir3, "none", "shared"), checker.IsNil)
cases = append(cases, []testCase{ cases = append(cases, []testCase{
{ {

View file

@ -102,13 +102,13 @@ func Mounted(mountpoint string) (bool, error) {
// specified like the mount or fstab unix commands: "opt1=val1,opt2=val2". See // specified like the mount or fstab unix commands: "opt1=val1,opt2=val2". See
// flags.go for supported option flags. // flags.go for supported option flags.
func Mount(device, target, mType, options string) error { func Mount(device, target, mType, options string) error {
flag, _ := parseOptions(options) flag, data := parseOptions(options)
if flag&REMOUNT != REMOUNT { if flag&REMOUNT != REMOUNT {
if mounted, err := Mounted(target); err != nil || mounted { if mounted, err := Mounted(target); err != nil || mounted {
return err return err
} }
} }
return ForceMount(device, target, mType, options) return mount(device, target, mType, uintptr(flag), data)
} }
// ForceMount will mount a filesystem according to the specified configuration, // ForceMount will mount a filesystem according to the specified configuration,

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 Mount(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), "")
} }