From 7fb23fc9ef3bbdb12411d35fbddc585c2b8a0a2f Mon Sep 17 00:00:00 2001 From: Vivek Goyal Date: Wed, 30 Sep 2015 15:21:22 -0400 Subject: [PATCH] devmapper: Fail device deletion early if device is still mounted If a device is still mounted at the time of DeleteDevice(), that means higher layers have not called Put() properly on the device and are trying to delete it. This is a bug in the code where Get() and Put() have not been properly paired up. Fail device deletion if it is still mounted. Signed-off-by: Vivek Goyal Upstream-commit: e97e46b7376c3195383636d305d832b2ba3f82c5 Component: engine --- .../engine/daemon/graphdriver/devmapper/deviceset.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/engine/daemon/graphdriver/devmapper/deviceset.go b/components/engine/daemon/graphdriver/devmapper/deviceset.go index c2488faa10..e96127a000 100644 --- a/components/engine/daemon/graphdriver/devmapper/deviceset.go +++ b/components/engine/daemon/graphdriver/devmapper/deviceset.go @@ -1521,6 +1521,13 @@ func (devices *DeviceSet) DeleteDevice(hash string) error { devices.Lock() defer devices.Unlock() + // If mountcount is not zero, that means devices is still in use + // or has not been Put() properly. Fail device deletion. + + if info.mountCount != 0 { + return fmt.Errorf("devmapper: Can't delete device %v as it is still mounted. mntCount=%v", info.Hash, info.mountCount) + } + return devices.deleteDevice(info) }