From 6b7cf2668961327370112ba20ab764ecfccd3d34 Mon Sep 17 00:00:00 2001 From: JUN JIE NAN Date: Tue, 24 Dec 2013 16:24:59 +0800 Subject: [PATCH] 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 --- lib/common-functions | 9 +++++++++ lib/ramdisk-functions | 9 ++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/common-functions b/lib/common-functions index f3afe39e..4873d781 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -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 +} diff --git a/lib/ramdisk-functions b/lib/ramdisk-functions index 3646585d..aaa26983 100644 --- a/lib/ramdisk-functions +++ b/lib/ramdisk-functions @@ -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" }