Browse code

Merge pull request #38992 from kolyshkin/mnt

pkg/mount: optimizations

Sebastiaan van Stijn authored on 2019/05/20 21:12:42
Showing 5 changed files
1 1
deleted file mode 100644
... ...
@@ -1,5 +0,0 @@
1
-// +build linux freebsd
2
-
3
-package daemon // import "github.com/docker/docker/daemon"
4
-
5
-const bindMountType = "bind"
... ...
@@ -141,10 +141,6 @@ func (daemon *Daemon) mountVolumes(container *container.Container) error {
141 141
 		if m.Writable {
142 142
 			writeMode = "rw"
143 143
 		}
144
-		opts := strings.Join([]string{bindMode, writeMode}, ",")
145
-		if err := mount.Mount(m.Source, dest, bindMountType, opts); err != nil {
146
-			return err
147
-		}
148 144
 
149 145
 		// mountVolumes() seems to be called for temporary mounts
150 146
 		// outside the container. Soon these will be unmounted with
... ...
@@ -154,8 +150,9 @@ func (daemon *Daemon) mountVolumes(container *container.Container) error {
154 154
 		// then these unmounts will propagate and unmount original
155 155
 		// mount as well. So make all these mounts rprivate.
156 156
 		// Do not use propagation property of volume as that should
157
-		// apply only when mounting happen inside the container.
158
-		if err := mount.MakeRPrivate(dest); err != nil {
157
+		// apply only when mounting happens inside the container.
158
+		opts := strings.Join([]string{bindMode, writeMode, "rprivate"}, ",")
159
+		if err := mount.Mount(m.Source, dest, "", opts); err != nil {
159 160
 			return err
160 161
 		}
161 162
 	}
... ...
@@ -2092,8 +2092,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) {
2092 2092
 			assert.NilError(c, err)
2093 2093
 			defer os.RemoveAll(tmpDir3)
2094 2094
 
2095
-			c.Assert(mount.Mount(tmpDir3, tmpDir3, "none", "bind,rw"), checker.IsNil)
2096
-			c.Assert(mount.ForceMount("", tmpDir3, "none", "shared"), checker.IsNil)
2095
+			c.Assert(mount.Mount(tmpDir3, tmpDir3, "none", "bind,shared"), checker.IsNil)
2097 2096
 
2098 2097
 			cases = append(cases, []testCase{
2099 2098
 				{
... ...
@@ -102,13 +102,13 @@ func Mounted(mountpoint string) (bool, error) {
102 102
 // specified like the mount or fstab unix commands: "opt1=val1,opt2=val2". See
103 103
 // flags.go for supported option flags.
104 104
 func Mount(device, target, mType, options string) error {
105
-	flag, _ := parseOptions(options)
105
+	flag, data := parseOptions(options)
106 106
 	if flag&REMOUNT != REMOUNT {
107 107
 		if mounted, err := Mounted(target); err != nil || mounted {
108 108
 			return err
109 109
 		}
110 110
 	}
111
-	return ForceMount(device, target, mType, options)
111
+	return mount(device, target, mType, uintptr(flag), data)
112 112
 }
113 113
 
114 114
 // ForceMount will mount a filesystem according to the specified configuration,
... ...
@@ -3,49 +3,49 @@ package mount // import "github.com/docker/docker/pkg/mount"
3 3
 // MakeShared ensures a mounted filesystem has the SHARED mount option enabled.
4 4
 // See the supported options in flags.go for further reference.
5 5
 func MakeShared(mountPoint string) error {
6
-	return ensureMountedAs(mountPoint, "shared")
6
+	return ensureMountedAs(mountPoint, SHARED)
7 7
 }
8 8
 
9 9
 // MakeRShared ensures a mounted filesystem has the RSHARED mount option enabled.
10 10
 // See the supported options in flags.go for further reference.
11 11
 func MakeRShared(mountPoint string) error {
12
-	return ensureMountedAs(mountPoint, "rshared")
12
+	return ensureMountedAs(mountPoint, RSHARED)
13 13
 }
14 14
 
15 15
 // MakePrivate ensures a mounted filesystem has the PRIVATE mount option enabled.
16 16
 // See the supported options in flags.go for further reference.
17 17
 func MakePrivate(mountPoint string) error {
18
-	return ensureMountedAs(mountPoint, "private")
18
+	return ensureMountedAs(mountPoint, PRIVATE)
19 19
 }
20 20
 
21 21
 // MakeRPrivate ensures a mounted filesystem has the RPRIVATE mount option
22 22
 // enabled. See the supported options in flags.go for further reference.
23 23
 func MakeRPrivate(mountPoint string) error {
24
-	return ensureMountedAs(mountPoint, "rprivate")
24
+	return ensureMountedAs(mountPoint, RPRIVATE)
25 25
 }
26 26
 
27 27
 // MakeSlave ensures a mounted filesystem has the SLAVE mount option enabled.
28 28
 // See the supported options in flags.go for further reference.
29 29
 func MakeSlave(mountPoint string) error {
30
-	return ensureMountedAs(mountPoint, "slave")
30
+	return ensureMountedAs(mountPoint, SLAVE)
31 31
 }
32 32
 
33 33
 // MakeRSlave ensures a mounted filesystem has the RSLAVE mount option enabled.
34 34
 // See the supported options in flags.go for further reference.
35 35
 func MakeRSlave(mountPoint string) error {
36
-	return ensureMountedAs(mountPoint, "rslave")
36
+	return ensureMountedAs(mountPoint, RSLAVE)
37 37
 }
38 38
 
39 39
 // MakeUnbindable ensures a mounted filesystem has the UNBINDABLE mount option
40 40
 // enabled. See the supported options in flags.go for further reference.
41 41
 func MakeUnbindable(mountPoint string) error {
42
-	return ensureMountedAs(mountPoint, "unbindable")
42
+	return ensureMountedAs(mountPoint, UNBINDABLE)
43 43
 }
44 44
 
45 45
 // MakeRUnbindable ensures a mounted filesystem has the RUNBINDABLE mount
46 46
 // option enabled. See the supported options in flags.go for further reference.
47 47
 func MakeRUnbindable(mountPoint string) error {
48
-	return ensureMountedAs(mountPoint, "runbindable")
48
+	return ensureMountedAs(mountPoint, RUNBINDABLE)
49 49
 }
50 50
 
51 51
 // MakeMount ensures that the file or directory given is a mount point,
... ...
@@ -59,13 +59,13 @@ func MakeMount(mnt string) error {
59 59
 		return nil
60 60
 	}
61 61
 
62
-	return Mount(mnt, mnt, "none", "bind")
62
+	return mount(mnt, mnt, "none", uintptr(BIND), "")
63 63
 }
64 64
 
65
-func ensureMountedAs(mountPoint, options string) error {
66
-	if err := MakeMount(mountPoint); err != nil {
65
+func ensureMountedAs(mnt string, flags int) error {
66
+	if err := MakeMount(mnt); err != nil {
67 67
 		return err
68 68
 	}
69 69
 
70
-	return ForceMount("", mountPoint, "none", options)
70
+	return mount("", mnt, "none", uintptr(flags), "")
71 71
 }