Skip to content

Commit

Permalink
Check if layer is actually mounted if mount count > 0
Browse files Browse the repository at this point in the history
We have an issue with zfs on reboots getting this data wrong.

You can cause this situation also if someone goes out an umounts
a mount point manually.

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Mar 5, 2019
1 parent 96d15ac commit bedb4b7
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 2 deletions.
5 changes: 5 additions & 0 deletions drivers/aufs/aufs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 5 additions & 0 deletions drivers/btrfs/btrfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 5 additions & 0 deletions drivers/devmapper/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 3 additions & 0 deletions drivers/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions drivers/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions drivers/vfs/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions drivers/zfs/zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
12 changes: 10 additions & 2 deletions layers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bedb4b7

Please sign in to comment.