Bläddra i källkod

ZFS driver: raise better errors during init

The ZFS driver should raise proper errors when the ZFS utility is
missing or when there's no zfs partition active on the system. Raising the
proper errors make possible to silently ignore the ZFS storage
driver when no default storage driver is specified.

Previous to this commit it was no longer possible to start the
docker daemon in that way:

  docker -d --storage-opt dm.loopdatasize=2GB

The above command resulted in an exit error because the ZFS driver
tried to use the storage options.

Signed-off-by: Flavio Castelli <fcastelli@suse.com>
Flavio Castelli 10 år sedan
förälder
incheckning
f95b3a6b6a
1 ändrade filer med 13 tillägg och 10 borttagningar
  1. 13 10
      daemon/graphdriver/zfs/zfs.go

+ 13 - 10
daemon/graphdriver/zfs/zfs.go

@@ -38,6 +38,19 @@ func (*Logger) Log(cmd []string) {
 
 
 func Init(base string, opt []string) (graphdriver.Driver, error) {
 func Init(base string, opt []string) (graphdriver.Driver, error) {
 	var err error
 	var err error
+
+	if _, err := exec.LookPath("zfs"); err != nil {
+		log.Debugf("[zfs] zfs command is not available: %v", err)
+		return nil, graphdriver.ErrPrerequisites
+	}
+
+	file, err := os.OpenFile("/dev/zfs", os.O_RDWR, 600)
+	if err != nil {
+		log.Debugf("[zfs] cannot open /dev/zfs: %v", err)
+		return nil, graphdriver.ErrPrerequisites
+	}
+	defer file.Close()
+
 	options, err := parseOptions(opt)
 	options, err := parseOptions(opt)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
@@ -53,16 +66,6 @@ func Init(base string, opt []string) (graphdriver.Driver, error) {
 		}
 		}
 	}
 	}
 
 
-	if _, err := exec.LookPath("zfs"); err != nil {
-		return nil, fmt.Errorf("zfs command is not available: %v", err)
-	}
-
-	file, err := os.OpenFile("/dev/zfs", os.O_RDWR, 600)
-	if err != nil {
-		return nil, fmt.Errorf("cannot open /dev/zfs: %v", err)
-	}
-	defer file.Close()
-
 	if options.fsName == "" {
 	if options.fsName == "" {
 		options.fsName, err = lookupZfsDataset(rootdir)
 		options.fsName, err = lookupZfsDataset(rootdir)
 		if err != nil {
 		if err != nil {