From 36a82c20321936a71b30fcfde8bc6c76d6cc8d1f Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 16 May 2016 11:07:03 -0700 Subject: [PATCH] Fix overlay use of rootdir and defer Check for the rootDir first because the mergeDir may not exist if root is present. Also fix unmounting in the defer to make sure it does not have a refcount. Signed-off-by: Michael Crosby --- daemon/graphdriver/overlay/overlay.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/daemon/graphdriver/overlay/overlay.go b/daemon/graphdriver/overlay/overlay.go index 1abab6b265..d532e44037 100644 --- a/daemon/graphdriver/overlay/overlay.go +++ b/daemon/graphdriver/overlay/overlay.go @@ -333,23 +333,22 @@ func (d *Driver) Get(id string, mountLabel string) (s string, err error) { if _, err := os.Stat(dir); err != nil { return "", err } + // If id has a root, just return it + rootDir := path.Join(dir, "root") + if _, err := os.Stat(rootDir); err == nil { + return rootDir, nil + } mergedDir := path.Join(dir, "merged") if count := d.ctr.Increment(mergedDir); count > 1 { return mergedDir, nil } defer func() { if err != nil { - d.ctr.Decrement(mergedDir) - syscall.Unmount(mergedDir, 0) + if c := d.ctr.Decrement(mergedDir); c <= 0 { + syscall.Unmount(mergedDir, 0) + } } }() - - // If id has a root, just return it - rootDir := path.Join(dir, "root") - if _, err := os.Stat(rootDir); err == nil { - return rootDir, nil - } - lowerID, err := ioutil.ReadFile(path.Join(dir, "lower-id")) if err != nil { return "", err