Browse code

graphdriver: Fail initialization if supported but got error

If a graphdriver fails initialization due to ErrNotSupported we ignore
that and keep trying the next. But if some driver has a different
error (for instance if you specified an unknown option for it) we fail
the daemon startup, printing the error, rather than falling back to an
unexected driver (typically vfs) which may not match what you have run
earlier.

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

Alexander Larsson authored on 2014/03/28 01:41:06
Showing 4 changed files
... ...
@@ -54,7 +54,7 @@ type Driver struct {
54 54
 func Init(root string) (graphdriver.Driver, error) {
55 55
 	// Try to load the aufs kernel module
56 56
 	if err := supportsAufs(); err != nil {
57
-		return nil, err
57
+		return nil, graphdriver.ErrNotSupported
58 58
 	}
59 59
 	paths := []string{
60 60
 		"mnt",
... ...
@@ -19,7 +19,7 @@ var (
19 19
 func testInit(dir string, t *testing.T) graphdriver.Driver {
20 20
 	d, err := Init(dir)
21 21
 	if err != nil {
22
-		if err == ErrAufsNotSupported {
22
+		if err == graphdriver.ErrNotSupported {
23 23
 			t.Skip(err)
24 24
 		} else {
25 25
 			t.Fatal(err)
... ...
@@ -31,7 +31,7 @@ func Init(home string) (graphdriver.Driver, error) {
31 31
 	}
32 32
 
33 33
 	if buf.Type != 0x9123683E {
34
-		return nil, fmt.Errorf("%s is not a btrfs filesystem", rootdir)
34
+		return nil, graphdriver.ErrNotSupported
35 35
 	}
36 36
 
37 37
 	return &Driver{
... ...
@@ -1,9 +1,9 @@
1 1
 package graphdriver
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 	"github.com/dotcloud/docker/archive"
6
-	"github.com/dotcloud/docker/utils"
7 7
 	"os"
8 8
 	"path"
9 9
 )
... ...
@@ -43,6 +43,8 @@ var (
43 43
 		"devicemapper",
44 44
 		"vfs",
45 45
 	}
46
+
47
+	ErrNotSupported = errors.New("driver not supported")
46 48
 )
47 49
 
48 50
 func init() {
... ...
@@ -62,7 +64,7 @@ func GetDriver(name, home string) (Driver, error) {
62 62
 	if initFunc, exists := drivers[name]; exists {
63 63
 		return initFunc(path.Join(home, name))
64 64
 	}
65
-	return nil, fmt.Errorf("No such driver: %s", name)
65
+	return nil, ErrNotSupported
66 66
 }
67 67
 
68 68
 func New(root string) (driver Driver, err error) {
... ...
@@ -74,9 +76,12 @@ func New(root string) (driver Driver, err error) {
74 74
 
75 75
 	// Check for priority drivers first
76 76
 	for _, name := range priority {
77
-		if driver, err = GetDriver(name, root); err != nil {
78
-			utils.Debugf("Error loading driver %s: %s", name, err)
79
-			continue
77
+		driver, err = GetDriver(name, root)
78
+		if err != nil {
79
+			if err == ErrNotSupported {
80
+				continue
81
+			}
82
+			return nil, err
80 83
 		}
81 84
 		return driver, nil
82 85
 	}
... ...
@@ -84,9 +89,12 @@ func New(root string) (driver Driver, err error) {
84 84
 	// Check all registered drivers if no priority driver is found
85 85
 	for _, initFunc := range drivers {
86 86
 		if driver, err = initFunc(root); err != nil {
87
-			continue
87
+			if err == ErrNotSupported {
88
+				continue
89
+			}
90
+			return nil, err
88 91
 		}
89 92
 		return driver, nil
90 93
 	}
91
-	return nil, err
94
+	return nil, fmt.Errorf("No supported storage backend found")
92 95
 }