Fixed device or resource busy issue in EXIT trap

cleanup for ramdisk failed to umount TMP_BUILD_DIR with device or
resource busy error.

The patch unmounts all the mountpoints under TMP_BUILD_DIR and
detaches loop devices associated with TMP_IMAGE_PATH.

The unmounts are applied with both force(-f) and lazy(-l)
options. Force option is only for NFS mounts, it's kept here since no
harm for lazy option.

Change-Id: I84035e6a003d8135186b2fda3facbd2c37967529
This commit is contained in:
JUN JIE NAN 2013-12-24 16:24:59 +08:00
parent f176a78486
commit 6b7cf26689
2 changed files with 17 additions and 1 deletions

View File

@ -275,3 +275,12 @@ function mount_proc_dev_sys () {
sudo mount -t sysfs none $TMP_MOUNT_PATH/sys
}
function unmount_dir () {
local pattern="$1" mnts=""
if [ -n "$pattern" ]; then
mnts=`awk '{print $2}' < /proc/mounts | grep "^$pattern" | sort -r`
fi
if [ -n "$mnts" ]; then
sudo umount -fl $mnts || true
fi
}

View File

@ -25,7 +25,14 @@ function fullpath() {
}
function cleanup () {
sudo umount -f $TMP_BUILD_DIR || true
unmount_dir "$TMP_BUILD_DIR/mnt"
if [ -f "$TMP_IMAGE_PATH" ]; then
loopdev=`sudo losetup -j "$TMP_IMAGE_PATH" | cut -d: -f1`
if [ -n "$loopdev" ]; then
detach_loopback "$loopdev"
fi
fi
unmount_dir "$TMP_BUILD_DIR"
rm -rf --one-file-system "$TMP_BUILD_DIR"
}