mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
DeviceSet: Add UnmountDevice()
Right now this does nothing but add a new layer, but it means that all DeviceMounts are paired with DeviceUnmounts so that we can track (and cleanup) active mounts.
This commit is contained in:
parent
261b0b01df
commit
251a7ed437
3 changed files with 24 additions and 8 deletions
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
15
image.go
15
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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue