From: Ian Kelling Date: Thu, 3 Oct 2024 11:35:50 +0000 (-0400) Subject: optimize away .5 seconds X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=f4af6695a3d34628736cf736f0fc22f50c6ff11c;p=distro-setup optimize away .5 seconds --- diff --git a/filesystem/usr/local/bin/mount-latest-subvol b/filesystem/usr/local/bin/mount-latest-subvol index 376b0d8..2cf48d4 100755 --- a/filesystem/usr/local/bin/mount-latest-subvol +++ b/filesystem/usr/local/bin/mount-latest-subvol @@ -129,15 +129,15 @@ mapper-dev() { } -# Input vars: $d, eg: /a +# Input vars: $vol, eg:a # -# Output vars: $root_dir, eg: /mnt/root +# Output vars: $root_dirs[$vol], eg: root_dir[a]=/mnt/root # # Note: code-organizational only function. get-btrfs-root-mountpoint() { local dev devx ### this is duplicated in check-subvol-stale - dev=$(sed -rn "s,^\s*([^#]\S*)\s+$d\s.*,\1,p" /etc/fstab /etc/mtab|head -n1) + dev=$(sed -rn "s,^\s*([^#]\S*)\s+/$vol\s.*,\1,p" /etc/fstab /etc/mtab|head -n1) # example dev: /dev/mapper/crypt-vgDISK_BY_ID_NAME-root d dev=$dev # $devx are the devices of the btrfs filesystem. they include $dev. @@ -160,9 +160,10 @@ get-btrfs-root-mountpoint() { echo "$0: error could not find root subvol mount for $dev" >&2 exit 1 fi + root_dirs[$vol]=$root_dir } -# Input vars: $vol, $root_dir (from get-btrfs-root-mountpoint) +# Input vars: $vol, $root_dir # Note: we cd $root_dir. expire-leaf-vols() { local leaf_vols count leaf_limit_time leaf_new_limit_time leaf @@ -189,7 +190,7 @@ expire-leaf-vols() { # # Silently give up if $1 is not a child of a btrbk subvol. # -# Input vars: $vol $root_dir (from get-btrfs-root-mounts) +# Input vars: $vol $root_dir dedupe-btrbk() { local parentid subvol parent_sub i lines tmpstr local -a bsubs @@ -228,7 +229,7 @@ dedupe-btrbk() { # Maybe move volume to leaf. # -# Input vars: $vol, $root_dir (from get-btrfs-root-mountpoint) +# Input vars: $vol, $root_dir # # Note: we cd $root_dir. mv-vol-to-leaf() { @@ -419,6 +420,7 @@ prune-vols() { ##### end ##### pruned_vols+=("$vol") + get-btrfs-root-mountpoint done } @@ -426,15 +428,15 @@ prune-vols() { # Find and fix the case where a bind mount's original source directory # got remounted with a different filesystem. # -# Input vars: ${pruned_vols[@]} +# Input vars: ${pruned_vols[@]} ${root_dirs[@]} # -# Set leftover vars: $root_dir +# Leftover vars: $root_dir mount-mismatch-fix() { local vol vol_id mp mp_id found_mismatch local -a to_umount for vol in ${pruned_vols[@]}; do set-d-binds - get-btrfs-root-mountpoint + root_dir=${root_dirs[$vol]} found_mismatch=false vol_id=$(stat -c%d $root_dir/$vol) for mp in $d ${binds[@]}; do @@ -532,9 +534,9 @@ umount-then-mount-latest() { umount-kill ${to_umount[@]} for vol in ${umount_vols[@]}; do set-d-binds + root_dir=${root_dirs[$vol]} if $umount_ret; then fresh_snap=$(cat /nocow/btrfs-stale/$vol 2>/dev/null) - get-btrfs-root-mountpoint mv-vol-to-leaf expire-leaf-vols b btrfs sub snapshot $fresh_snap $vol @@ -581,6 +583,8 @@ fi ret=0 mkdir -p /var/log/btrbk +declare -A root_dirs + setup-fstab prune-vols w mount-mismatch-fix ||: