diff --git a/drivers/aufs/aufs.go b/drivers/aufs/aufs.go index e821bc0c5d..0db0f763f4 100644 --- a/drivers/aufs/aufs.go +++ b/drivers/aufs/aufs.go @@ -742,3 +742,8 @@ func (a *Driver) UpdateLayerIDMap(id string, toContainer, toHost *idtools.IDMapp func (a *Driver) SupportsShifting() bool { return false } + +// Mounted tells whether the path is mounted +func (a *Driver) Mounted(path string) (bool, error) { + return mountpk.Mounted(path) +} diff --git a/drivers/btrfs/btrfs.go b/drivers/btrfs/btrfs.go index 30254d9fb5..7f0cbf6f85 100644 --- a/drivers/btrfs/btrfs.go +++ b/drivers/btrfs/btrfs.go @@ -685,3 +685,8 @@ func (d *Driver) Exists(id string) bool { func (d *Driver) AdditionalImageStores() []string { return nil } + +// Mounted tells whether the path is mounted +func (d *Driver) Mounted(path string) (bool, error) { + return mount.Mounted(path) +} diff --git a/drivers/devmapper/driver.go b/drivers/devmapper/driver.go index 13677c93a3..b97c68554d 100644 --- a/drivers/devmapper/driver.go +++ b/drivers/devmapper/driver.go @@ -242,3 +242,8 @@ func (d *Driver) Exists(id string) bool { func (d *Driver) AdditionalImageStores() []string { return nil } + +// Mounted tells whether the path is mounted +func (d *Driver) Mounted(path string) (bool, error) { + return mount.Mounted(path) +} diff --git a/drivers/driver.go b/drivers/driver.go index dda1725747..0baac67c1e 100644 --- a/drivers/driver.go +++ b/drivers/driver.go @@ -100,6 +100,9 @@ type ProtoDriver interface { Cleanup() error // AdditionalImageStores returns additional image stores supported by the driver AdditionalImageStores() []string + + // Mounted tells whether the path is mounted + Mounted(path string) (bool, error) } // DiffDriver is the interface to use to implement graph diffs diff --git a/drivers/overlay/overlay.go b/drivers/overlay/overlay.go index 657d9b3ce2..ecf836b22a 100644 --- a/drivers/overlay/overlay.go +++ b/drivers/overlay/overlay.go @@ -1052,6 +1052,11 @@ func (d *Driver) SupportsShifting() bool { return d.options.mountProgram != "" } +// Mounted tells whether the path is mounted +func (d *Driver) Mounted(path string) (bool, error) { + return mount.Mounted(path) +} + // dumbJoin is more or less a dumber version of filepath.Join, but one which // won't Clean() the path, allowing us to append ".." as a component and trust // pathname resolution to do some non-obvious work. diff --git a/drivers/vfs/driver.go b/drivers/vfs/driver.go index 5941ccc170..81ec719486 100644 --- a/drivers/vfs/driver.go +++ b/drivers/vfs/driver.go @@ -219,3 +219,8 @@ func (d *Driver) AdditionalImageStores() []string { } return nil } + +// Mounted tells whether the path is mounted +func (d *Driver) Mounted(path string) (bool, error) { + return true, nil +} diff --git a/drivers/zfs/zfs.go b/drivers/zfs/zfs.go index eaa9e8bc53..56053336eb 100644 --- a/drivers/zfs/zfs.go +++ b/drivers/zfs/zfs.go @@ -447,3 +447,8 @@ func (d *Driver) Exists(id string) bool { func (d *Driver) AdditionalImageStores() []string { return nil } + +// Mounted tells whether the path is mounted +func (d *Driver) Mounted(path string) (bool, error) { + return mount.Mounted(path) +} diff --git a/layers.go b/layers.go index 110e737b2e..a52e2ce0a6 100644 --- a/layers.go +++ b/layers.go @@ -745,8 +745,16 @@ func (r *layerStore) Mount(id string, options drivers.MountOpts) (string, error) return "", ErrLayerUnknown } if layer.MountCount > 0 { - layer.MountCount++ - return layer.MountPoint, r.saveMounts() + mounted, err := r.driver.Mounted(layer.MountPoint) + if err != nil { + return "", err + } + if mounted { + layer.MountCount++ + return layer.MountPoint, r.saveMounts() + } else { + layer.MountCount = 0 + } } if options.MountLabel == "" { options.MountLabel = layer.MountLabel