From d350b13d02e72e69aa219a6486e862a1b3aacf5f Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Fri, 26 Jul 2019 16:23:39 +0530 Subject: [PATCH] unmap rbd volume if we fail to get devicepath Signed-off-by: Madhu Rajanna --- pkg/rbd/rbd_attach.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/rbd/rbd_attach.go b/pkg/rbd/rbd_attach.go index 91befe1a6..4be1dcd1a 100644 --- a/pkg/rbd/rbd_attach.go +++ b/pkg/rbd/rbd_attach.go @@ -284,6 +284,11 @@ func createPath(volOpt *rbdVolume, cr *util.Credentials) (string, error) { } devicePath, found := waitForPath(volOpt.Pool, image, 10, useNBD) if !found { + output, err := execCommand(cmdName, []string{ + "unmap", imagePath, "--id", cr.ID, "-m", volOpt.Monitors, "--keyfile=" + cr.KeyFile}) + if err != nil { + klog.Warningf("rbd: unmap error %v, rbd output: %s", err, string(output)) + } return "", fmt.Errorf("could not map image %s, Timeout after 10s", imagePath) } return devicePath, nil