Browse code

Make sure dev/fuse is created in container

Fixes #5849

If the host system does not have fuse enabled in the kernel config we
will ignore the is not exist errors when trying to copy the device node
from the host system into the container.
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)

Michael Crosby authored on 2014/05/20 05:46:59
Showing 2 changed files
... ...
@@ -48,9 +48,12 @@ func InitializeMountNamespace(rootfs, console string, container *libcontainer.Co
48 48
 	if err := setupBindmounts(rootfs, container.Mounts); err != nil {
49 49
 		return fmt.Errorf("bind mounts %s", err)
50 50
 	}
51
-	if err := nodes.CopyN(rootfs, nodes.DefaultNodes); err != nil {
51
+	if err := nodes.CopyN(rootfs, nodes.DefaultNodes, true); err != nil {
52 52
 		return fmt.Errorf("copy dev nodes %s", err)
53 53
 	}
54
+	if err := nodes.CopyN(rootfs, nodes.AdditionalNodes, false); err != nil {
55
+		return fmt.Errorf("copy additional dev nodes %s", err)
56
+	}
54 57
 	if err := SetupPtmx(rootfs, console, container.Context["mount_label"]); err != nil {
55 58
 		return err
56 59
 	}
... ...
@@ -4,10 +4,11 @@ package nodes
4 4
 
5 5
 import (
6 6
 	"fmt"
7
-	"github.com/dotcloud/docker/pkg/system"
8 7
 	"os"
9 8
 	"path/filepath"
10 9
 	"syscall"
10
+
11
+	"github.com/dotcloud/docker/pkg/system"
11 12
 )
12 13
 
13 14
 // Default list of device nodes to copy
... ...
@@ -20,30 +21,43 @@ var DefaultNodes = []string{
20 20
 	"tty",
21 21
 }
22 22
 
23
+// AdditionalNodes includes nodes that are not required
24
+var AdditionalNodes = []string{
25
+	"fuse",
26
+}
27
+
23 28
 // CopyN copies the device node from the host into the rootfs
24
-func CopyN(rootfs string, nodesToCopy []string) error {
29
+func CopyN(rootfs string, nodesToCopy []string, shouldExist bool) error {
25 30
 	oldMask := system.Umask(0000)
26 31
 	defer system.Umask(oldMask)
27 32
 
28 33
 	for _, node := range nodesToCopy {
29
-		if err := Copy(rootfs, node); err != nil {
34
+		if err := Copy(rootfs, node, shouldExist); err != nil {
30 35
 			return err
31 36
 		}
32 37
 	}
33 38
 	return nil
34 39
 }
35 40
 
36
-func Copy(rootfs, node string) error {
41
+// Copy copies the device node into the rootfs.  If the node
42
+// on the host system does not exist and the boolean flag is passed
43
+// an error will be returned
44
+func Copy(rootfs, node string, shouldExist bool) error {
37 45
 	stat, err := os.Stat(filepath.Join("/dev", node))
38 46
 	if err != nil {
47
+		if os.IsNotExist(err) && !shouldExist {
48
+			return nil
49
+		}
39 50
 		return err
40 51
 	}
52
+
41 53
 	var (
42 54
 		dest = filepath.Join(rootfs, "dev", node)
43 55
 		st   = stat.Sys().(*syscall.Stat_t)
44 56
 	)
57
+
45 58
 	if err := system.Mknod(dest, st.Mode, int(st.Rdev)); err != nil && !os.IsExist(err) {
46
-		return fmt.Errorf("copy %s %s", node, err)
59
+		return fmt.Errorf("mknod %s %s", node, err)
47 60
 	}
48 61
 	return nil
49 62
 }