X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=mount-latest-subvol;h=026f490025538ffd1361217380b336836fe61c2c;hb=7f759d320592e791a62cd0a966350e8c53ee0976;hp=a277b55cbc9c9528542e222cc2ae4ce49aab5587;hpb=48389d89d65d783409b3b746919028dea8fb6219;p=distro-setup diff --git a/mount-latest-subvol b/mount-latest-subvol index a277b55..026f490 100644 --- a/mount-latest-subvol +++ b/mount-latest-subvol @@ -17,6 +17,7 @@ script=$(readlink -f -- "$BASH_SOURCE") cd / [[ $EUID == 0 ]] || exec sudo -E "$script" "$@" +source /usr/local/lib/err usage() { cat <&2 - set +x - echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]}:in \`$BASH_COMMAND' returned $err" - bash-trace 2 - echo "$0: exiting with code $err" - exit $err - } - trap _err-trap ERR - set -o pipefail -} -bash-trace() { - local -i argc_index=0 frame i start=${1:-1} max_indent=8 indent - local source - local extdebug=false - if [[ $(shopt -p extdebug) == *-s* ]]; then - extdebug=true - fi - - for ((frame=0; frame < ${#FUNCNAME[@]}-1; frame++)); do - argc=${BASH_ARGC[frame]} - argc_index+=$argc - ((frame < start)) && continue - if (( ${#BASH_SOURCE[@]} > 1 )); then - source="${BASH_SOURCE[frame+1]}:${BASH_LINENO[frame]}:" - fi - indent=$((frame-start+1)) - indent=$((indent < max_indent ? indent : max_indent)) - printf "%${indent}s↳%sin \`%s" '' "$source" "${FUNCNAME[frame]}" - if $extdebug; then - for ((i=argc_index-1; i >= argc_index-argc; i--)); do - printf " %s" "${BASH_ARGV[i]}" - done - fi - echo \' - done -} -errcatch - tu() { while read -r line; do file="$1" @@ -283,7 +242,7 @@ for vol in q a o i; do if m umount -R $dir; then unmounted+=($dir) else - if ! kill-dir TERM TERM TERM INT INT HUP HUP; then + 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 @@ -299,6 +258,7 @@ for vol in q a o i; do fi done + # if we unmounted some but not all, restore them and move on if ! $umount_ret; then for dir in ${unmounted[@]}; do mnt $dir @@ -306,6 +266,7 @@ for vol in q a o i; do continue fi + #### begin dealing with leaf vols #### # todo: decipher /mnt/root, like we do in check-subvol-stale cd /mnt/root if [[ -e $vol ]]; then @@ -330,7 +291,7 @@ for vol in q a o i; do if [[ $bsub ]]; then tmp=$(mktemp) # in testing, same subvol is 136 bytes. allow some overhead - btrfs send --no-data -p $bsub $leaf | head -c 1000 > $tmp + btrfs send --no-data -p $bsub $leaf | head -c 1000 > $tmp || [[ $? == 141 ]] if (( $(stat -c%s $tmp) < 1000)); then # example output for an empty diff: # Found a valid Btrfs stream header, version 1 @@ -358,6 +319,8 @@ for vol in q a o i; do done ## end expire leaf vols ## fi + #### end dealing with leaf vols #### + # Note, we make a few assumptions in this script, like # $d was not a different subvol id than $vol, and # things otherwise didn't get mounted very strangely. @@ -367,6 +330,7 @@ for vol in q a o i; do done stale_dir=/nocow/btrfs-stale rm -f $stale_dir/$d + done ### disabled