1
0
Fork 0
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:
Alexander Larsson 2013-09-09 12:39:42 +02:00 committed by Victor Vieux
parent 261b0b01df
commit 251a7ed437
3 changed files with 24 additions and 8 deletions

View file

@ -6,6 +6,7 @@ type DeviceSet interface {
DeactivateDevice(hash string) error DeactivateDevice(hash string) error
RemoveDevice(hash string) error RemoveDevice(hash string) error
MountDevice(hash, path string) error MountDevice(hash, path string) error
UnmountDevice(hash, path string) error
HasDevice(hash string) bool HasDevice(hash string) bool
HasInitializedDevice(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) 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 { func (wrapper *DeviceSetWrapper) HasDevice(hash string) bool {
return wrapper.wrapped.HasDevice(wrapper.wrap(hash)) return wrapper.wrapped.HasDevice(wrapper.wrap(hash))
} }

View file

@ -637,7 +637,7 @@ func (devices *DeviceSetDM) setupBaseImage() error {
return err return err
} }
err = syscall.Unmount(tmpDir, 0) err = devices.UnmountDevice("", tmpDir)
if err != nil { if err != nil {
return err return err
} }
@ -840,6 +840,16 @@ func (devices *DeviceSetDM) MountDevice(hash, path string) error {
return nil 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 { func (devices *DeviceSetDM) HasDevice(hash string) bool {
if err := devices.ensureInit(); err != nil { if err := devices.ensureInit(); err != nil {
return false return false

View file

@ -379,7 +379,7 @@ func (image *Image) ensureImageDevice(devices DeviceSet) error {
return err return err
} }
err = syscall.Unmount(mountDir, 0) err = devices.UnmountDevice(image.ID, mountDir)
if err != nil { if err != nil {
_ = devices.RemoveDevice(image.ID) _ = devices.RemoveDevice(image.ID)
return err return err
@ -467,16 +467,17 @@ func (image *Image) Unmount(runtime *Runtime, root string, id string) error {
return Unmount(root) return Unmount(root)
case MountMethodDeviceMapper: 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 // Try to deactivate the device as generally there is no use for it anymore
devices, err := runtime.GetDeviceSet() devices, err := runtime.GetDeviceSet()
if err != nil { if err != nil {
return err; return err;
} }
err = devices.UnmountDevice(id, root)
if err != nil {
return err
}
return devices.DeactivateDevice(id) return devices.DeactivateDevice(id)
} }
return nil return nil
@ -509,7 +510,7 @@ func (image *Image) Changes(runtime *Runtime, root, rw, id string) ([]Change, er
} }
changes, err := ChangesDirs(root, rw) changes, err := ChangesDirs(root, rw)
_ = syscall.Unmount(rw, 0) _ = devices.UnmountDevice(image.ID, rw)
if err != nil { if err != nil {
return nil, err return nil, err
} }