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 <crosbymichael@gmail.com> Upstream-commit: 36a82c20321936a71b30fcfde8bc6c76d6cc8d1f Component: engine
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user