Browse code

block aufs on incompatible file systems

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)

unclejack authored on 2014/05/30 04:55:59
Showing 2 changed files
... ...
@@ -23,20 +23,23 @@ package aufs
23 23
 import (
24 24
 	"bufio"
25 25
 	"fmt"
26
-	"github.com/dotcloud/docker/archive"
27
-	"github.com/dotcloud/docker/daemon/graphdriver"
28
-	"github.com/dotcloud/docker/pkg/label"
29
-	mountpk "github.com/dotcloud/docker/pkg/mount"
30
-	"github.com/dotcloud/docker/utils"
31 26
 	"os"
32 27
 	"os/exec"
33 28
 	"path"
34 29
 	"strings"
35 30
 	"sync"
31
+	"syscall"
32
+
33
+	"github.com/dotcloud/docker/archive"
34
+	"github.com/dotcloud/docker/daemon/graphdriver"
35
+	"github.com/dotcloud/docker/pkg/label"
36
+	mountpk "github.com/dotcloud/docker/pkg/mount"
37
+	"github.com/dotcloud/docker/utils"
36 38
 )
37 39
 
38 40
 var (
39 41
 	ErrAufsNotSupported = fmt.Errorf("AUFS was not found in /proc/filesystems")
42
+	IncompatibleFSMagic = []int64{0x9123683E /*btrfs*/, 0x61756673 /*AUFS*/}
40 43
 )
41 44
 
42 45
 func init() {
... ...
@@ -56,6 +59,20 @@ func Init(root string) (graphdriver.Driver, error) {
56 56
 	if err := supportsAufs(); err != nil {
57 57
 		return nil, graphdriver.ErrNotSupported
58 58
 	}
59
+
60
+	rootdir := path.Dir(root)
61
+
62
+	var buf syscall.Statfs_t
63
+	if err := syscall.Statfs(rootdir, &buf); err != nil {
64
+		return nil, fmt.Errorf("Couldn't stat the root directory: %s", err)
65
+	}
66
+
67
+	for _, magic := range IncompatibleFSMagic {
68
+		if int64(buf.Type) == magic {
69
+			return nil, graphdriver.ErrIncompatibleFS
70
+		}
71
+	}
72
+
59 73
 	paths := []string{
60 74
 		"mnt",
61 75
 		"diff",
... ...
@@ -44,8 +44,9 @@ var (
44 44
 		"vfs",
45 45
 	}
46 46
 
47
-	ErrNotSupported  = errors.New("driver not supported")
48
-	ErrPrerequisites = errors.New("Prerequisites for driver not satisfied (wrong filesystem?)")
47
+	ErrNotSupported   = errors.New("driver not supported")
48
+	ErrPrerequisites  = errors.New("prerequisites for driver not satisfied (wrong filesystem?)")
49
+	ErrIncompatibleFS = fmt.Errorf("backing file system is unsupported for this graph driver")
49 50
 )
50 51
 
51 52
 func init() {
... ...
@@ -79,7 +80,7 @@ func New(root string) (driver Driver, err error) {
79 79
 	for _, name := range priority {
80 80
 		driver, err = GetDriver(name, root)
81 81
 		if err != nil {
82
-			if err == ErrNotSupported || err == ErrPrerequisites {
82
+			if err == ErrNotSupported || err == ErrPrerequisites || err == ErrIncompatibleFS {
83 83
 				continue
84 84
 			}
85 85
 			return nil, err
... ...
@@ -90,7 +91,7 @@ func New(root string) (driver Driver, err error) {
90 90
 	// Check all registered drivers if no priority driver is found
91 91
 	for _, initFunc := range drivers {
92 92
 		if driver, err = initFunc(root); err != nil {
93
-			if err == ErrNotSupported || err == ErrPrerequisites {
93
+			if err == ErrNotSupported || err == ErrPrerequisites || err == ErrIncompatibleFS {
94 94
 				continue
95 95
 			}
96 96
 			return nil, err