done
return 1
}
+umount-kill() {
+ dir=$1
+ if mountpoint -q $dir; then
+ if m umount -R $dir; then
+ unmounted+=($dir)
+ else
+ if ! kill-dir TERM TERM TERM INT INT HUP HUP TERM TERM TERM INT INT HUP HUP; then
+ if $force; then kill-dir KILL; fi
+ fi
+
+ if m umount -R $dir; then
+ unmounted+=($dir)
+ else
+ echo "$0: failed to umount $dir"
+ umount_ret=false
+ ret=1
+ fi
+ fi
+ fi
+}
##### begin command line parsing ########
##### begin building up list of bind mounts ######
binds=() # list of bind mounts
- roots=($d) # list of bind mounts, plus the original mount
+ roots=($d)
while true; do
new_roots=()
for r in ${roots[@]}; do
done
(( ${#new_roots} )) || break
binds+=(${new_roots[@]})
+ # roots is used to recursively find binds of binds if they exist.
roots=( ${new_roots[@]} )
done
##### end building up list of bind mounts ######
# populated by check-subvol-stale if stale
if ! fresh_snap=$(cat /nocow/btrfs-stale/$vol 2>/dev/null); then
mnt $d
+ did=$(stat -c%d $d)
for b in ${binds[@]}; do
+ if mountpoint -q $b; then
+ bid=$(stat -c%d $b)
+ if [[ $did != $bid ]]; then
+ umount-kill $b
+ fi
+ fi
mnt $b
done
continue
umount_ret=true
unmounted=()
for dir in $(echo $d ${binds[*]}\ |tac -s\ ); do
- if mountpoint -q $dir; then
- if m umount -R $dir; then
- unmounted+=($dir)
- else
- if ! kill-dir TERM TERM TERM INT INT HUP HUP TERM TERM TERM INT INT HUP HUP; then
- if $force; then kill-dir KILL; fi
- fi
-
- if m umount -R $dir; then
- unmounted+=($dir)
- else
- echo "$0: failed to umount $dir"
- umount_ret=false
- ret=1
- continue
- fi
- fi
- fi
+ umount-kill $dir
done
# if we unmounted some but not all, restore them and move on