From 3515504d60663a9417d5d4a220b2d609be777f01 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Tue, 1 Dec 2020 20:14:48 -0500 Subject: [PATCH] fix the case of an outdated bind mount --- mount-latest-subvol | 49 +++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/mount-latest-subvol b/mount-latest-subvol index 77ade00..048c952 100644 --- a/mount-latest-subvol +++ b/mount-latest-subvol @@ -103,6 +103,26 @@ kill-dir() { 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 ######## @@ -211,7 +231,7 @@ for vol in q a o i; do ##### 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 @@ -222,6 +242,7 @@ for vol in q a o i; 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 ###### @@ -232,7 +253,14 @@ for vol in q a o i; do # 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 @@ -245,24 +273,7 @@ for vol in q a o i; do 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 -- 2.30.2