Jelajahi Sumber

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 11 tahun lalu
induk
melakukan
4bdb8c03fc

+ 1 - 1
daemon/graphdriver/aufs/aufs.go

@@ -54,7 +54,7 @@ type Driver struct {
 func Init(root string) (graphdriver.Driver, error) {
 	// Try to load the aufs kernel module
 	if err := supportsAufs(); err != nil {
-		return nil, err
+		return nil, graphdriver.ErrNotSupported
 	}
 	paths := []string{
 		"mnt",

+ 1 - 1
daemon/graphdriver/aufs/aufs_test.go

@@ -19,7 +19,7 @@ var (
 func testInit(dir string, t *testing.T) graphdriver.Driver {
 	d, err := Init(dir)
 	if err != nil {
-		if err == ErrAufsNotSupported {
+		if err == graphdriver.ErrNotSupported {
 			t.Skip(err)
 		} else {
 			t.Fatal(err)

+ 1 - 1
daemon/graphdriver/btrfs/btrfs.go

@@ -31,7 +31,7 @@ func Init(home string) (graphdriver.Driver, error) {
 	}
 
 	if buf.Type != 0x9123683E {
-		return nil, fmt.Errorf("%s is not a btrfs filesystem", rootdir)
+		return nil, graphdriver.ErrNotSupported
 	}
 
 	return &Driver{

+ 15 - 7
daemon/graphdriver/driver.go

@@ -1,9 +1,9 @@
 package graphdriver
 
 import (
+	"errors"
 	"fmt"
 	"github.com/dotcloud/docker/archive"
-	"github.com/dotcloud/docker/utils"
 	"os"
 	"path"
 )
@@ -43,6 +43,8 @@ var (
 		"devicemapper",
 		"vfs",
 	}
+
+	ErrNotSupported = errors.New("driver not supported")
 )
 
 func init() {
@@ -62,7 +64,7 @@ func GetDriver(name, home string) (Driver, error) {
 	if initFunc, exists := drivers[name]; exists {
 		return initFunc(path.Join(home, name))
 	}
-	return nil, fmt.Errorf("No such driver: %s", name)
+	return nil, ErrNotSupported
 }
 
 func New(root string) (driver Driver, err error) {
@@ -74,9 +76,12 @@ func New(root string) (driver Driver, err error) {
 
 	// Check for priority drivers first
 	for _, name := range priority {
-		if driver, err = GetDriver(name, root); err != nil {
-			utils.Debugf("Error loading driver %s: %s", name, err)
-			continue
+		driver, err = GetDriver(name, root)
+		if err != nil {
+			if err == ErrNotSupported {
+				continue
+			}
+			return nil, err
 		}
 		return driver, nil
 	}
@@ -84,9 +89,12 @@ func New(root string) (driver Driver, err error) {
 	// Check all registered drivers if no priority driver is found
 	for _, initFunc := range drivers {
 		if driver, err = initFunc(root); err != nil {
-			continue
+			if err == ErrNotSupported {
+				continue
+			}
+			return nil, err
 		}
 		return driver, nil
 	}
-	return nil, err
+	return nil, fmt.Errorf("No supported storage backend found")
 }