Skip to content

Commit

Permalink
ZFS driver: raise better errors during init
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
flavio committed Jul 20, 2015
1 parent 008d57b commit f95b3a6
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions daemon/graphdriver/zfs/zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit f95b3a6

Please sign in to comment.