Merge pull request #44 from marineam/fix-umount

Fix umount
This commit is contained in:
Brandon Philips 2013-07-18 23:47:07 -07:00
commit a80d755473
2 changed files with 30 additions and 45 deletions

View File

@ -61,7 +61,9 @@ run_partition_script() {
;; ;;
esac esac
safe_umount "${root_fs_dir}" if is_mounted "${root_fs_dir}"; then
safe_umount "${root_fs_dir}"
fi
sudo mount -o loop "${root_fs_img}" "${root_fs_dir}" sudo mount -o loop "${root_fs_img}" "${root_fs_dir}"
. "${root_fs_dir}/${PARTITION_SCRIPT_PATH}" . "${root_fs_dir}/${PARTITION_SCRIPT_PATH}"
write_partition_table "${outdev}" "${pmbr_img}" write_partition_table "${outdev}" "${pmbr_img}"

View File

@ -643,7 +643,7 @@ sub_mounts() {
# will). As such, we have to unmount in reverse order to cleanly # will). As such, we have to unmount in reverse order to cleanly
# unmount submounts (think /dev/pts and /dev). # unmount submounts (think /dev/pts and /dev).
awk -v path=$1 -v len="${#1}" \ awk -v path=$1 -v len="${#1}" \
'(substr($2, 1, len) == path) { print $2 }' /proc/mounts | \ '(substr($2, 1, len) == path) { print $2 }' /proc/self/mounts | \
tac | \ tac | \
sed -e 's/\\040(deleted)$//' sed -e 's/\\040(deleted)$//'
# Hack(zbehan): If a bind mount's source is mysteriously removed, # Hack(zbehan): If a bind mount's source is mysteriously removed,
@ -663,9 +663,9 @@ safe_umount_tree() {
return 0 return 0
fi fi
# First try to unmount in one shot to speed things up. # First try to unmount, this might fail because of nested binds.
if safe_umount -d ${mounts}; then if sudo umount -d ${mounts}; then
return 0 return 0;
fi fi
# Check whether our mounts were successfully unmounted. # Check whether our mounts were successfully unmounted.
@ -675,45 +675,28 @@ safe_umount_tree() {
return 0 return 0
fi fi
# Well that didn't work, so lazy unmount remaining ones. # Try one more time, this one will die hard if it fails.
warn "Failed to unmount ${mounts}" warn "Failed to unmount ${mounts}"
warn "Doing a lazy unmount" safe_umount -d ${mounts}
if ! safe_umount -d -l ${mounts}; then
mounts=$(sub_mounts "$1")
die "Failed to lazily unmount ${mounts}"
fi
} }
# Run umount as root. # Run umount as root.
safe_umount() { safe_umount() {
local ret=0 if sudo umount "$@"; then
local out="" return 0;
set +e else
for i in $(seq 1 4); do failboat safe_umount
out=`$([[ ${UID:-$(id -u)} != 0 ]] && echo sudo) umount "$@" 2>&1` fi
ret=$? }
if [[ $ret -eq 0 ]]; then
set -e # Check if a single path is mounted.
return 0 is_mounted() {
fi if grep -q "$(readlink -f "$1")" /proc/self/mounts; then
# Mount is not found return 0
if [[ `expr index "${out}" "not found"` -ne "0" ]]; then else
set -e return 1
return 0 fi
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() { get_git_id() {
@ -1162,9 +1145,9 @@ okboat() {
. o .. . o ..
o . o o.o o . o o.o
...oo_ ...oo_
_[__\___ _[__\\___
__|_o_o_o_o\__ __|_o_o_o_o\\__
OK \' ' ' ' ' ' / OK \\' ' ' ' ' ' /
^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
BOAT BOAT
echo -e "${V_VIDOFF}" echo -e "${V_VIDOFF}"
@ -1176,10 +1159,10 @@ failboat() {
' '
' ) ' )
) ( ) (
( .') __/\ ( .') __/\\
(. /o/` \ (. /o/\` \\
__/o/` \ __/o/\` \\
FAIL / /o/` / FAIL / /o/\` /
^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
BOAT BOAT
echo -e "${V_VIDOFF}" echo -e "${V_VIDOFF}"