Browse code

overlay2: fix unmounting layer without merge dir

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit e1af6c8a5767e38957449a1d07e56104e317191b)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>

Tonis Tiigi authored on 2017/02/16 10:55:50
Showing 1 changed files
... ...
@@ -30,7 +30,7 @@ import (
30 30
 	"github.com/docker/docker/pkg/mount"
31 31
 	"github.com/docker/docker/pkg/parsers"
32 32
 	"github.com/docker/docker/pkg/parsers/kernel"
33
-	"github.com/docker/go-units"
33
+	units "github.com/docker/go-units"
34 34
 
35 35
 	"github.com/opencontainers/runc/libcontainer/label"
36 36
 )
... ...
@@ -553,7 +553,17 @@ func (d *Driver) Get(id string, mountLabel string) (s string, err error) {
553 553
 
554 554
 // Put unmounts the mount path created for the give id.
555 555
 func (d *Driver) Put(id string) error {
556
-	mountpoint := path.Join(d.dir(id), "merged")
556
+	dir := d.dir(id)
557
+	_, err := ioutil.ReadFile(path.Join(dir, lowerFile))
558
+	if err != nil {
559
+		// If no lower, no mount happened and just return directly
560
+		if os.IsNotExist(err) {
561
+			return nil
562
+		}
563
+		return err
564
+	}
565
+
566
+	mountpoint := path.Join(dir, "merged")
557 567
 	if count := d.ctr.Decrement(mountpoint); count > 0 {
558 568
 		return nil
559 569
 	}