diff --git a/deviceset.go b/deviceset.go index 2caaf153b2..95a3d48f27 100644 --- a/deviceset.go +++ b/deviceset.go @@ -6,6 +6,7 @@ type DeviceSet interface { DeactivateDevice(hash string) error RemoveDevice(hash string) error MountDevice(hash, path string) error + UnmountDevice(hash, path string) error HasDevice(hash string) bool HasInitializedDevice(hash string) bool } @@ -43,6 +44,10 @@ func (wrapper *DeviceSetWrapper) MountDevice(hash, path string) error { return wrapper.wrapped.MountDevice(wrapper.wrap(hash), path) } +func (wrapper *DeviceSetWrapper) UnmountDevice(hash, path string) error { + return wrapper.wrapped.UnmountDevice(wrapper.wrap(hash), path) +} + func (wrapper *DeviceSetWrapper) HasDevice(hash string) bool { return wrapper.wrapped.HasDevice(wrapper.wrap(hash)) } diff --git a/devmapper/deviceset_devmapper.go b/devmapper/deviceset_devmapper.go index d163609a7f..e31515042c 100644 --- a/devmapper/deviceset_devmapper.go +++ b/devmapper/deviceset_devmapper.go @@ -637,7 +637,7 @@ func (devices *DeviceSetDM) setupBaseImage() error { return err } - err = syscall.Unmount(tmpDir, 0) + err = devices.UnmountDevice("", tmpDir) if err != nil { return err } @@ -840,6 +840,16 @@ func (devices *DeviceSetDM) MountDevice(hash, path string) error { return nil } +func (devices *DeviceSetDM) UnmountDevice(hash, path string) error { + err := syscall.Unmount(path, 0) + if err != nil { + return err + } + + return nil +} + + func (devices *DeviceSetDM) HasDevice(hash string) bool { if err := devices.ensureInit(); err != nil { return false diff --git a/image.go b/image.go index 081d28249a..da03fb8ff1 100644 --- a/image.go +++ b/image.go @@ -379,7 +379,7 @@ func (image *Image) ensureImageDevice(devices DeviceSet) error { return err } - err = syscall.Unmount(mountDir, 0) + err = devices.UnmountDevice(image.ID, mountDir) if err != nil { _ = devices.RemoveDevice(image.ID) return err @@ -467,16 +467,17 @@ func (image *Image) Unmount(runtime *Runtime, root string, id string) error { return Unmount(root) case MountMethodDeviceMapper: - err := syscall.Unmount(root, 0) - if err != nil { - return err - } - // Try to deactivate the device as generally there is no use for it anymore devices, err := runtime.GetDeviceSet() if err != nil { return err; } + + err = devices.UnmountDevice(id, root) + if err != nil { + return err + } + return devices.DeactivateDevice(id) } return nil @@ -509,7 +510,7 @@ func (image *Image) Changes(runtime *Runtime, root, rw, id string) ([]Change, er } changes, err := ChangesDirs(root, rw) - _ = syscall.Unmount(rw, 0) + _ = devices.UnmountDevice(image.ID, rw) if err != nil { return nil, err }