1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

devmapper: Remove call to waitClose()

During device removal, we are first waiting for device to close() in a tight
loop for 10 seconds. I am not sure why do we need it. First of all we come
here once the umount() is successful so device should be free. For some reason
of device is temporarily busy, then removeDevice() logic retries device removal
logic in a loop for 10 seconds and that should cover it. Can't see why one
more 10 seoncds loop is required before attempting device removal.

One loop should be able to cover all the temporary device busy conditions and
if condition is not temporary then 10 seconds loop is not going to help anyway.

So instead of two loops of 10 seconds each, I am converting it to a single
loop of 20 seconds. May be 10 second loop is good enough but for now I am
keeping it 20 seconds to avoid any regressions.

Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
This commit is contained in:
Vivek Goyal 2015-04-02 16:47:14 -04:00
parent dbf04ec4e2
commit f74d12012c

View file

@ -1225,12 +1225,6 @@ func (devices *DeviceSet) deactivateDevice(info *DevInfo) error {
logrus.Debugf("[devmapper] deactivateDevice(%s)", info.Hash) logrus.Debugf("[devmapper] deactivateDevice(%s)", info.Hash)
defer logrus.Debugf("[devmapper] deactivateDevice END(%s)", info.Hash) defer logrus.Debugf("[devmapper] deactivateDevice END(%s)", info.Hash)
// Wait for the unmount to be effective,
// by watching the value of Info.OpenCount for the device
if err := devices.waitClose(info); err != nil {
logrus.Errorf("Error waiting for device %s to close: %s", info.Hash, err)
}
devinfo, err := devicemapper.GetInfo(info.Name()) devinfo, err := devicemapper.GetInfo(info.Name())
if err != nil { if err != nil {
return err return err
@ -1251,7 +1245,7 @@ func (devices *DeviceSet) removeDevice(devname string) error {
logrus.Debugf("[devmapper] removeDevice START(%s)", devname) logrus.Debugf("[devmapper] removeDevice START(%s)", devname)
defer logrus.Debugf("[devmapper] removeDevice END(%s)", devname) defer logrus.Debugf("[devmapper] removeDevice END(%s)", devname)
for i := 0; i < 1000; i++ { for i := 0; i < 2000; i++ {
err = devicemapper.RemoveDevice(devname) err = devicemapper.RemoveDevice(devname)
if err == nil { if err == nil {
break break
@ -1270,32 +1264,6 @@ func (devices *DeviceSet) removeDevice(devname string) error {
return err return err
} }
// waitClose blocks until either:
// a) the device registered at <device_set_prefix>-<hash> is closed,
// or b) the 10 second timeout expires.
func (devices *DeviceSet) waitClose(info *DevInfo) error {
i := 0
for ; i < 1000; i++ {
devinfo, err := devicemapper.GetInfo(info.Name())
if err != nil {
return err
}
if i%100 == 0 {
logrus.Debugf("Waiting for unmount of %s: opencount=%d", info.Hash, devinfo.OpenCount)
}
if devinfo.OpenCount == 0 {
break
}
devices.Unlock()
time.Sleep(10 * time.Millisecond)
devices.Lock()
}
if i == 1000 {
return fmt.Errorf("Timeout while waiting for device %s to close", info.Hash)
}
return nil
}
func (devices *DeviceSet) Shutdown() error { func (devices *DeviceSet) Shutdown() error {
logrus.Debugf("[deviceset %s] Shutdown()", devices.devicePrefix) logrus.Debugf("[deviceset %s] Shutdown()", devices.devicePrefix)
logrus.Debugf("[devmapper] Shutting down DeviceSet: %s", devices.root) logrus.Debugf("[devmapper] Shutting down DeviceSet: %s", devices.root)