Retry losetup -d for up to 10 seconds.
When partition tables are added to loopback devices, this can set off a chain of udev hooks that may still be holding the loopback open. Failing to detach loopback devices was the reason we were seeing leaked tmpfs volumes. Fixes bug #1178091 Change-Id: I836d6e2bbce824951dd4786e3ef28273ea18ee73
This commit is contained in:
parent
bd0f73f4cc
commit
20661e8d80
@ -112,7 +112,7 @@ mv $TMP_BUILD_DIR/mnt $TMP_BUILD_DIR/built
|
|||||||
_NEEDED_SIZE=$(sudo du --block-size=800 -x -s ${TMP_BUILD_DIR}/built | awk ' { print $1 } ')
|
_NEEDED_SIZE=$(sudo du --block-size=800 -x -s ${TMP_BUILD_DIR}/built | awk ' { print $1 } ')
|
||||||
truncate -s${_NEEDED_SIZE}K $TMP_IMAGE_PATH
|
truncate -s${_NEEDED_SIZE}K $TMP_IMAGE_PATH
|
||||||
LOOPDEV=$(sudo losetup --show -f $TMP_IMAGE_PATH)
|
LOOPDEV=$(sudo losetup --show -f $TMP_IMAGE_PATH)
|
||||||
export EXTRA_UNMOUNT="sudo losetup -d $LOOPDEV"
|
export EXTRA_UNMOUNT="detach_loopback $LOOPDEV"
|
||||||
export IMAGE_BLOCK_DEVICE=$LOOPDEV
|
export IMAGE_BLOCK_DEVICE=$LOOPDEV
|
||||||
eval_run_d block-device "IMAGE_BLOCK_DEVICE="
|
eval_run_d block-device "IMAGE_BLOCK_DEVICE="
|
||||||
OPTS=""
|
OPTS=""
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
# vim: syntax=sh ts=4 sts=4 sw=2:et
|
||||||
# Copyright 2012 Hewlett-Packard Development Company, L.P.
|
# Copyright 2012 Hewlett-Packard Development Company, L.P.
|
||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
#
|
#
|
||||||
@ -159,3 +160,16 @@ function run_d() {
|
|||||||
check_break after-$1 bash
|
check_break after-$1 bash
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function detach_loopback() {
|
||||||
|
local loopdev=$1
|
||||||
|
# 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
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
echo $loopdev may be busy, sleeping up to $try more seconds...
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
echo Gave up trying to detach $loopdev
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user