From b210423311c0215fe1d3133027e97aff6b4a2b91 Mon Sep 17 00:00:00 2001 From: Vivek Goyal Date: Tue, 7 Jul 2015 14:13:29 -0400 Subject: [PATCH] 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 --- devicemapper/devmapper.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/devicemapper/devmapper.go b/devicemapper/devmapper.go index 3c58173..84d0729 100644 --- a/devicemapper/devmapper.go +++ b/devicemapper/devmapper.go @@ -587,6 +587,31 @@ func GetStatus(name string) (uint64, uint64, string, string, error) { 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 { task, err := TaskCreateNamed(DeviceTargetMsg, poolName) if task == nil {