瀏覽代碼

Merge pull request #38992 from kolyshkin/mnt

pkg/mount: optimizations
Sebastiaan van Stijn 6 年之前
父節點
當前提交
19008faf03

+ 0 - 5
daemon/bindmount_unix.go

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

+ 3 - 6
daemon/volumes_unix.go

@@ -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.
-		if err := mount.MakeRPrivate(dest); err != nil {
+		// apply only when mounting happens inside the container.
+		opts := strings.Join([]string{bindMode, writeMode, "rprivate"}, ",")
+		if err := mount.Mount(m.Source, dest, "", opts); err != nil {
 			return err
 			return err
 		}
 		}
 	}
 	}

+ 1 - 2
integration-cli/docker_api_containers_test.go

@@ -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.ForceMount("", tmpDir3, "none", "shared"), checker.IsNil)
+			c.Assert(mount.Mount(tmpDir3, tmpDir3, "none", "bind,shared"), checker.IsNil)
 
 
 			cases = append(cases, []testCase{
 			cases = append(cases, []testCase{
 				{
 				{

+ 2 - 2
pkg/mount/mount.go

@@ -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,

+ 12 - 12
pkg/mount/sharedsubtree_linux.go

@@ -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 {
-	if err := MakeMount(mountPoint); err != nil {
+func ensureMountedAs(mnt string, flags int) error {
+	if err := MakeMount(mnt); err != nil {
 		return err
 		return err
 	}
 	}
 
 
-	return ForceMount("", mountPoint, "none", options)
+	return mount("", mnt, "none", uintptr(flags), "")
 }
 }