Browse code

Don't use separate bind mount for container

Since we're not not mounting anything but the base filesystem outside
the container we no longer need the separate bind mount at
/var/lib/docker/container/$id/root in order to see the base filesystem
without extra mounts. So, we drop this and mount (again) the container
root directly at the real basefs mountpoint.

Docker-DCO-1.1-Signed-off-by: Alexander Larsson <alexl@redhat.com> (github: alexlarsson)

Alexander Larsson authored on 2014/03/04 18:16:09
Showing 5 changed files
... ...
@@ -374,7 +374,7 @@ func (b *buildFile) checkPathForAddition(orig string) error {
374 374
 func (b *buildFile) addContext(container *runtime.Container, orig, dest string, remote bool) error {
375 375
 	var (
376 376
 		origPath = path.Join(b.contextPath, orig)
377
-		destPath = path.Join(container.BasefsPath(), dest)
377
+		destPath = path.Join(container.RootfsPath(), dest)
378 378
 	)
379 379
 	// Preserve the trailing '/'
380 380
 	if strings.HasSuffix(dest, "/") {
... ...
@@ -71,7 +71,7 @@ func containerFileExists(eng *engine.Engine, id, dir string, t utils.Fataler) bo
71 71
 		t.Fatal(err)
72 72
 	}
73 73
 	defer c.Unmount()
74
-	if _, err := os.Stat(path.Join(c.BasefsPath(), dir)); err != nil {
74
+	if _, err := os.Stat(path.Join(c.RootfsPath(), dir)); err != nil {
75 75
 		if os.IsNotExist(err) {
76 76
 			return false
77 77
 		}
... ...
@@ -532,7 +532,7 @@ func (container *Container) Start() (err error) {
532 532
 	populateCommand(container)
533 533
 	container.command.Env = env
534 534
 
535
-	if err := mountVolumesForContainer(container, envPath); err != nil {
535
+	if err := setupMountsForContainer(container, envPath); err != nil {
536 536
 		return err
537 537
 	}
538 538
 
... ...
@@ -843,8 +843,6 @@ func (container *Container) cleanup() {
843 843
 		}
844 844
 	}
845 845
 
846
-	unmountVolumesForContainer(container)
847
-
848 846
 	if err := container.Unmount(); err != nil {
849 847
 		log.Printf("%v: Failed to umount filesystem: %v", container.ID, err)
850 848
 	}
... ...
@@ -1039,12 +1037,6 @@ func (container *Container) EnvConfigPath() (string, error) {
1039 1039
 // This method must be exported to be used from the lxc template
1040 1040
 // This directory is only usable when the container is running
1041 1041
 func (container *Container) RootfsPath() string {
1042
-	return path.Join(container.root, "root")
1043
-}
1044
-
1045
-// This is the stand-alone version of the root fs, without any additional mounts.
1046
-// This directory is usable whenever the container is mounted (and not unmounted)
1047
-func (container *Container) BasefsPath() string {
1048 1042
 	return container.basefs
1049 1043
 }
1050 1044
 
... ...
@@ -174,7 +174,6 @@ func (runtime *Runtime) Register(container *Container) error {
174 174
 				runtime.execDriver.Kill(command, 9)
175 175
 			}
176 176
 			// ensure that the filesystem is also unmounted
177
-			unmountVolumesForContainer(container)
178 177
 			if err := container.Unmount(); err != nil {
179 178
 				utils.Debugf("ghost unmount error %s", err)
180 179
 			}
... ...
@@ -185,7 +184,6 @@ func (runtime *Runtime) Register(container *Container) error {
185 185
 			utils.Debugf("Container %s was supposed to be running but is not.", container.ID)
186 186
 			if runtime.config.AutoRestart {
187 187
 				utils.Debugf("Restarting")
188
-				unmountVolumesForContainer(container)
189 188
 				if err := container.Unmount(); err != nil {
190 189
 					utils.Debugf("restart unmount error %s", err)
191 190
 				}
... ...
@@ -4,10 +4,8 @@ import (
4 4
 	"fmt"
5 5
 	"github.com/dotcloud/docker/archive"
6 6
 	"github.com/dotcloud/docker/execdriver"
7
-	"github.com/dotcloud/docker/pkg/mount"
8 7
 	"github.com/dotcloud/docker/utils"
9 8
 	"io/ioutil"
10
-	"log"
11 9
 	"os"
12 10
 	"path/filepath"
13 11
 	"strings"
... ...
@@ -35,29 +33,9 @@ func prepareVolumesForContainer(container *Container) error {
35 35
 	return nil
36 36
 }
37 37
 
38
-func mountVolumesForContainer(container *Container, envPath string) error {
39
-	// Setup the root fs as a bind mount of the base fs
40
-	var (
41
-		root    = container.RootfsPath()
42
-		runtime = container.runtime
43
-	)
44
-	if err := os.MkdirAll(root, 0755); err != nil && !os.IsExist(err) {
45
-		return nil
46
-	}
47
-
48
-	// Create a bind mount of the base fs as a place where we can add mounts
49
-	// without affecting the ability to access the base fs
50
-	if err := mount.Mount(container.basefs, root, "none", "bind,rw"); err != nil {
51
-		return err
52
-	}
53
-
54
-	// Make sure the root fs is private so the mounts here don't propagate to basefs
55
-	if err := mount.ForceMount(root, root, "none", "private"); err != nil {
56
-		return err
57
-	}
58
-
38
+func setupMountsForContainer(container *Container, envPath string) error {
59 39
 	mounts := []execdriver.Mount{
60
-		{runtime.sysInitPath, "/.dockerinit", false, true},
40
+		{container.runtime.sysInitPath, "/.dockerinit", false, true},
61 41
 		{envPath, "/.dockerenv", false, true},
62 42
 		{container.ResolvConfPath, "/etc/resolv.conf", false, true},
63 43
 	}
... ...
@@ -80,12 +58,6 @@ func mountVolumesForContainer(container *Container, envPath string) error {
80 80
 	return nil
81 81
 }
82 82
 
83
-func unmountVolumesForContainer(container *Container) {
84
-	if err := mount.Unmount(container.RootfsPath()); err != nil {
85
-		log.Printf("Failed to umount container: %v", err)
86
-	}
87
-}
88
-
89 83
 func applyVolumesFrom(container *Container) error {
90 84
 	if container.Config.VolumesFrom != "" {
91 85
 		for _, containerSpec := range strings.Split(container.Config.VolumesFrom, ",") {