From 35364749de1d8a70e0bc5c471e2f146d3df0940e Mon Sep 17 00:00:00 2001 From: Chris Alfonso Date: Thu, 15 Aug 2013 12:35:07 -0400 Subject: [PATCH] Remove a device mapping, then let the loop device get removed Change-Id: Ie1eb621ff56688208421d0115547f127a3c7fd56 --- lib/common-functions | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/common-functions b/lib/common-functions index 013274ee..ea4f9041 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -163,6 +163,16 @@ function run_d() { function detach_loopback() { local loopdev=$1 + + # Remove the map if it exists + # If setup on a rhel or derivative the map was created with kpartx not losetup + # and subsequently needs to be removed. + loopdev_name=$(echo $loopdev | sed 's/\/dev\///g') + mapper_name=$(sudo dmsetup ls | grep $loopdev_name | awk '{ print $1 }') + if [ "$mapper_name" ]; then + sudo dmsetup remove $mapper_name + fi + # loopback dev may be tied up a bit by udev events triggered by partition events for try in $(seq 10 -1 1) ; do if sudo losetup -d $loopdev ; then