Remove a device mapping, then let the loop device get removed

Change-Id: Ie1eb621ff56688208421d0115547f127a3c7fd56
This commit is contained in:
Chris Alfonso 2013-08-15 12:35:07 -04:00
parent e7a8fefa0b
commit 35364749de

View File

@ -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