From f95b3a6b6a4d86c6373e24b83ba1a008bf107265 Mon Sep 17 00:00:00 2001 From: Flavio Castelli Date: Mon, 20 Jul 2015 13:50:53 +0200 Subject: [PATCH] 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 --- daemon/graphdriver/zfs/zfs.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/daemon/graphdriver/zfs/zfs.go b/daemon/graphdriver/zfs/zfs.go index 3d4ed8fe4e..ece86cc0ab 100644 --- a/daemon/graphdriver/zfs/zfs.go +++ b/daemon/graphdriver/zfs/zfs.go @@ -38,6 +38,19 @@ func (*Logger) Log(cmd []string) { func Init(base string, opt []string) (graphdriver.Driver, 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) if err != nil { 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 == "" { options.fsName, err = lookupZfsDataset(rootdir) if err != nil {