devicemapper: Check loop devices of existing pool

Often it happens that docker is not able to shutdown/remove the thin
pool it created because some device has leaked into some mount name
space. That means device is in use and that means pool can't be removed.

Docker will leave pool as it is and exit. Later when user starts the
docker, it finds pool is already there and docker uses it. But docker
does not know it is same pool which is using the loop devices. Now
docker thinks loop devices are not being used. That means it does not
display the data correctly in "docker info", giving user wrong information.

This patch tries to detect if loop devices as created by docker are
being used for pool and fills in the right details in "docker info".

Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
This commit is contained in:
Vivek Goyal 2015-07-07 14:13:29 -04:00
parent 8f3be15af7
commit b210423311

View file

@ -587,6 +587,31 @@ func GetStatus(name string) (uint64, uint64, string, string, error) {
return start, length, targetType, params, nil return start, length, targetType, params, nil
} }
func GetTable(name string) (uint64, uint64, string, string, error) {
task, err := TaskCreateNamed(DeviceTable, name)
if task == nil {
logrus.Debugf("GetTable: Error TaskCreateNamed: %s", err)
return 0, 0, "", "", err
}
if err := task.Run(); err != nil {
logrus.Debugf("GetTable: Error Run: %s", err)
return 0, 0, "", "", err
}
devinfo, err := task.GetInfo()
if err != nil {
logrus.Debugf("GetTable: Error GetInfo: %s", err)
return 0, 0, "", "", err
}
if devinfo.Exists == 0 {
logrus.Debugf("GetTable: Non existing device %s", name)
return 0, 0, "", "", fmt.Errorf("Non existing device %s", name)
}
_, start, length, targetType, params := task.GetNextTarget(unsafe.Pointer(nil))
return start, length, targetType, params, nil
}
func SetTransactionId(poolName string, oldId uint64, newId uint64) error { func SetTransactionId(poolName string, oldId uint64, newId uint64) error {
task, err := TaskCreateNamed(DeviceTargetMsg, poolName) task, err := TaskCreateNamed(DeviceTargetMsg, poolName)
if task == nil { if task == nil {