Explorar el Código

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 <vgoyal@redhat.com>
Vivek Goyal hace 9 años
padre
commit
e97e46b737
Se han modificado 1 ficheros con 7 adiciones y 0 borrados
  1. 7 0
      daemon/graphdriver/devmapper/deviceset.go

+ 7 - 0
daemon/graphdriver/devmapper/deviceset.go

@@ -1521,6 +1521,13 @@ func (devices *DeviceSet) DeleteDevice(hash string) error {
 	devices.Lock()
 	devices.Lock()
 	defer devices.Unlock()
 	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)
 	return devices.deleteDevice(info)
 }
 }