|
@@ -2115,7 +2115,7 @@ func (devices *DeviceSet) MountDevice(hash, path, mountLabel string) error {
|
|
|
}
|
|
|
|
|
|
// UnmountDevice unmounts the device and removes it from hash.
|
|
|
-func (devices *DeviceSet) UnmountDevice(hash string) error {
|
|
|
+func (devices *DeviceSet) UnmountDevice(hash, mountPath string) error {
|
|
|
logrus.Debugf("[devmapper] UnmountDevice(hash=%s)", hash)
|
|
|
defer logrus.Debugf("[devmapper] UnmountDevice(hash=%s) END", hash)
|
|
|
|
|
@@ -2130,17 +2130,22 @@ func (devices *DeviceSet) UnmountDevice(hash string) error {
|
|
|
devices.Lock()
|
|
|
defer devices.Unlock()
|
|
|
|
|
|
- if info.mountCount == 0 {
|
|
|
- return fmt.Errorf("UnmountDevice: device not-mounted id %s", hash)
|
|
|
- }
|
|
|
+ // If there are running containers when daemon crashes, during daemon
|
|
|
+ // restarting, it will kill running contaienrs and will finally call
|
|
|
+ // Put() without calling Get(). So info.MountCount may become negative.
|
|
|
+ // if info.mountCount goes negative, we do the unmount and assign
|
|
|
+ // it to 0.
|
|
|
|
|
|
info.mountCount--
|
|
|
if info.mountCount > 0 {
|
|
|
return nil
|
|
|
+ } else if info.mountCount < 0 {
|
|
|
+ logrus.Warnf("[devmapper] Mount count of device went negative. Put() called without matching Get(). Resetting count to 0")
|
|
|
+ info.mountCount = 0
|
|
|
}
|
|
|
|
|
|
- logrus.Debugf("[devmapper] Unmount(%s)", info.mountPath)
|
|
|
- if err := syscall.Unmount(info.mountPath, syscall.MNT_DETACH); err != nil {
|
|
|
+ logrus.Debugf("[devmapper] Unmount(%s)", mountPath)
|
|
|
+ if err := syscall.Unmount(mountPath, syscall.MNT_DETACH); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
logrus.Debugf("[devmapper] Unmount done")
|