From 30e28d31e0b9d16365b767c38bce478eef091f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 18 Apr 2015 00:14:47 +0200 Subject: [PATCH] zfs: retrieve all filesystems on startup at once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The docker graph call driver.Exists() on initialisation for each filesystem in the graph. This results will results in a lot `zfs get all` commands. To reduce this, retrieve all descend filesystem at startup and cache it for later checks Signed-off-by: Jörg Thalheim Upstream-commit: bad25ccf978b56da6fa181439504ab33906524cd Component: engine --- .../engine/daemon/graphdriver/zfs/zfs.go | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/components/engine/daemon/graphdriver/zfs/zfs.go b/components/engine/daemon/graphdriver/zfs/zfs.go index 9f6734950a..5126f87de3 100644 --- a/components/engine/daemon/graphdriver/zfs/zfs.go +++ b/components/engine/daemon/graphdriver/zfs/zfs.go @@ -68,14 +68,28 @@ func Init(base string, opt []string) (graphdriver.Driver, error) { zfs.SetLogger(new(Logger)) - dataset, err := zfs.GetDataset(options.fsName) + filesystems, err := zfs.Filesystems(options.fsName) if err != nil { - return nil, fmt.Errorf("Cannot open %s", options.fsName) + return nil, fmt.Errorf("Cannot find root filesystem %s: %v", options.fsName, err) + } + + filesystemsCache := make(map[string]bool, len(filesystems)) + var rootDataset *zfs.Dataset + for _, fs := range filesystems { + if fs.Name == options.fsName { + rootDataset = fs + } + filesystemsCache[fs.Name] = true + } + + if rootDataset == nil { + return nil, fmt.Errorf("BUG: zfs get all -t filesystems -rHp '%s' should contain '%s'", options.fsName, options.fsName) } d := &Driver{ - dataset: dataset, - options: options, + dataset: rootDataset, + options: options, + filesystemsCache: filesystemsCache, } return graphdriver.NaiveDiffDriver(d), nil } @@ -138,8 +152,9 @@ func lookupZfsDataset(rootdir string) (string, error) { } type Driver struct { - dataset *zfs.Dataset - options ZfsOptions + dataset *zfs.Dataset + options ZfsOptions + filesystemsCache map[string]bool } func (d *Driver) String() string { @@ -270,6 +285,5 @@ func (d *Driver) Put(id string) error { } func (d *Driver) Exists(id string) bool { - _, err := zfs.GetDataset(d.ZfsPath(id)) - return err == nil + return d.filesystemsCache[d.ZfsPath(id)] == true }