From 11472e51660f2bd0db8678fff1c9cf4a5bc56eb1 Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Fri, 1 Feb 2013 15:11:13 -0800 Subject: [PATCH] common: make safe_umount retry a few times on Fedora 18 on Gnome 3.0 something is making the first attempt at unmounting return busy. Unfortunatly, the return code is 32 everytime so we have to parse the output of umount :( :( :( Change-Id: I7f94bf6c2059c7e7cb4fb173d9ffbabd59f2b24f --- bin/cros_update_image.sh | 8 ++++---- build_library/disk_layout_util.sh | 2 +- common.sh | 28 +++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/bin/cros_update_image.sh b/bin/cros_update_image.sh index 4ffe59ec1f..ebca9fbf83 100755 --- a/bin/cros_update_image.sh +++ b/bin/cros_update_image.sh @@ -66,10 +66,10 @@ if [[ ${PKGS/kernel/} != ${PKGS} ]]; then sudo dd if="./rootfs/boot/vmlinuz" of=part_2 bs=512 count=8192 conv=notrunc fi -sudo umount rootfs/usr/local -sudo umount rootfs/var -sudo umount rootfs -sudo umount stateful_part +safe_umount rootfs/usr/local +safe_umount rootfs/var +safe_umount rootfs +safe_umount stateful_part ./pack_partitions.sh ${IMAGE} cd - diff --git a/build_library/disk_layout_util.sh b/build_library/disk_layout_util.sh index 29ce67cd85..e75c07dac2 100644 --- a/build_library/disk_layout_util.sh +++ b/build_library/disk_layout_util.sh @@ -64,7 +64,7 @@ run_partition_script() { sudo mount -o loop "${root_fs_img}" "${root_fs_dir}" . "${root_fs_dir}/${PARTITION_SCRIPT_PATH}" write_partition_table "${outdev}" "${pmbr_img}" - sudo umount "${root_fs_dir}" + safe_umount "${root_fs_dir}" } get_fs_block_size() { diff --git a/common.sh b/common.sh index 78a0cc3f8b..7693d6ea84 100644 --- a/common.sh +++ b/common.sh @@ -705,7 +705,33 @@ safe_umount_tree() { # Run umount as root. safe_umount() { - $([[ ${UID:-$(id -u)} != 0 ]] && echo sudo) umount "$@" + local ret=0 + local out="" + set +e + for i in $(seq 1 4); do + out=`$([[ ${UID:-$(id -u)} != 0 ]] && echo sudo) umount "$@" 2>&1` + ret=$? + if [[ $ret -eq 0 ]]; then + set -e + return 0 + fi + # Mount is not found + if [[ `expr index "${out}" "not found"` -ne "0" ]]; then + set -e + return 0 + fi + # Mount is not mounted. + if [[ `expr index "${out}" "not mounted"` -ne "0" ]]; then + set -e + return 0 + fi + sleep 1 + # Mount is actually busy. + if [[ `expr index "${out}" "busy"` -ne "0" ]]; then + continue + fi + done + return $ret } get_git_id() {